Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private List<OffShowCountryDTO> GetOffShowCountry(string year, string location, decimal tot)
- {
- using (MasIntEntities context = new MasIntEntities())
- {
- List<OffShowCountryDTO> list = new List<OffShowCountryDTO>();
- var countries = context.Data1
- .Where(c => c.Geography_U == "SL" &&
- c.Manufacturing_unit_S == location &&
- c.Year_B == year &&
- c.Country_J != "Sri Lanka" &&
- c.Country_J != "")
- .GroupBy(d => d.Country_J)
- .Select(d => new
- {
- Col0 = d.FirstOrDefault().Country_J,
- Col1 = d.Sum(d1 => d1.GRN_X)
- })
- .OrderBy(d1 => d1.Col0)
- .ToList();
- var top4 = countries.Take(4)
- .ToList();
- var other = countries.Skip(4)
- .GroupBy(d => 1)
- .Select(d => new
- {
- Col0 = "Other",
- Col1 = d.Sum(d1 => d1.Col1)
- })
- .FirstOrDefault();
- foreach (var country in top4)
- {
- string value = Math.Round((double)(country.Col1 / tot) * 100, 2).ToString();
- OffShowCountryDTO c = new OffShowCountryDTO();
- c.Country = country.Col0;
- c.Value = value;
- list.Add(c);
- }
- if (other != null)
- {
- string valueOther = Math.Round((double)(other.Col1 / tot) * 100, 2).ToString();
- OffShowCountryDTO cOther = new OffShowCountryDTO();
- cOther.Country = other.Col0;
- cOther.Value = valueOther;
- list.Add(cOther);
- }
- return list;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement