public async Task <ICommandBase> UpdateOrder(Order order) { var _order = practiceContext.Order.FirstOrDefault(x => x.Id == order.Id); if (_order == null) { return(new CommandResult(false, $"Order not found.")); } var hasOrderName = practiceContext.Order.Any(c => c.Name.ToLower().Equals(order.Name.ToLower()) && c.Id != order.Id); if (hasOrderName) { return(new CommandResult(false, $"Order's name {order.Name} has already exists")); } _order.Name = order.Name; _order.SupplierId = order.SupplierId; practiceContext.Update(order); await practiceContext.SaveChangesAsync(); return(new CommandResult()); }
public async Task <IActionResult> Edit(int id, [Bind("ProductId,ProductName,Category,Color,UnitPrice,AvailableQuantity")] Products products) { if (id != products.ProductId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(products); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsExists(products.ProductId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(products)); }