Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
6
votes1
answer240
viewsA: Download server memory image
In his Controller, create a Action thus: public FileResult Imagem() { /* Carregue o stream antes. */ return File(stream, "image/jpeg"); } Or even, adapting its logic: public FileResult Imagem() {…
-
5
votes1
answer201
viewsA: I cannot remove a reference installed by Nuget
Open the Package Manager Console and execute the following command: PM> Uninstall-Package log4net All references to log4net will be removed correctly.…
-
1
votes1
answer108
viewsA: Property of a class that belongs to another context in the Entity Framework
It is possible for a class to have a list of a type that is not in its context in the Entity Framework? No. Almost certain it won’t work. The importance of having all entities mapped in just one…
-
6
votes1
answer1327
viewsA: Databinding, Dataset, Dataadapter and Datagridview: What are they for, how to use and in what order?
I’ll answer your questions in order. What is the purpose of each of these items. Data Binding This is the only one that is not a component, but a concept. It enunciates how data components connect…
-
13
votes2
answers5656
viewsA: When and where to use a delegate in C#?
Your question is very similar to this, but the context is a little different. Delegates can be roughly defined to types that define functions. In its example: public delegate void…
-
1
votes2
answers104
viewsA: Error saving a Many-To-Many relation
The problem is that there are things missing here: @for (var i = 0; i < Model.Niveis.Count; i++) { <li class="list-group-item"> @Html.Hidden("Niveis[" + i + "].nivelid",…
-
4
votes2
answers331
viewsA: Is there any way to change a file from a tag?
No. If it had, the function would lose its meaning. Tags serve to mark a point in the history of your code, as for example a release of a stable version, and that’s why even if no file can be…
-
0
votes2
answers89
viewsA: Convert PDF To SWF FLASH - Asp Net MVC
I found this tool here. The code below, according to this question here and this other topic here, does the conversion: int pageNumber = 1; string filename = @"MeuArquivo.pdf"; string outputfile =…
c#answered Leonel Sanches da Silva 88,623 -
2
votes1
answer409
viewsA: Dropdown Cascata
Prefer to use the typed version of the extension: @Html.DropDownListFor(model => model.idCanalIndicadoresMassivo, ViewBag.idCanalIndicadoresMassivo as SelectList, "[Selecione]", new { id =…
-
11
votes2
answers883
viewsA: What is the difference, in practice, between Session and Application?
You’ve already answered half the question. Session is a scope of settings for a particular user. Application is a scope of settings for the entire application. Speaking of C#, usually the…
-
31
votes3
answers1472
viewsA: How does an SQL Injection happen?
How an SQL Injection Happens? Let’s change your example a little bit: SqlCommand comm = new SqlCommand("UPDATE Contatos Set Telefone = " + txtTelefone.Text + " " + "WHERE Nome = @Nome", conn);…
-
3
votes3
answers63
viewsA: Characters " ' " and " f " appear in the textbox, how to correct?
Apparently you’re using the package jQuery.Numeric. This package has bugs (see the section 'Notes', and see that really the character ' enters all fields). I would not use it if I were in your…
-
1
votes2
answers545
viewsA: form validation on the same page
Any amount. A action does not influence client validation. Page validation is usually done in JS, and PHP has little role in this. In this case, a great option is the jQuery Validation. See working…
phpanswered Leonel Sanches da Silva 88,623 -
5
votes1
answer1271
viewsA: Relationship Problem Many to Many in the Entity Framework
This approach of creating the associative table using the ModelBuilder is somewhat problematic. In its place, would make an associative table and would not use Fluent API: public class UsuarioNivel…
-
0
votes2
answers4180
viewsA: Create a script to check if the table has a primary key
INFORMATION_SCHEMA is a special SQL Server schema, used to retrieve metadata from the databases on the server in question. If you run: SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS You’ll see…
-
6
votes2
answers37
viewsA: Doubt with sql command in c#
This is the bad way to fire an SQL command. It is correct to create parameters for each field that will be updated: SqlCommand comm = new SqlCommand("UPDATE Contatos Set Telefone = @Telefone, " +…
-
2
votes1
answer88
viewsA: How to handle multiple parameters not required on a route
The problem is that you are using all parameters after the null parameter as mandatory: public async Task<ActionResult> ConsultaVideo(string categoria, int? page, string sort, string genero)…
-
3
votes1
answer128
viewsA: Validate by js with for each
Well, since there’s no code started, I’ll suggest a. Validations are usually noted in Model. Can be by attributes or by implementing IValidatableObject. An example of validation by attributes would…
-
5
votes2
answers576
viewsA: Notice: "Possible Multiple enumeration of Ienumerable"
The reason is that, when mentioning range or any method of extending it, you will be calling GetEnumerator() and iterating somehow on it. For small lists like this, there is not much difference in…
-
4
votes1
answer545
viewsA: Inputmask by the model
Actually you want to validate the CPF on Controller, if I understand correctly. Implement the CPF validation attribute: [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field,…
-
7
votes2
answers500
viewsA: How to use Regular Expression correctly
Well, the expression is not exactly right. The correct would be: [RegularExpression(@"[0-9]{11}", ErrorMessage = "CPF inválido. O CPF deve conter 11 caracteres e apenas dígitos")] public string CPF…
-
4
votes2
answers708
viewsA: Code First and Calculated Fields
It is possible to do this way, but some care is needed: 1. Inform the Entity Framework that the property is not bank mapped If it does so: [NotMapped] public decimal ValorPedido { ... } 2. Calculate…
-
3
votes2
answers65
viewsA: What to do when a model has N responsibilities
In the Entity Framework, in the case of inheritances, the table is created with the name of the ancestral class, with all derived class fields, and a more named column of discriminator. The filling…
-
5
votes1
answer246
viewsA: How do I set up a project in Git and Github?
Github has an app, simpler than setting up native Git and using. Basically, just install and link your Github account to it. There will be in it 3 options: Add, Create and Clone: Add: Add a local…
-
2
votes1
answer81
viewsA: Quality Process Certification: how to get?
The ISO 9001 standard is normally used for quality management in companies and organizations, but can be perfectly used for quality management of a system development, in theory. In order to meet…
software-engineeringanswered Leonel Sanches da Silva 88,623 -
7
votes1
answer406
viewsA: Authorization in Asp.Net MVC
Has some elegant way of making that a component of mine view change rule according to the Roll user’s? Yes: @if (User.IsInRole("Administradores")) { ... } It may be necessary to write a RoleProvider…
-
1
votes1
answer86
viewsA: Break a number into equal parts
If the quantities are proportional, it is not necessary to use ifs: 1000a2000 => 10,00 2000a3000 => 20,00 3000a4000 => 30,00 4000a5000 => 40,00 5000a6000 => 50,00 6000a7000 =>…
phpanswered Leonel Sanches da Silva 88,623 -
2
votes3
answers1778
viewsA: Scaffolding error during View generation
This error message: 'A Configuration for type 'TST2.Models.Course' has already been Added. To Reference the existing Configuration use the Entity() or Complextype() methods. You mean this…
-
2
votes1
answer633
viewsA: How to JOIN where the identifier could not be associated
Do not mix ANSI syntax with simplified syntax. SQL Server gets lost. Use as follows: SELECT tab.matricula_usuario as tabCodigo , regional, r.cod_gerente AS cod_gerente, u2.username AS nome_gerente,…
-
2
votes2
answers1169
viewsA: Remove HTML tags
I made a Fiddle for the first case. Times were: Compile: 0.062s Execute: 0s Memory : 8kb CPU : 0.047s I made a Fiddle for the second case. For the method HtmlRemoval.StripTagsRegex(), times were:…
-
2
votes2
answers721
viewsA: Html.Editorfor value Default
EditorFor won’t work because EditorFor need to intuit the type to generate the field. For precaution, removed the possibility of the EditorFor receive value because this would be an endless source…
-
3
votes3
answers155
viewsA: How to test Filters that verify Claims data?
Write a method that instantiates the execution context (which in turn instantiates the authorization attribute, which is a filter) and makes a mock of the request, more or less like this: public…
-
4
votes2
answers800
viewsA: Slow SQL LINQ C# Entity Framework problems
For his reply, the slowness problem comes from the lazy load, which is possibly made for a great result. It will get slow even. The function below resembles a repository, which is a very wrong…
-
4
votes1
answer262
viewsA: How could I improve the code of this paging control?
Well, I’m sorry to say, but you reinvented the wheel yes. There’s a component that does this in a more performative way. His Nuget package is here. I saw that you are using Entity Framework. This…
-
3
votes1
answer44
viewsA: Set CSS style for already filled fields
When opening your HTML, check all inputs and add used to each one that is filled using .each(): $(document).ready(function() { $("input[type='text']").each(function( index ) { if ($this.val())…
-
2
votes1
answer34
viewsA: What is the use of variables of type Int32rect
Int32Rect is a data structure expressing a rectangle whose height, width, X source and Y source are all 32-bit integers (Int32). Can be used, for example, for delimiting a rectangular area in an…
-
5
votes2
answers242
viewsA: Differentiate Datetime.Now and Datetime.Now.Date
Only by language and . NET, no, because both return DateTime. What you can do is intuit this by checking in your variable if the number of seconds is equal to zero (which is what DateTime.Now.Date…
c#answered Leonel Sanches da Silva 88,623 -
1
votes2
answers119
viewsA: Best way to give Binding on objects from 1 to N - Asp.net MVC
The best way is to move the user group back to the Action POST: [HttpPost] public ActionResult Salvar(GrupoDeUsuario grupoDeUsuario) { /* Lógica de negócios aqui */ } Possibly your problem of…
-
7
votes1
answer234
viewsA: Entity Framework does not edit FK
It won’t work because you are misusing the Entity Framework. In this sentence: Veiculo veiculo = new Veiculo() { VeiculoId = 3, Nome = "Carro", Marca = new MarcaApplication().ListId(2), Modelo = new…
-
4
votes1
answer74
viewsA: Doubt in the image gallery
Just because CSS does not give because opacity applies to all elements belonging to the carousel, then it has to be by JS even. For the example on the link, using jQuery: $('.products_container…
-
3
votes1
answer1942
viewsA: Error when running test project
The error message says: Unable to create instance of class Meuprojeto.SubPasta.Homecontrollertest. Error: System.Typeloadexception: Set method in type Meuoutroprojeto.Context.Customcontext of…
-
6
votes1
answer114
viewsA: How to optimize this code?
What you’re doing is terrible at performance. My suggestion is: // Selecione todos os Products envolvidos no que você quer. // Adiante ProductHistory. Include() usa INNER JOIN. var allProducts =…
-
4
votes2
answers419
viewsA: Error creating data with foreign key
It’s not good here: @Html.EditorFor(model => model.IdDepartamento, new { htmlAttributes = new { @class = "form-control" } }) Being a foreign key, you can fill it out using a resource on…
-
2
votes1
answer94
viewsA: Auto-update of Publish in Visual Studio zeroing the database
For his Connection string, you use Localdb: Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DataBase\Database1.mdf;Integrated Security=True There are two possibilities: Or the file…
-
2
votes3
answers647
viewsA: Authorization of users to actions using the Authorize attribute
Maybe you’re not passing the variables because you didn’t indicate that you’re a Action POST: [HttpPost] public ActionResult Login(Usuario usuario) { ... }…
-
6
votes2
answers1872
viewsA: Error: The name 'Viewbag' does not exist in the Current context
There is an update for Visual Studio 2015 that enables the MVC4 syntax again. Still, I see no advantage in keeping a project in MVC4. Here is a migration guide for MVC5 that I have used a few times…
-
7
votes1
answer882
viewsA: How to resolve error: The best overloaded method match for
Well, it won’t work, obviously. You’re trying to add CandidatoViewModel in context, but a Viewmodel is not mapped by context by definition. The right thing would be for you to do: [HttpPost] public…
-
3
votes2
answers1336
viewsA: Remove Time in Datetime field
The simplest way of all is using only: @Html.TextBoxFor(model => model.DtCadastro, "{0:dd/MM/yyyy}", new { @class = "form-control", placeholder = "Data de Cadastro" }) You don’t need any of those…
-
2
votes1
answer59
viewsA: Search form does not execute controller method
Nothing. It’s all right. That’s because action of form is configured like this: <form role="search" method="get" id="search-form" name="search-form" action="/video/pesquisa"> Attributes GET do…
-
1
votes1
answer109
viewsA: problem with Dynamic proxies ASP . NET MVC
Well, you’re using the wrong technology. That’s why you have these results. Those two lines don’t make any sense: MensagensController mc = new MensagensController(); context.Dispose(); First because…