public override void ExtraDelete(Task task) { LogWorkRepo repoWork = new LogWorkRepo(); CommentRepo repoComment = new CommentRepo(); List <Comment> comments = repoComment.GetAll().ToList(); List <LogWork> work = repoWork.GetAll().ToList(); foreach (Comment item in comments) { if (item.taskId == task.Id) { repoComment.Delete(item); } } foreach (LogWork item in work) { if (item.TaskId == task.Id) { repoWork.Delete(item); } } }
public override void ExtraDelete(User user) { TaskRepo repoTask = new TaskRepo(); LogWorkRepo repoWork = new LogWorkRepo(); CommentRepo repoComment = new CommentRepo(); List <Task> tasks = repoTask.GetAll(t => t.creatorId == user.Id).ToList(); List <Comment> comments = repoComment.GetAll().ToList(); List <LogWork> works = repoWork.GetAll().ToList(); foreach (Task item in tasks) { foreach (Comment comment in comments) { if (comment.taskId == item.Id) { repoComment.Delete(comment); } } foreach (LogWork work in works) { if (work.TaskId == item.Id) { repoWork.Delete(work); } } repoTask.Delete(item); } }
public ActionResult Details(int id) { TaskRepo repo = new TaskRepo(); Task task = repo.GetById(id); if (task.assignetId != AuthenticationManager.LoggedUser.Id && task.creatorId != AuthenticationManager.LoggedUser.Id) { return(RedirectToAction("Index", "TaskManagement")); } DetailsTaskVM model = new DetailsTaskVM(); model.CommentsVM = new ListCommentVM(); model.LoggedWorkVM = new ListLogVM(); UserRepo repoUser = new UserRepo(); List <User> users = repoUser.GetAll().ToList(); CommentRepo repoComment = new CommentRepo(); List <Comment> comments = repoComment.GetAll(c => c.taskId == id).ToList(); LogWorkRepo repoWork = new LogWorkRepo(); List <LogWork> works = repoWork.GetAll(w => w.TaskId == id).ToList(); model.Id = task.Id; model.Tittle = task.tittle; model.Content = task.content; model.WorkingHours = task.estimate; model.AssigneeId = task.assignetId; model.CreatorId = task.creatorId; model.CreateOn = task.createdON; model.EditedBy = task.editedBY; model.EditedOn = task.editedON; model.Status = task.finnished; model.users = new List <User>(); foreach (User item in users) { model.users.Add(item); } model.CommentsVM.Items = new List <Comment>(); foreach (Comment item in comments) { model.CommentsVM.Items.Add(item); } model.LoggedWorkVM.Items = new List <LogWork>(); foreach (LogWork item in works) { model.LoggedWorkVM.Items.Add(item); } model.CommentsVM.Pager = new PagerVM(); model.CommentsVM.Filter = new CommentFilterVM(); model.CommentsVM.Pager.Prefix = "CommentsVM.Pager."; model.CommentsVM.Filter.Prefix = "CommentsVM.Filter."; model.CommentsVM.Filter.Pager = model.CommentsVM.Pager; model.LoggedWorkVM.Pager = new PagerVM(); model.LoggedWorkVM.Filter = new LogWorkFilterVM(); model.LoggedWorkVM.Pager.Prefix = "LoggedWorkVM.Pager."; model.LoggedWorkVM.Filter.Prefix = "LoggedWorkVM.Filter."; model.LoggedWorkVM.Filter.Pager = model.LoggedWorkVM.Pager; TryUpdateModel(model); Expression <Func <Comment, bool> > commentFilter = model.CommentsVM.Filter.GenerateFilter(); model.CommentsVM.Items = repoComment.GetAll(commentFilter, model.CommentsVM.Pager.CurrentPage, model.CommentsVM.Pager.PageSize).ToList(); Expression <Func <LogWork, bool> > workFilter = model.LoggedWorkVM.Filter.GenerateFilter(); model.LoggedWorkVM.Items = repoWork.GetAll(workFilter, model.LoggedWorkVM.Pager.CurrentPage, model.LoggedWorkVM.Pager.PageSize).ToList(); model.CommentsVM.Pager.PagesCount = (int)Math.Ceiling(model.CommentsVM.Items.Count / (double)model.CommentsVM.Pager.PageSize); model.CommentsVM.Items = model.CommentsVM.Items.Skip(model.CommentsVM.Pager.PageSize * (model.CommentsVM.Pager.CurrentPage - 1)).Take(model.CommentsVM.Pager.PageSize).ToList(); model.LoggedWorkVM.Pager.PagesCount = (int)Math.Ceiling(model.LoggedWorkVM.Items.Count / (double)model.LoggedWorkVM.Pager.PageSize); model.LoggedWorkVM.Items = model.LoggedWorkVM.Items.Skip(model.LoggedWorkVM.Pager.PageSize * (model.LoggedWorkVM.Pager.CurrentPage - 1)).Take(model.LoggedWorkVM.Pager.PageSize).ToList(); return(View(model)); }