public async Task <IActionResult> Create(int id, bool multiple, [Bind("Id,Quantity,Unit,AlternateProductName,AlternateProductUpccode,SupplierData,SupplierId,AlternateProductPrice,AlternateProductCost,AlternateSuggestedPrice,ProductId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] ProductPackageType productPackageType) { productPackageType.Id = 0; if (ModelState.IsValid) { if (User != null) { var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"emails").Value; productPackageType.CreatedBy = userFullName; } productPackageType.SupplierId = RequestDto.SupplierId; productPackageType.CreatedOn = DateTime.Now; productPackageType.ProductId = id; _dbWriteService.Add(productPackageType); await _dbWriteService.SaveChangesAsync(); } ViewData["ProductId"] = new SelectList(_context.Product, "Id", "ProductName", productPackageType.ProductId); ViewData["SupplierId"] = new SelectList(_context.Supplier, "Id", "SupplierName", productPackageType.SupplierId); if (multiple == true) { TempData["notifyUserSuccess"] = "Alternate Package Saved."; return(RedirectToAction("Create", "ProductPackageTypes", new { id = productPackageType.ProductId })); } return(RedirectToAction("Index", "ProductPackageTypes", new { id = productPackageType.ProductId })); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Quantity,Unit,AlternateProductName,AlternateProductUpccode,SupplierData,SupplierId,AlternateProductPrice,AlternateProductCost,AlternateSuggestedPrice,ProductId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] ProductPackageType productPackageType) { if (id != productPackageType.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (User != null) { var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value; productPackageType.UpdatedBy = userFullName; } productPackageType.UpdatedOn = DateTime.Now; _dbWriteService.Update(productPackageType); await _dbWriteService.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { bool result = await ProductPackageTypeExists(productPackageType.Id); if (!result) { return(NotFound()); } else { throw; } } } ViewData["ProductId"] = new SelectList(_context.Product, "Id", "ProductName", productPackageType.ProductId); ViewData["SupplierId"] = new SelectList(_context.Supplier, "Id", "SupplierName", productPackageType.SupplierId); return(RedirectToAction("Index", "ProductPackageTypes", new { id = productPackageType.ProductId })); }