public async Task <IActionResult> CreateProductAndPackage(int id, [Bind("Id,ProductName,ProductDescription,Upccode,ProductLocation,ProductCost,ProductPrice,SuggestedPrice,PackageSize,PackageType,ContainerSizeTypeId,ContainerTypeId,OrderWeek,CategoryId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy,UnitsPerCase,SupplierData")] Product product) { var requestId = RequestDto.RequestId; product.Id = 0; if (ModelState.IsValid) { if (User != null) { var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"emails").Value; product.CreatedBy = userFullName; } product.CreatedOn = DateTime.Now; _dbWriteService.Add(product); await _dbWriteService.SaveChangesAsync(); _dbReadService.IncludeEntityNavigation <Request>(); var request = await _dbReadService.GetSingleRecordAsync <Request>(s => s.Id.Equals(requestId)); request.ProductId = product.Id; _dbWriteService.Update(request); await _dbWriteService.SaveChangesAsync(); if (request.StoreId != null) { RequestEmail requestEmail = new RequestEmail(_configuration, _dbReadService); requestEmail.SendRequestToStoreManager(request); } RequestLogHelper logHelper = new RequestLogHelper(); logHelper.LogRequestChange(request, _context, RequestLogConstants.RequestAddByVendor); } ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "CategoryName", product.CategoryId); ViewData["OrderWeeks"] = new SelectList(new Dictionary <int, int>() { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 }, { 8, 8 }, { 9, 9 } }, "Key", "Value", product.OrderWeek); return(RedirectToAction("Create", "ProductPackageTypes", new { id = product.Id })); }
public async Task <IActionResult> DeleteConfirmed(int id) { var request = await _dbReadService.GetSingleRecordAsync <Request>(s => s.Id.Equals(id)); _dbWriteService.Delete(request); var response = await _dbWriteService.SaveChangesAsync(); if (!response) { TempData["notifyUser"] = "******"; } RequestLogHelper logHelper = new RequestLogHelper(); logHelper.LogRequestChange(request, _context, RequestLogConstants.RequestDeletedByStaff); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int id, [Bind("Id,RequestDescription,RequestTypeId,StatusTypeId,UserId,ProductId,SupplierId,StoreId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] Request request) { if (id != request.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (User != null) { string claimTypeEmailAddress = $"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"; var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value; request.UserId = User.Claims.FirstOrDefault(x => x.Type == claimTypeEmailAddress).Value; request.UpdatedBy = userFullName; } request.UpdatedOn = DateTime.Now; request.ProductId = _dbReadService.GetSingleRecordAsync <Request>(p => p.Id.Equals(request.Id)).Result.ProductId; _dbWriteService.Update(request); await _dbWriteService.SaveChangesAsync(); var status = await _dbReadService.GetSingleRecordAsync <StatusType>(s => s.Id.Equals(request.StatusTypeId)); if (request.StatusTypeId != RequestDto.StatusId) { switch (status.StatusTypeName) { case "New Request": break; case "Approved": RequestLogHelper logHelperApproved = new RequestLogHelper(); logHelperApproved.LogRequestChange(request, _context, RequestLogConstants.RequestApproved); RequestEmail requestEmailManager = new RequestEmail(_configuration, _dbReadService); requestEmailManager.SendApprovedRequestEmailToHeadQuarters(request); break; case "Denied": RequestLogHelper logHelperDenied = new RequestLogHelper(); logHelperDenied.LogRequestChange(request, _context, RequestLogConstants.RequestDenied); RequestEmail requestEmailOriginator = new RequestEmail(_configuration, _dbReadService); requestEmailOriginator.SendDeniedRequestEmailToOriginatingUser(request); break; case "Complete": RequestLogHelper logHelperComplete = new RequestLogHelper(); logHelperComplete.LogRequestChange(request, _context, RequestLogConstants.RequestComplete); RequestEmail requestEmailCompletedStatus = new RequestEmail(_configuration, _dbReadService); requestEmailCompletedStatus.SendRequestCompletedToGroup(request); break; } } } catch (DbUpdateConcurrencyException) { bool result = await RequestExists(request.Id); if (!result) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } RequestDto.StatusId = null; return(View(request)); }