public IHttpActionResult PutCustomer(int id, Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customer.customer_ID) { return(BadRequest()); } db.Entry(customer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public RoleDto AddRole(RoleDto roleDto) { Role role = _mapper.Map <Role>(roleDto); _roleRepo.Add(role); _context.SaveChanges(); return(_mapper.Map <RoleDto>(role)); }
public IHttpActionResult PutFoodOrder(int id, List <OrderProduct> orderproduct) { FoodOrder foodorder = db.FoodOrders.Find(id); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != foodorder.Order_ID) { return(BadRequest("Invalid OrdeID")); } var products = db.OrderProducts.Where(p => p.OrderId == id); foreach (var foodproductitem in products) { db.OrderProducts.Remove(foodproductitem); } foreach (var addfoodproduct in orderproduct) { db.OrderProducts.Add(addfoodproduct); } if (db.ChangeTracker.HasChanges()) { db.SaveChanges(); int totalOrderPrice = 0; var updatedOrderProduct = (from orderP1 in db.OrderProducts where orderP1.OrderId == id select new { opKey = orderP1.orderProductKey, opID = orderP1.OrderId, opFoodpID = orderP1.fProductid, tProductPrice = orderP1.productQuantity * orderP1.productPrice }); foreach (var orderprodprice in updatedOrderProduct) { totalOrderPrice = totalOrderPrice + orderprodprice.tProductPrice; } foodorder.OrderPrice = totalOrderPrice; } //db.Entry(foodOrder).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!FoodOrderExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public virtual void Update(T entity) { //dbset.Attach(entity); dataContext.Entry(entity).State = EntityState.Modified; dataContext.SaveChanges(); }