Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
2
votes1
answer844
viewsA: C# MVC5 - Table with Checkbox and Different Actions
The most elegant solution I know is to implement a button detection attribute of Submit of form: [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public class…
-
2
votes1
answer96
viewsA: Asp Net MVC Block Permission
Thus, in the View: @if (User.IsInRole("Role1")) { @* Escreva o form aqui *@ } else if (User.IsInRole("Role2")) { @* Escreva outro form aqui *@ } EDIT I forgot an important detail: It is necessary to…
-
2
votes1
answer189
viewsA: ASP NET MVC authentication
Basically, by writing your own authorization attribute. For example: [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)] public class…
-
4
votes2
answers619
viewsA: How to get data from two tables in the same column?
If the columns are the same, you can use a SELECT with UNION (to avoid duplication) or UNION ALL if you want to display the result even with duplicates: SELECT ID, NOME, SEXO, 'Tabela1' as TABELA…
-
1
votes1
answer42
viewsA: Delete WHERE clause if passed Zero or Cakephp 3.0
Not much of a secret. Just segmenting logic: public function listProductsByTrend($subCategoryId, $productsQuantity, $column, $order) { $products = TableRegistry::get('products'); $query =…
-
1
votes1
answer281
viewsA: Starting SQL Server 2008 express R2
The 2008 version of SQL Server presents a list of problems for newer operating systems. It is possible to install, but involves a number of steps that are avoidable if you leave for a newer version…
-
4
votes1
answer117
viewsA: How to save in a database, confrontations between teams?
An associative table, I believe, would be the most interesting alternative: CREATE TABLE CONFRONTOS ( ID_CONFRONTO INT PRIMARY KEY, ID_TIME_1 INT NOT NULL, ID_TIME_2 INT NOT NULL, DATA_CONFRONTO…
-
1
votes2
answers709
viewsA: Projects created in Visual Studio 2015 are recognized in Visual Studio 2013?
Projects created in Visual Studio 2015 are recognized in Visual Studio 2013? Up to the date of this answer, yes. I ran a test by creating an ASP.NET Web Application project. By the way, the Visual…
-
1
votes1
answer216
viewsA: Transcribe SELECT to LINQ query expression
The reason I asked if you were using Entity Framework is precisely because of the approach. LINQ does not support Include, which is used to load the information in advance (Eager Load) and mount the…
-
18
votes2
answers1854
viewsA: Pagination C# MVC Asp . NET
The approach is incorrect. Use a repository in your case is incorrect. I’ve explained it a few times. If you want to use the PagedList, abandon this type of approach: var bdPergunta = new…
-
2
votes1
answer246
viewsA: How not to publish an Asp.net mvc configuration file
Using files of transformation. Note that your file Web.config drift to two other: Web.Release.config; Web.Debug.config. When you publish in production, change the Release. I suppose your Web.config…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
4
votes3
answers1719
viewsA: Very slow C# and MVC site
This behavior is normal in the first publication. It occurs for two reasons: As Views are recompiled in the first request; As Migrations are executed if the first request makes some data access.…
-
7
votes1
answer471
viewsA: Design Patterns - DTO, POCO, MODEL
POCO = Plain Old Class Object POCO is derived from POJO. The term was coined by Martin Fowler. POCO (usually) follows the classical precepts of object-oriented programming such as state and…
-
1
votes2
answers7710
viewsA: Unable to locate Data Provider . Requested Net Framework. Sql Server + Entity
There’s something very strange about this entrance: <add name="Entities"…
-
3
votes2
answers427
viewsA: Many-To-Many Entityframework update does not work
I think I understand what you are trying to do. Your relationship is wrong. If a Projeto has N Atividades, and a Atividade belongs to N Projetos, you never could wear something like that: public…
entity-frameworkanswered Leonel Sanches da Silva 88,623 -
3
votes1
answer397
viewsA: How to make a website homepage using Cakephp 3.0
You can use Elements. I see no problem in your PagesController make access to data of various entities to assemble the View. Just make sure you target each element of the homepage to facilitate…
-
9
votes2
answers7119
viewsA: How popular a Dropdownlist from another Dropdownlist
For this answer, I will assume that your project has installed jQuery and JSON.NET (both come by default in an ASP.NET MVC project). First, isolate the search for a subproject in a Action to return…
-
6
votes1
answer193
viewsA: Entity Framework 6 tries to insert FK
Possibly you created the Model Usuario, inserted two users with the same Login and tried to execute a Migration to get the error. Revert all the Migrations using one of the two commands: PM>…
-
5
votes1
answer393
viewsA: How to add an HTML element to the PDF via iTextSharp?
You will need to use a HtmlWorker: TextReader reader = new StringReader(html); HTMLWorker worker = new HTMLWorker(_documento); _documento.Open(); worker.StartDocument(); worker.Parse(reader);…
-
2
votes5
answers10525
viewsA: Show every day between two dates
The following code prints all dates in a range. DECLARE @Data1 DATE, @Data2 DATE SET @Data1 = '20150701' SET @Data2 = '20150705' SELECT CONVERT(varchar, DATEADD(DAY, number + 1, @Data1), 103) [Data]…
-
4
votes1
answer682
viewsA: Send only object from the list that has changed to the controller
It is cheaper in processing cost to bring the original list and compare the values. Apparently you use a repository, so I don’t know how it’s done, but using an Entity Framework context would be…
-
3
votes1
answer177
viewsA: Publish ASP.Net website
Freevar does not support ASP.NET MVC. Won’t work. Somee supports. The correct way to publish an ASP.NET MVC site is to use it Web Deploy. No point in describing step-by-step here. There are several…
-
0
votes2
answers2051
viewsA: Merge two distinct lists using LINQ
You can merge the two objects into new objects using the TypeMerger of Kyle Finley. For historical preservation purposes, I will reproduce the two classes here in the answer: TypeMerger.cs using…
-
5
votes2
answers2201
viewsA: Person registration using multiple viewModels and only one controller
You’re using the Entity Framework wrong. It’s a great opportunity to show why it’s a lousy idea to implement a generic repository and/or service layer. This: public PessoaViewModel…
-
0
votes2
answers2556
viewsA: Pick start and end date of one week of the month
The following command takes the first Monday of the month: SELECT @PrimeiraSegundaFeira = DATEADD(WEEK, DATEDIFF(WEEK, 0, DATEADD(DAY, 6 – DATEPART(DAY, GETDATE()), GETDATE())), 0) The Monday of the…
-
1
votes2
answers247
viewsA: Doubt about Security, Authentication and Authorization
You can create your own solution or use a ready-made. A good solution is the Fluent Security. It has Nuget package and is quite simple to install. Here is a small tutorial. Another option is to…
-
1
votes1
answer87
viewsA: Is it really necessary to create a property that indicates the Foreign-key of a One-To-Many relation?
Entityframework requires me to create a field MarcaId in the object Car? Yes. It’s the default framework. Additionally, you would have to add a browsing property (as below) to stay entirely within…
entity-frameworkanswered Leonel Sanches da Silva 88,623 -
1
votes1
answer40
viewsA: Mysql Data Entities with Mysql Data 5.3.7
This package is depreciated His natural replacement is Mysql.Data.Entity. Note that the last Entities update is January 2014. Just trade Entities for the Entity, in the singular. Using with…
-
1
votes1
answer89
viewsA: How to load only the ID attribute in Many-To-One Relationship in EF?
No. Not least because there is no need to load only one piece of information, since from a performance standpoint the cost of bringing a column or all is virtually identical. Moreover, this…
-
2
votes2
answers121
viewsA: Software Release by Customers
Make a tag by version The first step is to keep the application code in the version the customer purchased. The best way is to freeze the code when the version is stable. In your case, which uses…
-
1
votes1
answer369
viewsA: One-To-Many relation with explicit Foreign key name
Let’s start with the generated SQL: SELECT "Alias1"."status_atividade", "Alias1"."pk_atividade", "Alias1"."data_hora_fim", "Alias1"."data_hora_inicio", "Alias1"."descricao_atividade",…
-
4
votes1
answer613
viewsA: How to start on MVC5 ASP.NET?
Start with this answer. I’ll start from her to continue. The basic structure of an ASP.MET MVC Project I created my project, I can connect it to a base of SQL Server Express, and I have something…
-
1
votes2
answers2346
viewsA: Generate txt file according to the predefined layout in c#
There are several ways to solve it. One of my favorites is to make a override of ToString(): public class NovosCotistasDTO { public string Agencia { get; set; } public string Conta { get; set; }…
-
6
votes1
answer2994
viewsA: Model "Product" table for multiple different product types
I’d do it this way: A table with the product category; A table with the characteristics that a product of a given category has; A table with the data of each feature for a product; It may seem a…
-
2
votes2
answers83
viewsA: doubts about localDB in MVC C#
The name localDB, gives idea that the information is in the client machine, therefore, there would be no way to get this information, right? Wrong. Localdb is a version of SQL Server that works on…
c#answered Leonel Sanches da Silva 88,623 -
0
votes1
answer36
viewsA: Doubt with time recording data in master-detail tables?
This is not a very good way to get the last Id inserted. By competition conditions, this Id may have been changed between one command and another. In this answer I put three alternatives that can be…
-
2
votes2
answers169
viewsA: How to capture the Exception generated by a method whose access is not authorized by a particular user profile
In your place, I would make my own authorization attribute with the ability to return a 403 or 405 error, depending on your goal: public class MeuAuthorizeAttribute : AuthorizeAttribute { protected…
-
3
votes1
answer247
viewsA: Error reading from XML
I modified your code a little bit for the following: XmlDocument arquivo = new XmlDocument(); arquivo.Load(@"D:\Downloads\Windows XP.xml"); // Esta linha abaixo gera a exceção // "Referência de…
c#answered Leonel Sanches da Silva 88,623 -
2
votes2
answers313
viewsA: How to create an input grid in Asp.net C# - MVC5
This is the wrong way to solve it. In ASP.NET MVC, you must pass to the form or a collection of Models or a collection of Viewmodels. For example of Viewmodel, you must declare a class as follows:…
-
2
votes2
answers398
viewsA: Glyphicons with error when publishing to IIS
Apparently it’s a problem in the Bundling. Try using another Bundle Transformer, like Yui, and see what happens. Example of use: var cssBundle = new StyleBundle("~/Content/css").Include(…
-
1
votes2
answers400
viewsA: C# MVC5 - Insert Fields with 4 Decimal Digits
Implement a ModelBinder like this: public class DecimalModelBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {…
-
3
votes2
answers858
viewsA: Problem to run "Update-Database"
There are several things wrong with your setup. Before changing the bank technology, you should have followed the tutorial until the end. Come on. First, in your file App.config:…
-
2
votes3
answers466
viewsA: Best practice to check if the module is being used
If I were you, I wouldn’t block the bank cache distributed, such as the Redis. Here’s a tutorial on how to use. Instead of storing user keys, I would store keys per module, or per screen, or even by…
-
0
votes1
answer914
viewsA: C# MVC5 - Using Outputcache
I don’t quite understand how you’re using the OutputCache in the Global.asax. Usually a decoration is made by Attribute in the Controller. In your case, it would be Action login:…
-
4
votes2
answers1498
viewsA: Entityframework, Migrations and Mysql. Schema name being misinterpreted. How to resolve?
You can customize the code generator to Migrations: public class MeuProprioMySqlMigrationSqlGenerator : MySqlMigrationSqlGenerator { protected override MigrationStatement…
-
0
votes5
answers2046
viewsA: Compressing PDF files
I’ve never done this, because the libraries I use for compression are paid for, but there is a Open Source JBIG2 Encoder and Decoder which may be useful to your case. Here are examples of use.…
-
1
votes1
answer263
viewsA: How to integrate one database table into another?
Integration between tables is usually done by foreign keys. A foreign key relates a primary key of a table to the primary key of another table. This ensures the referential integrity between tables.…
databaseanswered Leonel Sanches da Silva 88,623 -
2
votes2
answers231
viewsA: EF 6 Code First: Decimal field gives error when trying to save
The way is to implement your own Model Binder. A Model Binder which use for decimals is below: public class DecimalModelBinder : DefaultModelBinder { public override object…
-
0
votes2
answers101
viewsA: Problems filling out PDF fields in Asp.net MVC
I’m not sure if that’s it, but don’t use it @Html.DisplayFor() with the Rotary. The Rotary is a weird and troublesome package. Switch to the direct mention of the variable, as below: <text…
-
2
votes1
answer1065
viewsA: Canvas Search Field (ASP.Net - MVC)
What I did in a system of my own was to create a Controller common implementation of the research method. Something like this: public abstract class Controller<TSource> :…