Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
1
votes3
answers462
viewsA: JSON serialization and deserialization in desktop application
The JSON.NET package serializes an object for you: https://www.nuget.org/packages/newtonsoft.json/ Thus: string json = JsonConvert.SerializeObject(produto); And deserializing: var produto =…
-
2
votes1
answer354
viewsA: Create a web form generator
Yeah. It’s called Scaffolding. The Visual Studio has Scaffolding shipped from version 2013, and per command line until version 2012 (maintained by Microsoft) and 2013 and 2015 (maintained by the…
-
4
votes2
answers429
viewsA: How to filter a list asynchronously using LINQ?
The trick is to make up the list: var products = await db.Products.Where(_ => _.UserId == currentUserId).ToListAsync(); See all asynchronous methods by this link here.…
-
5
votes1
answer789
viewsA: Which aspect-oriented programming frameworks exist for . NET?
There are several. I made a list: Postsharp LOOM.NET Aspect.NET Enterprise Library 3.0 Policy Injection Application Block Aspectdng Dotspect (.SPECT) Spring.NET Wicca Seasar.NET Aspect# Puzzle.…
-
22
votes1
answer6255
viewsA: Asp.Net Identity, how to use only Roles or Claims?
Answering the point, yes. It’s possible. Using Roles The standard ASP.NET MVC5 project configured with ASP.NET Identity does not bring an ASP.NET Identity provider implementation Roll already…
-
2
votes1
answer203
viewsA: How to publish . mdf database in Azure SQL Dabases?
You will have to generate a script from that file MDF and connect to the Azure base using SQL Server Management Studio. The procedure is a bit big and would not fit in the answer (it would have to…
asp.net-mvc-5 sql-server code-first windows-azure migrationsanswered Leonel Sanches da Silva 88,623 -
1
votes1
answer127
viewsA: Problem displaying image
You need to save the change in Model, as below: [HttpPost] public ActionResult Adicionar(usuario usuario, HttpPostedFileBase foto) { if (ModelState.IsValid) { db.usuario.Add(usuario);…
-
5
votes1
answer2409
viewsA: Many to many relationship with Asp.net MVC and Entity Framework
The creation of tables by EDMX causes the Entity Framework to configure this associative table by Fluent API, within your context file (a class that derives DbContext). In my experience, I don’t…
asp.net-mvc-5answered Leonel Sanches da Silva 88,623 -
14
votes1
answer2089
viewsA: Queries in Asp.net mvc with Entity framework
Basically using extension methods (or in English, Extension Methods). The complete list of them is here, but try to use the link as a reference, after you have mastered the general aspect of how to…
-
8
votes3
answers3275
viewsA: Algorithm for faster route calculation between two points in parallel Cartesian layers (3D)
A* is what is normally used, but there is a family of algorithms called D* that considers that the calculation may vary from stage to stage, but this would be interesting if the path was not…
algorithmanswered Leonel Sanches da Silva 88,623 -
10
votes3
answers1631
viewsA: Concurrency control in database insertion
Using transactional scope. So: public void InserirFoo(Foo variavel, int id) { var diaDeHoje = DateTime.Now; using (var scope = new TransactionScope()) { if (!VerificarInsercao(id, diaDeHoje)) {…
-
1
votes2
answers330
viewsA: How to execute C# query for request control
The code is very close to what you need. I imagine that ProcessRequest be that code higher up, so I’d do the following: [HttpGet] public ActionResult ProcessRequest(int requestId) { // Estou supondo…
-
5
votes1
answer171
viewsA: Controller Edit - Entering Values
Another example of the classic problem of the highlighted context. When you do that: bdPromocoes = PromocoesAplicacaoConstrutor.PromocoesAplicacaoEF(); bdEnciclopedia =…
-
1
votes1
answer112
viewsA: Error display foreign key attribute
Your View possibly makes lazy load of something on its object, so the requirement for the context to exist until the complete rendering of the View. The dispose manual is not necessary, since it is…
-
2
votes1
answer83
viewsA: Entity Framework 1-n
You are loading Flags and Courses in different contexts. For this to work, the context of Flags and Courses accurate be the same. I would do something like this: var bdBandeira =…
-
0
votes2
answers1876
viewsA: How to use sum with condition relative to another field
Subqueries and CASE must solve: select a.id_avaliacao, a.id_pessoa, a.concluida, a.segunda_avaliacao, (case when a.segunda_avaliacao = 'S' then (select sum(nota) from nota where id_avaliacao =…
sqlanswered Leonel Sanches da Silva 88,623 -
4
votes1
answer628
viewsA: Combo box with search
To implement Autocomplete, you will need to install the following package: https://www.nuget.org/packages/jquery.ui.combined/ Suppose a TextBox with Autocomplete that brings cities, and…
-
1
votes1
answer237
viewsA: Vallidationsummary shows no error on screen
Possibly jQuery Unobstrusive Validation is missing. It is best to use in your solution the following Nuget package: https://www.nuget.org/packages/jQuery.Validation.Unobtrusive/ Add JS scripts to…
-
12
votes1
answer2456
viewsA: Return Object Code as soon as inserted
I understand that you want the return of an object ID, if the ID column is integer and IDENTITY. Whereas the mapping was done within the norms of the Entity Framework: [DisplayColumn("Nome")] public…
-
4
votes3
answers780
viewsA: Is it feasible to change databases in an existing system?
I wanted to know what the rework would be, thinking at CRUD level, if I use Controller’s and View’s generated using scaffold, where these directly use my context, initial in Mysql, when I change the…
-
2
votes1
answer454
viewsA: Is DAL class required for database connection?
It is necessary to create a file for database connection? No. The context + the connection strings defined in your file Web.config are already doing that. The archive mdf is not responsible for…
-
3
votes1
answer221
viewsA: Application Layer
Is it really necessary to use this layer (repository)? And what are the advantages of its use? Is not necessary. The advantage of the layer is being able to write unit tests more easily, because…
-
3
votes1
answer257
viewsA: Manipulate String C#
Use String.Split (http://msdn.microsoft.com/pt-br/library/b873y76a(v=vs.110). aspx): var strings = suaString.Split(','); In the case, strings is a Array. As requested in comment, to use in the form…
c#answered Leonel Sanches da Silva 88,623 -
3
votes1
answer274
viewsA: Url.Action outside the Area
Just explain that the Action does not use Area: var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code, area = "" }, protocol: Request.Url.Scheme);…
-
4
votes2
answers324
viewsA: How to define a fixed value attribute in ASP.Net MVC?
In the Model, more specifically in the constructor: public class Usuario { ... public int Permissao { get; set; } public Usuario() { Permissao = 1; } } To prevent value modification (read-only…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
2
votes1
answer403
viewsA: Two types of search in the same textbox
It is possible. Just make your search string also search by CPF. I don’t know her user class, but I suppose she has a field CPF which is a String already formatted, and what comes from the screen is…
-
11
votes1
answer358
viewsA: What are closures and what is their use?
Concept Closure (or in Portuguese, enclosure) is a function that references free variables in the lexical context (I took it from this article on Wikipedia). That is, it is a function that…
-
19
votes1
answer8375
viewsA: What’s the difference between Less and Sass?
There is a Gist in which differences and specifics are put into detail. There is also this document where several more macro aspects are weighed between the two standards, that in the final…
-
1
votes1
answer95
viewsA: SQL Server versioning integrated into the Entity Framework
The best would be to use Migrations, but as the author of the question asked for it not to be possible, I will suggest an alternative solution. By generating their Migrations, perform a…
-
2
votes1
answer2993
viewsA: Convert C++ to C#
The ideal would not even be to answer, since a translation of code from one language to another can be done with the use of a tool like this: https://www.varycode.com/ However, I will put in…
-
3
votes1
answer1355
viewsA: System.Argumentexception when using Mysql with Entity framework
Failed to register with Entity Framework: <entityFramework> <providers> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices,…
-
1
votes2
answers165
viewsA: How to use Referenceequals, Equals, Gettype, Compareto, Gettypecode?
ReferenceEquals Compare two references to objects and return true if they are equal. Equals Compares objects and checks if they are equal. GetType Get the class type of an object. CompareTo Compares…
c#answered Leonel Sanches da Silva 88,623 -
2
votes2
answers999
viewsA: Bundle does not render css Asp.net mvc
Directories created by Visual Studio are managed by IIS, which prohibits the Bundling to create temporary files. Simply delete the directory /Content/css that the Bundling will work again.…
asp.net-mvc-5answered Leonel Sanches da Silva 88,623 -
5
votes1
answer1395
viewsA: Controller message to view
Implementing a @helper to send messages Flash to the screen. I implemented one like this: App_code/Flash.cshtml I’m guessing you use jQuery for your project: @helper…
-
1
votes2
answers264
viewsA: How to instantiate a class with abstract methods in C#
Yes, through an object called Action Delegate: http://msdn.microsoft.com/en-us/library/system.action.aspx For example: class Teste { public static void MinhaAcao<T>(T numero) {…
c#answered Leonel Sanches da Silva 88,623 -
4
votes1
answer496
viewsA: Changes to the database with Asp.net MVC 5
What now? What about my code, outdated? Since I have already created Controller, and views. Exactly, more at the level of Views than of Controllers, but the Controllers may be affected if there is a…
-
1
votes1
answer62
viewsA: Pass fixed value to Repository
Yes. Actually just change to the following: public virtual T Adiciona(T entity) { var empresaId = LoggedUserHelper.GetEmpresaUsuario(User); var objetoEmpresa = new Empresa { EmpresaId = empresaId };…
asp.net-mvc-5answered Leonel Sanches da Silva 88,623 -
0
votes2
answers265
viewsA: Conditional Client-Side (Jquery) validation
Implementing custom attributes that implement an interface called IClientValidatable. In this question users show in detail how to do this. In this case, your event Validate enters as a validation…
-
1
votes1
answer61
viewsA: Make more than one condition Annotation Asp.net mvc
Using a mixed validation attribute. In another answer, I taught how to implement an attribute that validates Cnpjs. The challenge is to do the same validation for the CPF. I’m not with the CPF code…
asp.net-mvc-5answered Leonel Sanches da Silva 88,623 -
5
votes2
answers646
viewsA: Is it possible to work directly with Entityframework fonts?
Using Nightly Builds It is also possible to work with the daily version releases made by Micosoft, but which are packaged and I do not know if the Dlls of these packages have Debug information. In…
-
2
votes1
answer1321
viewsA: Edit object list with POST form in MVC C#
My solution requires you to install the Package Nuget Begincollectionitem Htmlhelper. Controller Logic required for editing only in Entity Framework 5. No 6 does not need. To create a person, this…
-
1
votes1
answer478
viewsA: Conditional Sub-model Validation MVC 4 C#
Is complicating yes. Never validation may be different because of client switching. In fact, clean up the ModelState is a bad practice in almost all cases. Implement your Class2 as follows: public…
-
0
votes1
answer116
viewsA: User permissions calling all rules at each access
In fact what happens is that Lazy Load is being called to the extreme. Switch to the next: public string[] GetRolesForUser(string login) { using (Contexto db = new Contexto()) { var usuario =…
-
3
votes1
answer3790
viewsA: Getting objects with Jquery and sending via Ajax to MVC C#
Understanding the ModelBinder of ASP.NET MVC Basically what the ModelBinder does is try to reconcile the names and values of the fields of a form (in the case of POST) or a request (in the case of…
-
3
votes2
answers406
viewsA: Error Mysql Connection Asp.net MVC
Data Source is for SQL Server. Modify to: <connectionStrings> <clear /> <add name="BancoDados" connectionString="Server=mysql01.hospedagemdesites.ws; Database=catalog; Uid=userid;…
-
1
votes1
answer101
viewsA: User Defined Table Types between different databases
The message Operand Type Clash means that you have declared the two types in different databases and they possess some difference between them which makes the database get lost. There’s an article…
sql-serveranswered Leonel Sanches da Silva 88,623 -
1
votes1
answer279
viewsA: How to do Reload Asp.net mvc pagedlist?
If the Controller was implemented as in this answer, the following Ajax must resolve: $.ajax({ url: "Deletar", type: "POST", data: { Id: Id}, success: function (data) { window.location.reload(true);…
asp.net-mvc-5answered Leonel Sanches da Silva 88,623 -
8
votes1
answer633
viewsA: Design Pattern
I find separation unnecessary for your case at some points. The separation in Dlls between Domain, Repository and Application is unnecessary because you said yourself that the Interface will…
-
1
votes1
answer326
viewsA: Error changing C# Asp.net application model
If it is Code First, is wrong you change the bank manually. What’s right to do is: Add the column directly to Model; Generate a Migration through the Package Manager Console: Inside your Visual…
-
1
votes1
answer981
viewsA: You can pass the roles without using [Authorize(Roles = "Role name")]
Basically, the idea would be to write your own authorization attribute. It can be done on ASP.NET Identity or on ASP.NET Membership. There is an answer where I talk about more alternative forms of…