public async Task <object> Assign(AssignmentDto model) { var workItem = await _context.WorkItems .Include(r => r.Report) .Include(u => u.AssignedUser) .FirstOrDefaultAsync(x => x.Id == model.WorkItemId); if (workItem == null) { return(NotFound()); } var submission = await _context.Submissions .Include(s => s.FileSpecification) .FirstOrDefaultAsync(x => x.Id == workItem.Report.SubmissionId); var idemUser = _idemService.GetUser(model.IdentityGuid); var user = _context.Users.FirstOrDefault(x => x.IdentityGuid == model.IdentityGuid) ?? new UserProfile(); Mapper.Map(idemUser, user); submission.Reassign(_currentUserFullName, workItem, user, model.Reason); _context.SaveChanges(); //Send assignment notification WorkEmailer.Send(workItem, submission); return(Ok(model)); }
public async Task <object> Reject(int id) { var workItem = await _context.WorkItems.Include(u => u.AssignedUser).FirstOrDefaultAsync(x => x.Id == id); if (workItem == null) { return(NotFound()); } //TODO: Pulling too much data here var submission = await _context.Submissions .Include(x => x.FileSpecification.GenerationGroup.Users) .Include(r => r.Reports) .FirstOrDefaultAsync(x => x.CurrentReportId == workItem.ReportId); if (!submission.FileSpecification.GenerationGroup.Users.Any()) { return(BadRequest("No group members to assign next task. ")); } var wi = submission.Reject(workItem); await _context.SaveChangesAsync(); wi.Report.CurrentDocumentVersion += 1; WorkEmailer.Send(wi, submission); var dto = Mapper.Map <WorkItemViewDto>(wi); return(Ok(dto)); }
public async Task <object> ReportError(SubmissionErrorDto model) { //TODO: Will not work in WebApi. Convert to Webapi method /api/workitem/reporterror var id = model.Id; if (model.Files.Length == 0) { ModelState.AddModelError("", "You must include at least 1 file"); } if (!ModelState.IsValid) { var errors = new List <string>(); foreach (var state in ModelState) { foreach (var error in state.Value.Errors) { errors.Add(error.ErrorMessage); } } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var workItem = await _context.WorkItems.Include(x => x.AssignedUser).Include(x => x.Report).FirstOrDefaultAsync(x => x.Id == id); if (workItem == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var submission = _context.Submissions .Include(f => f.FileSpecification.GenerationGroup.Users) .FirstOrDefault(s => s.Id == workItem.Report.SubmissionId); var assignedUser = _membershipService.GetAssignee(submission.FileSpecification.GenerationGroup); var wi = submission.CompleteWork(workItem, assignedUser, generateErrorTask: true); wi.Description = model.Description; foreach (var f in model.Files) { wi.WorkItemImages.Add(new WorkItemImage() { Image = f.ConvertToByte(), }); } var notifiers = _membershipService.GetGroupMembers(Constants.SubmissionErrorNotifiers); WorkEmailer.Send(wi, submission, model.Files); WorkEmailer.SendErrorNotification(wi, submission, model.Files, notifiers); await _context.SaveChangesAsync(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public async Task <object> ReOpen(int id, SubmissionReOpenAuditEntryDto model) { if (model == null) { return(BadRequest("No audit entry found in request")); } //TODO: Pulling too much data here var submission = await _context.Submissions .Include(r => r.Reports) .Include(f => f.FileSpecification.GenerationGroup) .FirstOrDefaultAsync(x => x.Id == id); if (submission == null) { return(NotFound()); } if (submission.FileSpecification.GenerationGroup == null) { return(BadRequest($"No generation group defined for File { submission.FileSpecification.FileNumber }")); } var group = _context.Groups.Include(x => x.Users) .FirstOrDefault(x => x.Id == submission.FileSpecification.GenerationGroupId); var assignedUser = _membershipService.GetAssignee(group); if (assignedUser == null) { return(BadRequest($"No group members to assign next task. ")); } var workItem = submission.Reopen(_currentUserFullName, model.Message, assignedUser, model.NextSubmissionDate); _context.SaveChanges(); //TODO: Refactor. Do not have access to new report until after save submission.CurrentReportId = submission.Reports.LastOrDefault().Id; _context.SaveChanges(); WorkEmailer.Send(workItem, submission); var dto = Mapper.Map <SubmissionViewDto>(submission); return(Ok(dto)); }
public async Task <object> Start(int id) { var submission = await _context.Submissions .Include(f => f.FileSpecification.GenerationGroup).Include(r => r.Reports) .FirstOrDefaultAsync(x => x.Id == id); if (submission == null) { return(NotFound()); } if (submission.FileSpecification.GenerationGroup == null) { return(BadRequest($"No generation group defined for File { submission.FileSpecification.FileNumber }")); } var group = _context.Groups.Include(x => x.Users).FirstOrDefault(x => x.Id == submission.FileSpecification.GenerationGroupId); var assignedUser = _membershipService.GetAssignee(group); if (assignedUser == null) { return(BadRequest($"No group members to assign next task. ")); } var workItem = submission.Start(assignedUser, _currentUserFullName); WorkEmailer.Send(workItem, submission); _context.SaveChanges(); if (submission.CurrentReportId == null) { submission.CurrentReportId = submission.Reports.LastOrDefault().Id; _context.SaveChanges(); } var dto = Mapper.Map <SubmissionViewDto>(submission); return(Ok(dto)); }
public async Task <object> SubmitReport(int id) { //TODO: Refactor.. too messy //get work item var workItem = await _context.WorkItems.Include(x => x.AssignedUser).Include(x => x.Report).FirstOrDefaultAsync(x => x.Id == id); //get report var report = workItem.Report; var submission = _context.Submissions.Include(f => f.FileSpecification.GenerationGroup.Users).FirstOrDefault(x => x.CurrentReportId == report.Id); var version = (report.CurrentDocumentVersion ?? 0) + 1; //Retrieve file from file parameter foreach (string filename in HttpContext.Current.Request.Files) { var f = HttpContext.Current.Request.Files[filename]; //Checking file is available to save. if (f == null) { continue; } var reportLevel = ReportLevel.SCH; //TODO: Refactor Constants to use ReportLevel Value if (f.FileName.ToLower().Contains(Constants.SchoolKey.ToLower())) { reportLevel = ReportLevel.SCH; } if (f.FileName.ToLower().Contains(Constants.LeaKey.ToLower())) { reportLevel = ReportLevel.LEA; } if (f.FileName.ToLower().Contains(Constants.StateKey.ToLower())) { reportLevel = ReportLevel.SEA; } var documentName = submission.FileSpecification.FileNameFormat.Replace("{level}", reportLevel.GetDisplayName()).Replace("{version}", string.Format("v{0}.csv", version)); var br = new BinaryReader(f.InputStream); var data = br.ReadBytes((f.ContentLength)); var doc = new ReportDocument() { FileData = data, ReportLevel = reportLevel, Filename = documentName, FileSize = data.Length, Version = version }; br.Dispose(); //attach report documents report.Documents.Add(doc); } report.CurrentDocumentVersion = version; //finish work item var wi = submission.CompleteWork(workItem, workItem.AssignedUser); WorkEmailer.Send(wi, submission); _context.SaveChanges(); var dto = Mapper.Map <WorkItemViewDto>(workItem); return(Ok(dto)); }
public async Task <object> Complete(int id) { var workItem = await _context.WorkItems .Include(x => x.AssignedUser) .Include(x => x.Report.Submission) .FirstOrDefaultAsync(x => x.Id == id); if (workItem == null) { return(NotFound()); } //TODO: Pulling too much data here var submission = _context.Submissions .Include(f => f.FileSpecification.GenerationGroup.Users) .Include(f => f.FileSpecification.ApprovalGroup.Users) .Include(f => f.FileSpecification.SubmissionGroup.Users) .FirstOrDefault(x => x.Id == workItem.Report.SubmissionId); var currentReport = submission.Reports.FirstOrDefault(x => x.Id == submission.CurrentReportId); Group group = submission.FileSpecification.GenerationGroup; switch (workItem.WorkItemAction) { case WorkItemAction.Generate: group = submission.FileSpecification.GenerationGroup; break; case WorkItemAction.Review: group = submission.FileSpecification.ApprovalGroup; break; case WorkItemAction.Approve: group = submission.FileSpecification.SubmissionGroup; break; } if (group == null) { return(BadRequest($"No group defined for next task")); } //If current workitem is a generation task, the review task should return to same user var assignee = workItem.AssignedUser; if (workItem.WorkItemAction != WorkItemAction.Generate || workItem.WorkItemAction == WorkItemAction.Submit) { assignee = _membershipService.GetAssignee(group); } if (assignee == null) { return(BadRequest($"No members in {group.Name} to assign next task")); } //TODO Move to completed work method if (workItem.WorkItemAction == WorkItemAction.Generate) { var result = _documentService.GenerateDocuments(currentReport); if (result.IsFailure) { return(BadRequest(result.Error)); } } var wi = submission.CompleteWork(workItem, assignee); if (wi.WorkItemAction == 0) { var notifiers = _membershipService.GetGroupMembers(Constants.SubmissionNotifiers); var generators = _membershipService.GetGroupMembers(submission.FileSpecification.GenerationGroup.Name).ToList(); var approvers = _membershipService.GetGroupMembers(submission.FileSpecification.ApprovalGroup.Name).ToList(); notifiers.AddRange(generators); notifiers.AddRange(approvers); WorkEmailer.SendCompletion(wi, submission, notifiers); } else { WorkEmailer.Send(wi, submission, null); } _context.SaveChanges(); var dto = Mapper.Map <WorkItemViewDto>(workItem); return(Ok(dto)); }