public static void AddRoleForUser(RolesResourcesViewModel model, int user) { TasksRoles task = new TasksRoles { RoleId = RolesService.Add(model) }; Userservice.Save(new RefUserProViewModel { UserId = user, Task = task, Tasks = new List <TasksRoles> { task }, ProjecrId = model.ProjectId, ProjectId = model.ProjectId }); }
public static List <TasksViewModel> Get(int ProjectId) { using (var db = new ShlekenEntities3()) { var Roles = RolesService.Get(ProjectId); var listTasks = db.Tasks .Where(i => i.Projects.AccountId == Userservice.AccountId && i.ProjectId == ProjectId) .ToList() .Select(i => { var item = i.Map <Entities.Tasks, TasksViewModel>(); item.AllTasksRoles = new List <TasksRoles>(); foreach (var rols in Roles) { var cnt = 1; foreach (var Hour in item.TasksRoles) { if (Hour.RoleId == rols.Id && Hour.TaskId == item.Id) { item.AllTasksRoles.Add(Hour); } else { if (item.TasksRoles.Count == cnt) { var RolesEmpty = new TasksRoles(); RolesEmpty.Value = 0; RolesEmpty.RoleId = rols.Id; item.AllTasksRoles.Add(RolesEmpty); } cnt++; } } if (item.AllTasksRoles.Count() == 0) { var RolesEmpty = new TasksRoles(); RolesEmpty.Value = 0; RolesEmpty.RoleId = rols.Id; item.AllTasksRoles.Add(RolesEmpty); } } return(item); }).ToList(); return(listTasks.Where(t => t.Name != "no task").ToList()); } }