public async Task <IActionResult> Edit(int id, [Bind("Id,Name,ProductCode,Price")] Product product) { if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { try { ViewBag.UserName = User.FindFirstValue(ClaimTypes.Name); ViewBag.StoreId = User.FindFirstValue(ClaimTypes.NameIdentifier); _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Edit(short id, [Bind("Id,Name,CountryId,Status,Remarks")] District mSDistrict) { if (id != mSDistrict.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mSDistrict); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MSDistrictExists(mSDistrict.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(mSDistrict)); }
/// <summary> /// Creates order /// </summary> /// <param name="order"></param> /// <returns></returns> public async Task CreateOrder(Order order) { try { order.OrderDate = DateTime.Now; _context.Orders.Add(order); var shoppinCartItems = _shoppingCart.ShoppingCartItems; foreach (var item in shoppinCartItems) { var orderLineItem = new OrderLineItem { Order = order, Quantity = item.Quantity, InventoryItemId = item.Product.Id * order.StoreId, Price = item.Product.Price }; var inventoryItems = _context.Inventory .Include(i => i.Product) .Include(i => i.Store) .AsNoTracking() .Where(i => i.StoreId == order.StoreId && i.ProductId == item.Product.Id).FirstOrDefault(); var newQuantity = inventoryItems.Quantity - item.Quantity; var inventoryToUpdate = new InventoryItem { Id = inventoryItems.Id, ProductId = item.Product.Id, StoreId = order.StoreId, Quantity = newQuantity, ChangedDate = DateTimeOffset.Now, LoggedUserId = order.CustomerId }; _context.OrderLineItems.Add(orderLineItem); _context.Update(inventoryToUpdate); } await _context.SaveChangesAsync(); } catch (Exception) { throw; } }