Advertisement
sandunfx

MAS 2

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