public IHttpActionResult PuttblOrder(int id, OrderDTO dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dto.id) { return(BadRequest()); } tblOrder tblOrder = new tblOrder { id = dto.id, cusID = dto.cusID, emlID = dto.emlID, payment = dto.payment, address = dto.address, date = dto.date, status = dto.status }; db.Entry(tblOrder).State = EntityState.Modified; if (dto.status == 1) { IEnumerable <tblOrderDetail> listDetail = db.tblOrderDetails .Where(detail => detail.orderID == dto.id) .ToList(); foreach (tblOrderDetail detail in listDetail) { tblToy toy = db.tblToys.Find(detail.toyID); toy.quantity -= detail.quantity; } } try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tblOrderExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IEnumerable <ToyDTO> listToys(IEnumerable <ToyDTO> listToys) { foreach (ToyDTO toy in listToys) { tblToy temp = db.tblToys.Single(tempToy => tempToy.id == toy.id); toy.image = temp.image; toy.name = temp.name; toy.price = temp.price; toy.category = temp.category; toy.description = temp.desciption; } return(listToys); }
public IHttpActionResult PuttblToy(int id, ToyDTO tblToy) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tblToy.id) { return(BadRequest()); } tblToy toy = db.tblToys.Find(id); toy.name = tblToy.name; toy.price = tblToy.price; toy.quantity = tblToy.quantity; toy.category = tblToy.category; toy.desciption = tblToy.description; toy.image = tblToy.image; db.Entry(toy).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tblToyExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PuttblToy(int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } tblToy toy = db.tblToys.Find(id); if (toy == null) { return(BadRequest()); } toy.isActived = false; db.Entry(toy).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tblToyExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }