public async Task <bool> Insert(Project project, List <string> errors) { try { project.IsActive = true; project.StatusId = ProjectStatusKey.Opened; project.CreatedDate = DateTime.Now; _unitOfWork.Projects.Insert(project); //insert watcher var listMember = new List <RoleInProject>(); listMember.Add(new RoleInProject { IsActive = true, RoleId = HardFixJobRole.PM, UserName = project.CreatedBy }); project.Modules = new List <Module>() { new Module { IsActive = true, Title = HardFixJobRoleTitle.Watcher, RoleInProjects = listMember } }; var result = await _unitOfWork.CommitAsync() > 0; if (result) { await _projectLog.AddLog(new ProjectLog { Content = $"Created project. Code: {project.Code}", CreatedBy = project.CreatedBy, CreatedDate = DateTime.Now, ProjectId = project.Id }, errors); } return(result); } catch (Exception ex) { errors.Add(ex.Message); return(false); } }
public async Task <bool> Insert(Module module, IEnumerable <MemberParamsViewModel> members, List <string> errors) { try { module.IsActive = true; var listMember = members.Select(m => new RoleInProject { IsActive = true, RoleId = m.RoleId, UserName = m.Username }).ToList(); listMember.Add(new RoleInProject { IsActive = true, RoleId = HardFixJobRole.TeamLead, UserName = module.TeamLead, JoinDate = DateTime.Now }); for (int i = 0; i < listMember.Count; i++) { listMember[i].JoinDate = DateTime.Now; } module.RoleInProjects = listMember; _unitOfWork.Modules.Insert(module); var resultCommit = await _unitOfWork.CommitAsync() > 0; if (resultCommit) { var project = await _unitOfWork.Projects.GetById(module.ProjectId); await _projectLog.AddLog(new ProjectLog { Content = $"Create module {module.Title}", CreatedBy = project.CreatedBy, CreatedDate = DateTime.Now, ProjectId = module.ProjectId }, new List <string>()); } return(resultCommit); } catch (Exception ex) { errors.Add(ex.Message); return(false); } }
public async Task <bool> Create(Solution solution, string userName, int statusId, List <string> errors) { try { var task = await _unitOfWork.Tasks.GetById(solution.TaskId); var statusFrom = task.LookupStatus.Name; task.StatusId = statusId; _unitOfWork.Tasks.Update(task); solution.CreatedBy = userName; solution.CreatedDateTime = DateTime.Now; _unitOfWork.Solutions.Insert(solution); var result = await _unitOfWork.CommitAsync() > 0; if (result) { var statusTo = await _unitOfWork.LookupStatuss.GetById(statusId); await _projectLog.AddLog(new ProjectLog { Content = $"Change status task {task.Title} from {statusFrom} to {statusTo.Name}", CreatedBy = userName, CreatedDate = DateTime.Now, ProjectId = task.Module.ProjectId }, new List <string>()); } return(result); } catch (Exception ex) { errors.Add(ex.Message); return(false); } }
public async Task <DTO.Task> CheckSolutionTaskPermission(int taskId, int statusId, string userName, List <string> errors) { try { var result = await _unitOfWork.Tasks.GetById(taskId); var statusFrom = result.LookupStatus.Name; switch (statusId) { case TaskStatusKey.InProgress: if (result.StatusId != TaskStatusKey.Closed) { result.StatusId = TaskStatusKey.InProgress; _unitOfWork.Tasks.Update(result); var success = await _unitOfWork.CommitAsync() > 0; if (success) { var statusTo = await _unitOfWork.LookupStatuss.GetById(result.StatusId); await _projectLog.AddLog(new ProjectLog { Content = $"Change status task {result.Title} from {statusFrom} to {statusTo.Name}", CreatedBy = userName, CreatedDate = DateTime.Now, ProjectId = result.Module.ProjectId }, new List <string>()); } if (success) { return(result); } } return(null); case TaskStatusKey.Resolved: if (result.StatusId != TaskStatusKey.Closed) { return(result); } return(null); case TaskStatusKey.Closed: if (result.CreatedBy == userName) { result.StatusId = statusId; _unitOfWork.Tasks.Update(result); var success2 = await _unitOfWork.CommitAsync() > 0; if (success2) { var statusTo = await _unitOfWork.LookupStatuss.GetById(result.StatusId); await _projectLog.AddLog(new ProjectLog { Content = $"Change status task {result.Title} from {statusFrom} to {statusTo.Name}", CreatedBy = userName, CreatedDate = DateTime.Now, ProjectId = result.Module.ProjectId }, new List <string>()); } if (success2) { return(result); } return(null); } else { return(null); } case TaskStatusKey.ReOpened: if (result.CreatedBy == userName) { return(result); } else { return(null); } default: break; } return(null); } catch (Exception ex) { errors.Add(ex.Message); return(null); } }