public async Task <IActionResult> Edit(long id, [Bind("Id,ApprovalHierarchyId,UserId,Sequence")] ApprovalHierarchyDetail approvalHierarchyDetail) { if (id != approvalHierarchyDetail.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(approvalHierarchyDetail); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApprovalHierarchyDetailExists(approvalHierarchyDetail.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", "ApprovalHierarchies")); } ViewData["Id"] = new SelectList(_context.ApprovalHierarchy, "Id", "Name", approvalHierarchyDetail.Id); ViewData["UserId"] = new SelectList(_context.AspNetUsers, "Id", "UserName", approvalHierarchyDetail.UserId); return(View(approvalHierarchyDetail)); }
public async Task <IActionResult> Edit(long id, [Bind("Id,Code,Name,ApprovalTypeId,IsActive")] ApprovalHierarchy approvalHierarchy) { if (id != approvalHierarchy.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(approvalHierarchy); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApprovalHierarchyExists(approvalHierarchy.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ApprovalTypeId"] = new SelectList(_context.ApprovalType, "Id", "Name", approvalHierarchy.ApprovalTypeId); return(View(approvalHierarchy)); }
public async Task <IActionResult> Edit(long id, [Bind("Id,Title,Description,ApprovalTypeId,ApprovalStatusId,AssignedTo,CreatedOn,CreatedBy,UpdateOn,UpdateBy,IsDeleted,CommentsHistory,LastComment")] Approval approval, IFormFile file, string Approve, string Reject) { var user = await _userManager.GetUserAsync(User); if (id != approval.Id) { return(NotFound()); } var path = ""; if (file != null && file.Length > 0 && Approve == null && Reject == "") { path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Docs", file.FileName); var filePath = Path.GetTempFileName(); //using (var stream = System.IO.File.Create(filePath)) using (var stream = new FileStream(path, FileMode.Create)) { if (stream.Length < 2097152) { await file.CopyToAsync(stream); } } } if (ModelState.IsValid) { try { approval.FilePath = path; approval.IsDeleted = false; var approvalDetail = _context.ApprovalDetail.FirstOrDefault(t => t.ApprovalId == id && t.UserId == approval.AssignedTo); if (Approve != null && Approve.Equals("Approve")) { approval.LastComment = $@"{Environment.NewLine} APPROVED ({user.UserName}) - -> {approval.LastComment}"; if (_context.ApprovalDetail.Max(t => t.Sequence) != approvalDetail.Sequence) { var nextApprover = _context.ApprovalDetail.Single(t => t.ApprovalId == id && t.Sequence == approvalDetail.Sequence + 1); approval.AssignedTo = nextApprover.UserId; approval.ApprovalStatusId = (Int64)EApprovalStatus.InProcess; } else { approval.ApprovalStatusId = (Int64)EApprovalStatus.Approve; } approvalDetail.ApprovalStatusId = (Int64)EApprovalStatus.Approve; approvalDetail.Comments = (String.IsNullOrWhiteSpace(approval.LastComment) ? "" : approval.LastComment); approvalDetail.ApprovalDate = DateTime.Now; _context.Update(approvalDetail); } else if (Reject != null && Reject.Equals("Reject")) { approvalDetail.Comments = (String.IsNullOrWhiteSpace(approval.LastComment) ? "" : approval.LastComment); approvalDetail.ApprovalDate = DateTime.Now; approvalDetail.ApprovalStatusId = (Int64)EApprovalStatus.Reject; approval.ApprovalStatusId = (Int64)EApprovalStatus.Reject; approval.AssignedTo = approval.CreatedBy; approval.LastComment = $@"{Environment.NewLine} REJECTED ({user.UserName}) - -> {approval.LastComment}"; _context.Update(approvalDetail); } else { var approvalDetail1 = _context.ApprovalDetail.FirstOrDefault(t => t.ApprovalId == id && t.Sequence == 1); approval.AssignedTo = approvalDetail1.UserId; approval.CommentsHistory += $@"{Environment.NewLine} (RESUBMITTED) {user.UserName} - -> {approval.LastComment}"; } approval.UpdateOn = DateTime.Now; approval.UpdateBy = user.Id; _context.Update(approval); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApprovalExists(approval.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ApprovalStatusId"] = new SelectList(_context.ApprovalStatus, "Id", "Name", approval.ApprovalStatusId); ViewData["ApprovalTypeId"] = new SelectList(_context.ApprovalType, "Id", "Name", approval.ApprovalTypeId); ViewData["CreatedBy"] = new SelectList(_context.AspNetUsers, "Id", "UserName", approval.CreatedBy); ViewData["UpdateBy"] = new SelectList(_context.AspNetUsers, "Id", "UserName", approval.UpdateBy); return(View(approval)); }