Posts by Filipe Oliveira • 2,655 points
60 posts
-
2
votes2
answers250
viewsA: How to sort and list only 5 items from a list?
The filter was made but was not assigned again where it should You can do it like this: dashboard.NotasFiscais = lista.Take(5).OrderByDescending(x => x.ValorTotalNota); return View(dashboard);…
-
1
votes2
answers76
viewsA: Button with different format with CSS
Yes, it is possible. You can do so: div { height: 50px; background: #0099d9; position: relative; width:300px; } div:before { content: ''; position: absolute; top: 0; right: 0; border-top: 20px solid…
-
2
votes1
answer41
viewsA: Give preference to results that have the parameter passed in the Entity Framework
You can do it that way: var result = Produtos.OrderByDescending(e => e.Fabricante.Contains("Pepsico"));
-
3
votes1
answer77
viewsA: Use Defaultifempty in a LINQ query with Join
You can do it like this: var pr = new List<int>() { 1, 2, 3 }; var un = new List<int>() { 1, 2 }; var pu = from p in pr join u in un on p equals u into u1 from u2 in…
-
2
votes1
answer62
viewsA: How to see object in c#
You can use the Visual Studio breakpoint and see the state of your object. Example:…
-
2
votes1
answer246
viewsA: Create second column in Datatable
If I understand what you want, probably the solution is to do it this way: DataTable DT = new DataTable(); DT.Columns.Add("1ª", typeof(int)); DT.Columns.Add("2ª", typeof(int)); for (int i = 0; i…
-
2
votes2
answers156
viewsA: I cannot capture the post by webapi c#
Use the JSON.stringify: $.ajax({ type:'POST', contentType: 'application/json; charset=utf-8', data: JSON.stringify(objFornecedor), ...
-
1
votes4
answers444
viewsA: Incorrect date on return of json
It has this "contour solution". var dataAdmissao = obj.DTADMISSAO var milisegundos = parseInt(dataAdmissao.slice(dataAdmissao.indexOf('(') + 1, dataAdmissao.indexOf(')'))); var data = new…
-
0
votes2
answers912
viewsA: Problems with special characters in Asp.net GRIDVIEW
You can use the Html.Raw(). Example: @Html.Raw(finalResult)
-
1
votes1
answer82
viewsA: Bring selected manually filled combo
Like the gestor.Status is a bool, or you change the Value for bool: lista.Add(new SelectListItem { Text = "Habilitado", Value = "True" }); lista.Add(new SelectListItem { Text = "Desabilitado", Value…
-
4
votes2
answers684
viewsA: Filtering Kids Collection in Entity Framework with Lambda
If I understand correctly, you can try it this way: Pai .Include(Filhos) .Where(x => x.Ativo && !x.Filhos.Any(e => !e.Ativo)); EDIT: From what I understand, you want all active…
-
4
votes6
answers2762
viewsA: How to walk an Enum?
You can do it like this: public enum triaguloLetra { a = 'a', b = 'b', c = 'c', d = 'd', e = 'e', f = 'f', g = 'g', h = 'h', i = 'i', j = 'j', l = 'l', m = 'm', n = 'n', o = 'o', p = 'p', q = 'q', r…
-
1
votes1
answer911
viewsA: Problem when deleting image
The problem occurred by opening the image without closing. In the code snippet: public ActionResult ExibirImagem() { Image image = Image.FromFile(Path.Combine(Server.MapPath("~/Minha/Pasta/"),…
-
2
votes1
answer911
viewsQ: Problem when deleting image
I have an image that is my user’s avatar, then I need to delete and I have the following code snippets: Action that is used in file import public void MinhaActionParaImport() { var arquivo =…
-
1
votes3
answers1947
viewsA: Dropdownlist validation in ASP.Net MVC
If you put a OptionLabel in his DropDownList it will work (in case, the "Select" in the example below). You can follow this example: @using (Html.BeginForm()) { <strong>@Html.LabelFor(e =>…
-
1
votes1
answer470
viewsA: Radio button using Viewdata for a MVC model
The @Html.RadioButton() does not accept a Collection. To have something like the RadioButtonList you would have to implement a helper. You can give yes a cast on ViewData and create Radio Buttons.…
-
1
votes2
answers620
viewsA: Automapper with Expression
In case of making Automapper with Expression, you have to use the .Where() and not the .Find(). The .Find() returns a single element and you are trying to map to a Collection. Would look like this:…
c#answered Filipe Oliveira 2,655 -
4
votes2
answers772
viewsA: How to implement a chat in an Android app with backend Webapi
An alternative to the use of GCM answered by @Gustavobitencourt, is to use Signaler for communication between Webapi and Android. In the tutorials page of Signaler you can use the same chat example…
-
2
votes1
answer2209
viewsA: How to fill out a web form through c#
If the question is exactly what I understand, you can try to do it this way: Winform public Form1() { InitializeComponent(); //navigate to you destination…
-
3
votes1
answer481
viewsA: Query using Linq to sql in Asp.net MVC
You are not returning the variable that was used in the search. The line: return View(dao.cliente.ToList()); Should be: return View(sql.ToList());…
-
0
votes2
answers1247
viewsA: Problem inserting double value in Mysql
Try to parse that way: double.Parse(txtVencimento.Text, System.Globalization.CultureInfo.InvariantCulture)
-
8
votes2
answers385
viewsQ: In which scenario is it recommended to use Keyedcollection instead of a Dictionary?
I didn’t know about the existence of KeyedCollection until you see this reply gypsy. I wondered how and when to use a KeyedCollection, since there is the Dictionary which apparently has the same…
-
2
votes1
answer314
viewsA: How to add items from a IENUMERABLE in . Net MVC into a Jquery array?
You can do it this way: var equipamentos = @Html.Raw(Json.Encode(Model.Equipamentos)); How to use? You can use normally as if it were any json. Let’s say my equipment model is like this: public…
-
7
votes1
answer166
viewsA: Add property in relation to N-N
I believe the only solution is to create a class for the relationship. In your case, it would look like this: Product class public class Produto { [Key] public int ProdutoID { get; set; } public…
-
3
votes2
answers1405
viewsA: How to remove unused Resources?
The solution I found was to use the RESX Utils. As this solution was not working properly, few modifications to the source code solved the problem. The applied solution: RESX Utils uses only the…
-
2
votes2
answers1405
viewsQ: How to remove unused Resources?
Is there any way or extension of Visual Studio that makes it possible to search for unused Resources in the application?
-
5
votes2
answers475
viewsQ: Is it feasible to use more than one Dbcontext for in the same database?
I’m developing a new application on ASP.NET MVC and searching saw some examples of applications with more than one context. Let’s say my application has several different modules, but all entities…
-
4
votes1
answer495
viewsQ: What are the positives of using Aspx View Engine instead of Razor?
When researching about ASP.Net MVC, I have always found all the examples of views with Razor (I don’t remember exactly if I saw any in aspx) and in the past I remember that it was possible to select…
-
1
votes1
answer179
viewsQ: Access App_data content through the business layer (Classlibrary)
I need to upload a file that is in the folder App_Data, but I saw that it is not possible to use the Server.MapPath in my business layer. Which approach is most appropriate for this case? Add the…
-
2
votes2
answers528
viewsA: Button event with Asp.net
When typing the OnClick="" you can squeeze Ctrl + Space inside the quotes and select <Create New Event> And your method will be created in code-Behind.…
-
4
votes1
answer875
viewsA: Entity Framework auto relationship enable cascading delete
You can use the .WillCascadeOnDelete(); Example: //Auto-relacionamento Projeto modelBuilder.Entity<Usuario>() .HasOptional(p => p.ObjPai) .WithMany(p => p.ListaPartes) .HasForeignKey(p…
-
1
votes2
answers1260
viewsA: Consume Webservice from an external link
Try it this way: function buscarCep() { var cep = $("#txtCep").val(); var url = "http://api.postmon.com.br/v1/cep/" + cep; $.getJSON(url,function(data){ console.log(data); }); } <script…
-
2
votes4
answers395
viewsA: How to Debug only one project in Visual Studio?
You can make a Unload of the project As follows: Right-click on the project you want to disable on Solution Explorer Click on Unload Project And just like that. If you want to reverse: Right click…
-
4
votes1
answer157
viewsA: Data overriding onClick command
You can solve this using ViewState[]. Viewstate is the mechanism that ASP.NET uses to maintain the state of controls and objects when a Postback occurs on the page. The information is stored in a…
-
1
votes1
answer275
viewsQ: How to maintain a Session after re-running an application?
In my MVC 5 project, a session with the user data is created in the login and after the re-execution of the application the Session no longer exists, however, the authentication Coockie still…
-
4
votes1
answer357
viewsQ: How to force login after running the application?
My scenario is this:: After authentication with Active Directory, the user who logged in is saved to a Session [HttpPost] public ActionResult Login(LoginModel model, string returnUrl) { if…
-
1
votes2
answers1731
viewsA: I can’t restore my backup
Pnet, tries to right-click the database and select the Options. Thence within the group State you change the Restricted access for SINGLE_USER So just do the restoration again. Follow picture:…
-
2
votes2
answers64
viewsQ: Why can’t I query for an added object before Savechanges?
I need to add several objects to the database and some objects need another specific object that I added earlier. When I make a query to get the object, it comes null. Example: var subItem = new…
-
4
votes5
answers15132
viewsA: Change NULL value in SQL SERVER
Daniel, can you define the default value from the field to NONE in the SQL Server table. So every field NULL will be NONE. ALTER TABLE SUA_TABELA ADD CONSTRAINT DF_NomeQualquer DEFAULT N'NONE' FOR…
-
10
votes4
answers3435
viewsA: Pick random element from a List<T>
You can do as follows in .net: var lista = new List<int>{3,5,1,8,4,9}; var rnd = new Random(); var valorAleatorio = lista[rnd.Next(lista.Count)];
-
3
votes2
answers4935
viewsA: Sort List by decreasing values
You can use the .OrderByDescending Example: var listaOrdenada = cromossomos.OrderByDescending(e => e.ValorFitness);
-
3
votes1
answer1223
viewsA: Complex query when passing parameters
If I understand correctly, maybe this will help you: var resultadopdv = (from pdv in db.T_PDV .Where(res => (res.CNPJ == "" || res.CNPJ == _cnpj)) select new { pdv.RazaoSocial, pdv.});…
-
21
votes5
answers6769
viewsQ: Should I use GUID or int as the primary key?
I’m about to start a new project in MVC 4 with Entity Framework, searching I found several examples here in Sopt of models that use GUID as ID and some doubts have arisen me: What is the advantage…
-
4
votes1
answer763
viewsQ: Change namespace automatically when changing folder file
I need to restructure the folders of a project, only that there are many files and their respective namespaces need to be changed. Is there any way to change the namespace automatically when moving…
-
43
votes5
answers2270
viewsQ: Using unused affect performance?
While I was developing, I saw that in most of my classes contained a certain amount of using that were not being used and came to me the doubt of the title. Using unused affects the performance of…
-
6
votes1
answer841
viewsA: Convert Enum variable to int in C#
Do it this way: int t = (int)enum.OPEN; frequencia[t]++;
-
5
votes2
answers483
viewsA: Like taking multiple groups in a Regex?
Do it this way: this.nomedochar2 = new StreamReader(WebRequest.Create(site).GetResponse().GetResponseStream()).ReadToEnd(); MatchCollection matches = nomedochar.Matches(nomedochar2); this.player =…
-
7
votes1
answer1157
viewsA: In a checkbox list, know which ones are checked
You can do it this way: function FazerCopiaEstabs() { $("input:checkbox[name=filialCopia]:checked").each(function () { alert(this.value); }); }…
-
1
votes3
answers5346
viewsA: Clone class objects using Icloneable
Address also need to implement the Iclonable. public class Endereco : ICloneable { public string Rua { get; set; } public string Cidade { get; set; } public string Cep { get; set; } public…
c#answered Filipe Oliveira 2,655 -
3
votes5
answers2467
viewsQ: Is it feasible to define mandatory fields in the application instead of the database?
I came across a system where most of the mandatory field rules are done in the application and not in the database (with the exception of the primary key). As I have no experience with many systems,…