Advertisement
sandunfx

MAS 1

Nov 15th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1.  
  2.         private List<OffShowCountryDTO> GetOffShowCountry(string year, string location, decimal tot)
  3.         {
  4.             using (MasIntEntities context = new MasIntEntities())
  5.             {
  6.                 List<OffShowCountryDTO> list = new List<OffShowCountryDTO>();
  7.  
  8.                 var countries = context.Data1
  9.                                         .Where(c => c.Geography_U == "SL" &&
  10.                                                     c.Manufacturing_unit_S == location &&
  11.                                                     c.Year_B == year &&
  12.                                                     c.Country_J != "Sri Lanka" &&
  13.                                                     c.Country_J != "")
  14.                                        .GroupBy(d => d.Country_J)
  15.                                        .Select(d => new
  16.                                        {
  17.                                            Col0 = d.FirstOrDefault().Country_J,
  18.                                            Col1 = d.Sum(d1 => d1.GRN_X)
  19.                                        })
  20.                                        .OrderBy(d1 => d1.Col0)
  21.                                        .ToList();
  22.  
  23.                 var top4 = countries.Take(4)
  24.                                     .ToList();
  25.  
  26.                 var other = countries.Skip(4)
  27.                                      .GroupBy(d => 1)
  28.                                      .Select(d => new
  29.                                      {
  30.                                          Col0 = "Other",
  31.                                          Col1 = d.Sum(d1 => d1.Col1)
  32.                                      })
  33.                                      .FirstOrDefault();
  34.  
  35.                 foreach (var country in top4)
  36.                 {
  37.                     string value = Math.Round((double)(country.Col1 / tot) * 100, 2).ToString();
  38.  
  39.                     OffShowCountryDTO c = new OffShowCountryDTO();
  40.                     c.Country = country.Col0;
  41.                     c.Value = value;
  42.                     list.Add(c);
  43.                 }
  44.  
  45.                 if (other != null)
  46.                 {
  47.                     string valueOther = Math.Round((double)(other.Col1 / tot) * 100, 2).ToString();
  48.  
  49.                     OffShowCountryDTO cOther = new OffShowCountryDTO();
  50.                     cOther.Country = other.Col0;
  51.                     cOther.Value = valueOther;
  52.                     list.Add(cOther);
  53.                 }
  54.  
  55.                 return list;
  56.             }
  57.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement