public static void Delete(int id) { using (var db = new ShlekenEntities3()) { var user = db.RefUserPro.Where(u => u.Id == id).FirstOrDefault(); var item = db.Roles.Single(i => i.Id == user.RoleId); var list = db.Teams.ToList(); foreach (var i in list) { if (i.ProjectId == item.ProjectId && i.RoleId == item.Id) { db.Teams.Remove(i); db.SaveChanges(); } } var TasksRoles = db.TasksRoles.ToList(); foreach (var t in TasksRoles) { if (t.Roles.ProjectId == item.ProjectId && t.RoleId == item.Id) { db.TasksRoles.Remove(t); db.SaveChanges(); } } db.Roles.Remove(item); db.RefUserPro.Remove(user); db.SaveChanges(); } }
public static void SaveRolestaks(ICollection <TasksRoles> TasksRoles, int TaskId) { using (var db = new ShlekenEntities3()) { foreach (var model in TasksRoles) { model.TaskId = TaskId; var item = db.TasksRoles.SingleOrDefault(i => i.RoleId == model.RoleId && i.TaskId == TaskId); if (item != null) { item.TaskId = model.TaskId; item.RoleId = model.RoleId; item.Value = model.Value; db.SaveChanges(); } else { TasksRoles newItem = new TasksRoles { TaskId = model.TaskId, RoleId = model.RoleId, Value = model.Value }; db.TasksRoles.Add(newItem); db.SaveChanges(); } } } }
public static void Save(List <TasksViewModel> models) { using (var db = new ShlekenEntities3()) { foreach (var model in models) { if (model.Id > 0) { var tr = model.TasksRoles; model.TasksRoles = null; var item = db.Tasks.SingleOrDefault(i => i.Projects.AccountId == Userservice.AccountId && i.Id == model.Id); item = model.Map <TasksViewModel, Entities.Tasks>(item); db.SaveChanges(); if (tr != null) { SaveRolestaks(tr, item.Id); } } else { if (model.Name != null) { var item = model.Map <TasksViewModel, Entities.Tasks>(); db.Tasks.Add(item); db.SaveChanges(); var TasksAfterSave = db.Tasks.ToList().Last(); if (model.TasksRoles != null) { SaveRolestaks(model.TasksRoles, TasksAfterSave.Id); } } } } } }
public static void Save(List <GlobalsViewModel> models) { using (var db = new ShlekenEntities3()) { if (models != null) { foreach (var model in models) { if (model.Id > 0) { var item = db.Globals.Single(i => i.Projects.AccountId == Userservice.AccountId && i.Id == model.Id); item = model.Map <GlobalsViewModel, Globals>(item); db.SaveChanges(); } else { if (model.Name != null) { var item = model.Map <GlobalsViewModel, Globals>(); db.Globals.Add(item); db.SaveChanges(); } } } } } }
public static void Save(RefUserProViewModel model) { using (var db = new ShlekenEntities3()) { if (model.Id > 0) { var item = db.Users.Single(i => i.RefUserPro.Any(u => u.Id == model.Id)); int id = item.Id; item = model.Map <UsersViewModel, Users>(item); item.Id = id; db.SaveChanges(); } else { db.TasksRoles.Add(new TasksRoles { RoleId = model.Task.RoleId, TaskId = Taskservice.GetTemp(model.ProjectId) }); db.SaveChanges(); if (model.UserId == 0) { db.Users.Add(new Users { Email = model.Email, Password = model.Password, Name = model.Name, AccountId = db.Accounts.FirstOrDefault().Id }); db.SaveChanges(); model.UserId = db.Users.ToList().LastOrDefault().Id; } int roleId = db.TasksRoles.ToList().LastOrDefault().RoleId; db.RefUserPro.Add(new RefUserPro { ProjecrId = model.ProjectId, RoleId = roleId, UserId = model.UserId }); var y = db.TasksRoles.ToList().LastOrDefault(); db.SaveChanges(); List <TasksRoles> tasks = new List <TasksRoles>(); foreach (var item in db.Projects.Single(p => p.Id == model.ProjectId).Tasks) { if (db.TasksRoles.Any(t => t.TaskId == item.Id && t.RoleId == roleId) == false) { tasks.Add(new TasksRoles { TaskId = item.Id, RoleId = roleId, Value = 0 }); } } db.TasksRoles.AddRange(tasks); db.SaveChanges(); } } }
public static void Save(OutcomesViewModel model) { using (var db = new ShlekenEntities3()) { if (model.Id > 0) { var item = db.Outcomes.Single(i => i.Projects.AccountId == Userservice.AccountId && i.Id == model.Id); item = model.Map <OutcomesViewModel, Outcomes>(item); db.SaveChanges(); } else { var item = model.Map <OutcomesViewModel, Outcomes>(); db.Outcomes.Add(item); db.SaveChanges(); } } }
public static void Delete(int id) { using (var db = new ShlekenEntities3()) { var item = db.Outcomes.Single(i => i.Projects.AccountId == Userservice.AccountId && i.Id == id); db.Outcomes.Remove(item); db.SaveChanges(); } }
public static void Delete(int id) { using (var db = new ShlekenEntities3()) { var item = db.Users.Single(i => i.Id == id); db.Users.Remove(item); db.SaveChanges(); } }
public static int Add(RolesResourcesViewModel model) { using (var db = new ShlekenEntities3()) { var item = model.Map <RolesResourcesViewModel, Roles>(); db.Roles.Add(item); db.SaveChanges(); return(item.Id); } }
public static void SaveTeamsHoursCost(int TeamsHours, int TeamsCost, int ProjectId) { using (var db = new ShlekenEntities3()) { var item = db.Projects.Single(i => i.AccountId == Userservice.AccountId && i.Id == ProjectId); item.TeamTotalCost = TeamsCost; item.TeamTotalHours = TeamsHours; db.SaveChanges(); } }
public static void Save(UsersViewModel model) { using (var db = new ShlekenEntities3()) { if (model.Id > 0) { var item = db.Users.Single(i => i.Id == model.Id); item = model.Map <UsersViewModel, Users>(item); db.SaveChanges(); } else { var item = model.Map <UsersViewModel, Users>(); item.AccountId = Userservice.AccountId; db.Users.Add(item); db.SaveChanges(); } } }
public static void New(int pro, string name) { using (var db = new ShlekenEntities3()) { db.Roles.Add(new Roles { Name = name, ProjectId = pro }); db.SaveChanges(); } }
public static bool IsProjectManager(int projects, int userId) { ShlekenEntities3 db = new ShlekenEntities3(); RefUserPro user = db.RefUserPro.ToList().FirstOrDefault(u => u.ProjecrId == projects && u.UserId == userId); bool isM = db.Projects.ToList().FirstOrDefault(j => j.Id == projects).RefUserPro.Min(o => o.Id) == user.Id; db.RefUserPro.ToList().FirstOrDefault(u => u.ProjecrId == projects && u.UserId == userId).IsOwner = isM; db.SaveChanges(); return(isM); }
public static void Save(ToDoListsViewModel model) { using (var db = new ShlekenEntities3()) { if (model.Id > 0) { var item = db.ToDoLists.Single(i => i.Projects.AccountId == Userservice.AccountId && i.Id == model.Id); item = model.Map <ToDoListsViewModel, ToDoLists>(item); db.SaveChanges(); } else { var item = model.Map <ToDoListsViewModel, ToDoLists>(); item.CreatedDate = DateTime.Now; item.Userid = Userservice.UserId; db.ToDoLists.Add(item); db.SaveChanges(); } } }
public static int Add(ActivitiesViewModel model) { using (var db = new ShlekenEntities3()) { var item = model.Map <ActivitiesViewModel, Activities>(); item.Date = DateTime.Now; item.ProjectId = 1; db.Activities.Add(item); db.SaveChanges(); return(item.Id); } }
public static int Add(FilesViewModel model) { using (var db = new ShlekenEntities3()) { var item = model.Map <FilesViewModel, Files>(); item.CreatedDate = DateTime.Now; item.UserId = 7; db.Files.Add(item); db.SaveChanges(); return(item.Id); } }
public static void Delete(int Projects, int RoleId, int UserId) { using (var db = new ShlekenEntities3()) { var items = db.Teams.Where(i => i.Projects.AccountId == Userservice.AccountId && i.RoleId == RoleId && i.UserId == UserId && i.ProjectId == Projects).ToList(); foreach (var item in items) { db.Teams.Remove(item); db.SaveChanges(); } } }
public static void Delete(int id, int projectId) { using (var db = new ShlekenEntities3()) { var item = db.Users.Single(i => i.RefUserPro.Any(r => r.Id == id)); var tasks = db.RefUserPro.Where(t => t.UserId == item.Id).SelectMany(y => y.Roles.TasksRoles); db.TasksRoles.RemoveRange(tasks); db.RefUserPro.RemoveRange(db.RefUserPro.Where(r => r.ProjecrId == projectId && r.UserId == item.Id)); db.Teams.RemoveRange(db.Teams.Where(r => r.ProjectId == projectId && r.UserId == item.Id)); db.SaveChanges(); } }
public static void Save(ProjectsViewModel model) { using (var db = new ShlekenEntities3()) { if (model.Id > 0) { var item = db.Projects.Single(i => i.AccountId == Userservice.AccountId && i.Id == model.Id); item = model.Map <ProjectsViewModel, Projects>(item); db.SaveChanges(); } else { var item = model.Map <ProjectsViewModel, Projects>(); db.Projects.Add(item); db.SaveChanges(); db.Tasks.Add(new Tasks { Name = "no task", ProjectId = db.Projects.ToList().LastOrDefault().Id, Description = "h", Status = "done", ShowClient = false }); db.SaveChanges(); } } }
public static int GetTemp(int pro) { ShlekenEntities3 db = new ShlekenEntities3(); var oo = db.Tasks.ToList().FirstOrDefault(t => t.Name == "no task" && t.ProjectId == pro); if (oo == null) { db.Tasks.Add(new Tasks { Name = "no task", ProjectId = pro, Description = "h", Status = "done", ShowClient = false }); db.SaveChanges(); GetTemp(pro); } return(oo.Id); }
public static void Delete(int id) { using (var db = new ShlekenEntities3()) { var item = db.Tasks.Single(i => i.Projects.AccountId == Userservice.AccountId && i.Id == id); var TasksRoles = db.TasksRoles.Where(i => i.TaskId == item.Id && i.Tasks.ProjectId == item.ProjectId && i.Tasks.Projects.AccountId == item.Projects.AccountId).ToList(); foreach (var taskrols in TasksRoles) { db.TasksRoles.Remove(taskrols); } db.Tasks.Remove(item); db.SaveChanges(); } }
public void SetViewModel() { ShlekenEntities3 db = new ShlekenEntities3(); ProjectId = ProjecrId; Tasks = db.TasksRoles.Where(t => t.RoleId == RoleId).ToList(); db.TasksRoles.Where(t => t.RoleId == RoleId).ToList().ForEach(t => t.Value = Value); var user = db.RefUserPro.FirstOrDefault(r => r.Id == Id).Users; Password = user.Password; Email = user.Email; Name = user.Name; Roles = db.Roles.FirstOrDefault(t => t.Id == RoleId); RoleName = Roles.Name; db.SaveChanges(); }
public static void Delete(int id) { using (var db = new ShlekenEntities3()) { var item = db.Projects.Single(i => i.AccountId == Userservice.AccountId && i.Id == id); var list = db.Contacts.ToList(); foreach (var i in list) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Contacts.Remove(i); db.SaveChanges(); } } var m = db.Meetings.ToList(); foreach (var i in m) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Meetings.Remove(i); db.SaveChanges(); } } var tr = db.TasksRoles.ToList(); foreach (var i in tr) { if (i.Tasks.ProjectId == item.Id && i.Roles.ProjectId == item.Id && i.Tasks.Projects.AccountId == item.AccountId && i.Roles.Projects.AccountId == item.AccountId) { db.TasksRoles.Remove(i); db.SaveChanges(); } } var r = db.Tasks.ToList(); foreach (var i in r) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Tasks.Remove(i); db.SaveChanges(); } } var g = db.Globals.ToList(); foreach (var i in g) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Globals.Remove(i); db.SaveChanges(); } } var Teams = db.Teams.ToList(); foreach (var i in Teams) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Teams.Remove(i); db.SaveChanges(); } } var res = db.Roles.ToList(); foreach (var i in res) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Roles.Remove(i); db.SaveChanges(); } } var Fixes = db.Fixes.ToList(); foreach (var i in Fixes) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Fixes.Remove(i); db.SaveChanges(); } } var a = db.Activities.ToList(); foreach (var i in a) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Activities.Remove(i); db.SaveChanges(); } } var o = db.Outcomes.ToList(); foreach (var i in o) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Outcomes.Remove(i); db.SaveChanges(); } } var n = db.Incomes.ToList(); foreach (var i in n) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Incomes.Remove(i); db.SaveChanges(); } } var f = db.Files.ToList(); foreach (var i in f) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Files.Remove(i); db.SaveChanges(); } } var Risks = db.Risks.ToList(); foreach (var i in Risks) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.Risks.Remove(i); db.SaveChanges(); } } var t = db.ToDoLists.ToList(); foreach (var i in t) { if (i.ProjectId == item.Id && i.Projects.AccountId == item.AccountId) { db.ToDoLists.Remove(i); db.SaveChanges(); } } var re = db.RefUserPro.ToList(); foreach (var i in re) { if (i.ProjecrId == item.Id && i.Projects.AccountId == item.AccountId) { db.RefUserPro.Remove(i); db.SaveChanges(); } } db.Projects.Remove(item); db.SaveChanges(); } }
public static List <TeamsViewModel> GetHoursUsers(int ProjectId) { using (var db = new ShlekenEntities3()) { var newTeams = new List <Teams>(); db.Projects.Where(p => p.Id == ProjectId).SelectMany(p => p.RefUserPro).ToList().Where(p => !db.Teams.Any(pp => pp.RoleId == p.RoleId && pp.UserId == p.UserId)).ToList().ForEach(i => newTeams.Add(new Teams { ProjectId = i.ProjecrId, RoleId = i.RoleId.Value, UserId = i.UserId, Date = DateTime.Today, Hours = 0, Roles = i.Roles, Users = i.Users })); db.Teams.AddRange(newTeams); db.SaveChanges(); var UsersRoles = new List <TeamsViewModel>(); var datesProjects = DatesProjects(ProjectId); var ListTeams = new List <TeamsViewModel>(); var listTeams = db.Teams .Where(i => i.Projects.AccountId == Userservice.AccountId && i.ProjectId == ProjectId) .OrderBy(i => i.RoleId) .ToList() .Select(i => { var item = i.Map <Teams, TeamsViewModel>(); item.RolesName = i.Roles.Name; item.Name = i.Users.Name; return(item); }).ToList() .GroupBy(i => new { i.UserId, i.RoleId }) .ToList(); foreach (var Teams in listTeams) { var item = new TeamsViewModel(); item.UsersHours = new List <HourDate>(); foreach (var t in Teams) { item.Id = t.Id; item.Date = t.Date; item.UserId = t.UserId; item.Name = t.Name; item.RolesName = t.RolesName; item.RoleId = t.RoleId; item.UsersHours.Add(new HourDate { Hour = t.Hours, Date = t.Date, Id = t.Id }); } item.AllHours = new List <HourDate>(); foreach (var date in datesProjects) { var count = 1; foreach (var hour in item.UsersHours) { if (hour.Date.Month == date.Date.Month && hour.Date.Year == date.Date.Year) { item.AllHours.Add(new HourDate { Hour = hour.Hour, Date = hour.Date, Id = hour.Id }); } else { if (count == item.UsersHours.Count) { item.AllHours.Add(new HourDate { Hour = 0, Date = date.Date }); } count++; } } } ListTeams.Add(item); } var tt = new List <Teams>(); return(ListTeams.OrderBy(i => i.RoleId).ToList()); } }