public IHttpActionResult PutShop(int id, Shop shop) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != shop.ShopId) { return(BadRequest()); } db.Entry(shop).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ShopExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.ProductId) { return(BadRequest()); } db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Delete(int id) { var item = db.Set <TModel>().Find(id); if (item != null) { db.Set <TModel>().Remove(item); } db.SaveChanges(); }
public Shop AddProduct(Guid id, ProductRequest request) { var shop = _dbcontext.Shops.FirstOrDefault(x => x.Id == id); var product = _mapper.Map <Product>(request); if (shop.Products == null) { shop.Products = new List <Product>(); } shop.Products.Add(product); _dbcontext.SaveChanges(); return(shop); }
private void Seed() { using (var context = new ShopsContext(ContextOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var shop = new Shop() { Id = Guid.NewGuid(), Name = "Aldi", Products = new List <Product>() { new Product() { Name = "pomme", Price = 5 } } }; context.AddRange(shop); context.SaveChanges(); } }
public void Create(Shop shop) { db.Shops.Add(shop); db.SaveChanges(); }
public void Create(Product product) { db.Products.Add(product); db.SaveChanges(); }
public ActionResult NewShop(Shops shop) { db.Shops.Add(shop); db.SaveChanges(); return(RedirectToAction("Index")); }