Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
2
votes2
answers88
viewsA: Increment Viewbag in . cshtml
Business logic in View is a lousy practice, especially because ViewBag is an auxiliary object to carry values from Controller to the View. If you really need variables in View, use normal . NET…
c#answered Leonel Sanches da Silva 88,623 -
4
votes1
answer264
viewsA: Parallelism and Entity Framework
My question is : This is the best way to make validations in parallel? Not at all. This is one of the worst, I’d say. You are creating there the problem of the highlighted context. This code will…
-
1
votes1
answer668
viewsA: Calculation of hotel nights in MVC application
There are several errors in your code, but I imagine you need a calculation routine in Ajax. I put together this context test to help. First of all, define a ReservasViewModel: public class…
-
2
votes2
answers1770
viewsA: Referencing folders created in the project
I think there’s a confusion of concepts there. This: using nomeProjeto.NomedaPasta Indicates the use of a namespace, not a directory. What Visual Studio does for you (for convenience, by the way)…
-
5
votes2
answers989
viewsA: How to install Sqlite to be part of a C#project?
Which version of Sqlite should I download, could help me with the link? The latest Nuget package. This version works for 32 and 64 bits. Which manager should I use to create the database and tables?…
-
6
votes1
answer1167
viewsA: Rounding Up - C#
Use Math.Ceiling instead of Math.Round: strArray2[4] = Math.Ceiling(Convert.ToDecimal(strArray2[4]) / 382M * 100M).ToString(); Ceiling always round up. Round rounded up only if the decimal part is…
c#answered Leonel Sanches da Silva 88,623 -
3
votes1
answer549
viewsA: Entity with multiple members of the same type in the Entity Framework
What is good practice in this case? It depends on what you need. If you need the data to be unified, the approach is correct. If this is not necessary, it is pertinent to separate. In case of…
-
0
votes2
answers320
viewsA: @Html.Dropdownlistfor Default item at first list values
It would be something like that: $('#ClienteId').append($('<option>', { text: "Novo", value: 0, selected: false })); var options = $('#ClienteId option'); $(options[options.size() -…
-
1
votes1
answer187
viewsA: INNER JOIN performance in SQL
Not in performance, but in language expression, yes. Oracle recommends quitting non-ASII operations because they are more limited than ANSI operations. Also, since ANSI syntax is a standard…
-
2
votes1
answer69
viewsA: Doubt in the study of the Code First development approach
I can study the code first using the 4.1 version examples? You can but avoid using the EDMX approach, which is already outdated. The best tutorial I know is this and soon I should be writing a…
-
4
votes1
answer1012
viewsA: How to implement drag-and-drop on an html page?
Start with jQuery UI Sortable Plugin. He does exactly what you want. Functional example: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI…
-
1
votes2
answers193
viewsA: Dropdownlistfor has no selected value
This happens because you are using the wrong component. It is useless to generate the list with Selected set in server where the value of Pagamento_MesReferencia is not equal to 6. The correct is…
-
2
votes1
answer162
viewsA: Webmethod with Data Model
You must have something like this: public class Farmacia { ... public ICollection<FarmaciaTreinamento> Treinamentos { get; set; } } Change to: public class Farmacia { ... public…
-
4
votes1
answer984
viewsA: What is Mersenne Twister?
I translate Wikipedia article about: Mersenne-Twister is a pseudo-random number generator (PRNG). It is by far the most widely used pseudo-generator. Its name derives from the fact that its interval…
random-numbersanswered Leonel Sanches da Silva 88,623 -
1
votes1
answer69
viewsA: Deploying Sign single on using AD
It is possible to implement single Sign on using AD? Yes, it is possible. How my legacy applications will communicate with AD? Depends on the legacy application. In C#, from the framework 3.5 This…
-
2
votes1
answer48
viewsA: Database First - MVC
For read-only contexts, add the following in the context class: public override int SaveChanges() { throw new AccessViolationException( "Contexto é somente leitura."); } public override async…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
7
votes1
answer99
viewsA: Doubts with Arrays in C#
When a double array is maintained in C#, each position of the array starts-without as null or zero? With zero. Here is a table with all the default values of C variables#. Is there any method that…
-
3
votes2
answers46
viewsA: ID is null when I enter the details by index
If you’re wearing one Viewmodel for their Views, need to fill in DisponibilidadeID, otherwise it obviously won’t work: DisponibilidadeViewModel model = new DisponibilidadeViewModel() {…
-
0
votes1
answer148
viewsA: Actionresult Dynamic Route
Log the following route on RouteConfig.cs: routes.MapRoute( name: "Instituicao", url: "{faculdade}/{curso}", defaults: new { controller = "Instituicao", action = "Instituicao", faculdade = "", curso…
-
1
votes1
answer425
viewsA: Is it possible to validate the import of an excel file with regular Expression?
Make a file validation attribute: public class ArquivoExcelAttribute : RequiredAttribute { public override bool IsValid(object value) { var file = value as HttpPostedFileBase; if (file == null) {…
-
0
votes2
answers146
viewsA: Context trying to delete the same record twice
In its place, I would not inject into the form a service, but rather a context. A tutorial from Microsoft goes exactly in this line. This is another problem of the highlighted context. You load the…
-
3
votes1
answer58
viewsA: Query and view in dropdownlist
ViewBag.Catequizando is not a SelectList. It’s a regular list. You need to convert to work. There are two ways to do: First form, in Controller: ViewBag.Catequizando = new…
-
2
votes1
answer497
viewsA: Entity Framework Migration - Indicate migrations as executed
Then in the next access, it will try to run the migrations, giving error, because already exist the objects of the migrations, because they were created by Database.Create Not exactly.…
-
5
votes2
answers960
viewsA: What is the purpose of the 'Let' statement in a LINQ query?
let is used to define variables at expression time. In this case: var source = from em in query let dateTimeOffset = em.Data You are set a variable for the declaration dateTimeOffset, which is used…
-
2
votes1
answer185
viewsA: Query Linq and see index
I think the sentence is right. I just consider that we need to type the return object: public class DisponibilidadeViewModel { // Não sei os tipos das suas variáveis, então vou colocar tudo String.…
-
2
votes1
answer465
viewsA: concatenate files in c#
The performative way is like this: const int chunkSize = 2 * 1024; // 2KB var inputFiles = new[] { "marcos1.txt", "marcos2.txt", "marcos3.txt" }; using (var output =…
c#answered Leonel Sanches da Silva 88,623 -
4
votes1
answer141
viewsA: create custom mask
Use the Nuget package jQuery.Maskedinput. In the View: @section scripts { <script> $("#OrdemBancaria").mask("9999OB99999"); </script> } Usually I use the Bundle thus: bundles.Add(new…
-
2
votes3
answers533
viewsA: How to point the Entity framework to another database?
Not much of a secret. Pro SQL Server, for example, just point to the instance and remove the reference to the file name, because traditional SQL Server databases do not use files:…
-
1
votes1
answer72
viewsA: How to build a list in Controller and mount a Dropdownlist
With String gets like this: @Html.DropDownListFor(model => model.TipoEndereco, new List<String> { "Residencial", "Comercial" }.Select(option => new SelectListItem { Text = option, Value…
-
2
votes1
answer1559
viewsA: How to do a back post (refresh) on MVC
I think it’s worth explaining the architectural differences between Web Forms and MVC. You could start here, but I’m going to dig a little deeper into the concepts you’ve put. I am new to MVC and am…
-
3
votes2
answers157
viewsA: Add @onchange to Editorfor using Razor
Thus: @Html.TextBoxFor(model => model.CEP, new { @class = "classe", onchange = "myfunction(id)" })
-
7
votes2
answers701
viewsA: Save and send selected item id in dropdowlinst
Gypsy Method of Implementing a Research Form This is the method I use in my applications, and it has several advantages: Search parameters in the URL. No need form to repeat the search. A simple F5…
-
5
votes2
answers10482
viewsA: Doubt about "Error Converting data type varchar to float"
You need to use parameters: var cmd = new SqlCommand(@"UPDATE Notas SET nota = @nota WHERE idMateria = @idMateria and idAluno = @idAluno", con); cmd.Parameters.Add("@nota", SqlDbType.Float).Value =…
-
2
votes1
answer55
viewsA: How to access specific information within a View Bag Asp.net
The right way to do this is to create a Viewmodel and typing the View as follows: var posts_public = from p in db.Posts join e in db.Especificars on p.id_post equals e.id_post join pu in…
-
0
votes2
answers399
viewsA: Use Viewbag as counter
Actually this is the way well wrong to perform a ratio of cardinality 1 to N in a View. The correct way is not to "count" the number of phones. The correct way is to generate as many phone elements…
-
3
votes1
answer257
viewsA: Creation of Graph in Dictionary form returning integers
You are reading a file. Natural that they are strings. To type to integer, modify your code to the following: with open (filename, "r") as f: d = {} for line in f: key, value = line.split() if key…
-
12
votes2
answers785
viewsQ: Selectize.js with Tags, reload key and value in edit form
I posted the same question in the Gringo OS too. I’m making a research form (action=GET) where a field uses Selectize.js: $("#selectize").each(function () { $(this).selectize({ plugins:…
-
0
votes1
answer160
viewsA: How to insert information into a Json object?
On the circular serialization error, implement the content of this response to resolve. And then: public ActionResult GetDadosItensVenda(int? Codigo) { db.Configuration.ProxyCreationEnabled = false;…
-
2
votes1
answer95
viewsA: Doubt when configuring entities relationship
If, for obvious reasons, every city class will necessarily have a related Uf property, I would need to declare the Uf property also in the Address class? If Endereco belongs to a Cidade, nay. What…
-
3
votes2
answers531
viewsA: Organize columns in rows for equal ID in SQL server
I think it is not the case of Pivot Tables because it is not a simple transposition. I decided to do so: select id_ok, max(fornecedor_1) as fornecedor_1, max(valor_final_1) as valor_final_1,…
-
18
votes1
answer2002
viewsQ: Consulting multiple Cnpjs situation in the IRS
They gave me an ungrateful mission to consult in the base of the IRS the situation of several CNPJ’s (more than 1000). Is there any programmatic way to do this, and preferably not cost?…
language-independentasked Leonel Sanches da Silva 88,623 -
3
votes2
answers1744
viewsA: How to change the name property in @Html.Editorfor
The estate name ALWAYS COMES Name, how I make her come name how are you in the @Html.EditorFor? name and id are not changeable in the @Html.EditorFor. You will need to change to @Html.TextBoxFor:…
-
45
votes3
answers20821
viewsA: How to define a software version?
I would like to know what the number of software versions are and how they work, for example v1.1.2 what it means? According to the Semantic Versioning: The first number indicates that the system…
-
6
votes2
answers93
viewsA: Check two null fields with Data Annotation
When it involves two fields, it is right to decorate your Model with IValidatableObject as follows: public class MeuModel : IValidatableObject { public int? Inicio {get; set;} public int? Final…
-
1
votes1
answer92
viewsA: How to insert information from a model that has a Relationship?
This case of yours doesn’t need a Viewmodel. You can use only the Model of Produto. Let’s take this one out first try... catch that is not required in ASP.NET MVC. Then we will simplify your Where…
-
3
votes2
answers506
viewsA: Receive null int in Razor (@Html.Textboxfor)
Another way is by using the following: @Html.TextBoxFor(model => model.AnoInspecao, new { Value = "", @type = "number" }) Apart from the @type, this solution works for everything Nullable.…
-
12
votes3
answers880
viewsA: What are the security impacts of a site that has an invalid certificate?
Is it necessary for a site to have a valid certificate for communication with it to be safe? Why? Yes, it is. Any and all requests made over SSL require a key that is contained within the…
-
7
votes1
answer280
viewsA: How to read data in Json on the server?
This is the wrong way to go. Actions should return values only to requests, not to internal functions. The correct way to do this is through Helpers, static classes that serve precisely the purpose…
-
9
votes2
answers1359
viewsA: What changed from MVC4 to MVC5?
In short, a lot. Detailing a little more, the most important changes are: Scaffolds updated to support Bootstrap, which is installed by default for new projects; Resource of Scaffolding becomes…
-
2
votes1
answer331
viewsA: Robot to perform Phantomjs-like web procedures
Is there any framework or implementation way to navigate a website programmatically through c code#? Yes. Abot does this thing. His Nuget package is here.…