public static UserSalaryTable BuildSalaryTable(List <ApplicationUser> users) { UserSalaryTable model = new UserSalaryTable(); foreach (var user in users) { UserSalaryViewModel UserSalary = new UserSalaryViewModel() { ShortName = user.ShortName != null ? user.ShortName : user.UserName, Dept = user.Department == null ? "Ошибка" : user.Department.Name, id = user.Id, ProjectsBalances = user.UserBalances.Select(x => new UserProjectSalaryViewModel() { id = x.Project.ProjectId, Balance = x.Sum, ProjectName = x.Project.Name, PaidsOut = user.UsersPayments.Where(y => y.PaymentGroup.State == PaymentsGroupState.PaidOut && y.Project.ProjectId == x.Project.ProjectId). GroupBy(y => y.PaymentGroup.WhenPaidOut).ToDictionary(z => z.Key, z => z.Sum(v => v.Sum)), Balanced = user.UsersPayments.Where(y => y.PaymentGroup.State == PaymentsGroupState.InProcess && y.Project.ProjectId == x.Project.ProjectId). GroupBy(y => y.PaymentGroup.WhenCreated).ToDictionary(z => z.Key, z => z.Sum(v => v.Sum)) }) }; model.Users.Add(UserSalary); } foreach (var x in model.Users) { foreach (var y in x.ProjectsBalances) { foreach (var z in y.PaidsOut) { if (!model.PaymentsGroupsColumns.Contains(z.Key)) { model.PaymentsGroupsColumns.Add(z.Key); } } foreach (var z in y.Balanced) { if (!model.PaymentsGroupsColumns.Contains(z.Key)) { model.PaymentsGroupsColumns.Add(z.Key); } } } } model.PaymentsGroupsColumns.Sort(delegate(DateTime x, DateTime y) { return(y.CompareTo(x)); }); return(model); }
public ActionResult Members() { ApplicationUser currentUser = manager.FindById(User.Identity.GetUserId()); List <ApplicationUser> users = new List <ApplicationUser>(); var results = (from u in db.Users select u); if (manager.IsInRole(currentUser.Id, SalaryRoles.Managers) && !manager.IsInRole(currentUser.Id, SalaryRoles.Directors) && !manager.IsInRole(currentUser.Id, SalaryRoles.Administrators)) { results = results.Where(x => x.Department.Boss.Id == currentUser.Id && x.UserName != "root" && x.HideSalary == false); } users = results.OrderBy(x => x.Department.Name).ToList(); UserSalaryTable model = BuildSalaryTable(users); return(View(model)); }