public async Task <HttpResponseMessage> PutBeers(int id, Beers beers) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != beers.Id) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.Entry(beers).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { if (!BeersExists(id)) { return(Request.CreateResponse(HttpStatusCode.NotFound, ex)); } else { throw; } } return(Request.CreateResponse(HttpStatusCode.Accepted)); }
public IActionResult PutBeer([FromRoute] long id, [FromBody] Beer beer) { lock (Locks.orderLock) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (String.IsNullOrEmpty(beer.Name) || !beer.StyleId.HasValue || !beer.BreweryId.HasValue || !beer.Stock.HasValue || !beer.ResourceVersion.HasValue || beer.Stock.Value < 0) { return(BadRequest()); } if (id != beer.Id) { beer.Id = id; } _context.Entry(beer).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BeerExists(id)) { return(NotFound()); } else { return(Conflict()); } } beer.ResourceVersion++; _context.Entry(beer).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { throw; } return(NoContent()); } }
public async Task <IActionResult> PutBrewery([FromRoute] long id, [FromBody] Brewery brewery) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (String.IsNullOrEmpty(brewery.Name) || String.IsNullOrEmpty(brewery.Country) || !brewery.ResourceVersion.HasValue) { return(BadRequest()); } if (id != brewery.Id) { brewery.Id = id; } _context.Entry(brewery).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BreweryExists(id)) { return(NotFound()); } else { return(Conflict()); } } brewery.ResourceVersion++; _context.Entry(brewery).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(NoContent()); }
public async Task <IActionResult> PutStyleItem([FromRoute] long id, [FromBody] Style styleItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (String.IsNullOrEmpty(styleItem.Name) || !styleItem.OptimalTemperature.HasValue || !styleItem.ResourceVersion.HasValue) { return(BadRequest()); } if (id != styleItem.Id) { styleItem.Id = id; } _context.Entry(styleItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StyleItemExists(id)) { return(NotFound()); } else { return(Conflict()); } } styleItem.ResourceVersion++; _context.Entry(styleItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(NoContent()); }
public ActionResult Edit([Bind(Include = "Beer,NewManufacturer,OriginalManufacturer,NewType,OriginalBeerType")] CreateBeerViewModel editBeer) { if (ModelState.IsValid) { if (!String.IsNullOrEmpty(editBeer.NewManufacturer)) { Manufacturer manufacturer = new Manufacturer { Name = editBeer.NewManufacturer }; context.Manufacturers.Add(manufacturer); context.SaveChanges(); editBeer.Beer.Manufacturer = manufacturer; editBeer.Beer.ManufacturerID = manufacturer.ID; } else { Manufacturer manufacturer = context.Manufacturers.Find(editBeer.Beer.ManufacturerID); editBeer.Beer.Manufacturer = manufacturer; editBeer.Beer.ManufacturerID = manufacturer.ID; } editBeer.Beer.Type = editBeer.Beer.Type == "Create New" ? editBeer.NewType : editBeer.Beer.Type; context.Entry(editBeer.Beer).State = EntityState.Modified; context.SaveChanges(); return(RedirectToAction("Index")); } return(View(editBeer)); }
public ActionResult Edit([Bind(Include = "DrozdzeID,NazwaDrozdzy,Flokulacja,Fermentacja,Tolerancja,Odfermentowanie")] Drozdze drozdze) { if (ModelState.IsValid) { db.Entry(drozdze).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(drozdze)); }
public ActionResult Edit([Bind(Include = "ID,Description,StartDate,BottleDate,StartingGravity,FinalGravity,SecondaryFermentationDate,Variables")] Brew brew) { if (ModelState.IsValid) { context.Entry(brew).State = EntityState.Modified; context.SaveChanges(); return(RedirectToAction("Index")); } return(View(brew)); }
public ActionResult Edit([Bind(Include = "SlodID,NazwaSlodu,Barwa,Ekstraktywnosc")] Slod slod) { if (ModelState.IsValid) { db.Entry(slod).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(slod)); }
public ActionResult Edit([Bind(Include = "ID,Username")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(user)); }
public ActionResult Edit([Bind(Include = "DocumentTypeId,Description")] DocumentType documentType) { if (ModelState.IsValid) { db.Entry(documentType).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(documentType)); }
public ActionResult Edit([Bind(Include = "ID,Name,Brewery,Country,Type,Percent,Sorting")] Beer beer) { if (ModelState.IsValid) { db.Entry(beer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(beer)); }
public ActionResult Edit([Bind(Include = "ChmielID,NazwaChmielu,AlfaKwasy")] Chmiel chmiel) { if (ModelState.IsValid) { db.Entry(chmiel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(chmiel)); }
public ActionResult Edit([Bind(Include = "StylID,NazwaStylu,Kod,OGmin,OGmax,FGmin,FGmax,ABVmin,ABVmax,IBUmin,IBUmax,EBCmin,EBCmax")] Styl styl) { if (ModelState.IsValid) { db.Entry(styl).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(styl)); }
public ActionResult Edit([Bind(Include = "SupplierId,CompanyName,CompanyAddress,CompanyEmail,CompanyPhoneNumber")] Supplier supplier) { if (ModelState.IsValid) { db.Entry(supplier).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
public ActionResult Edit([Bind(Include = "ID,Name,EmailAddress,FacebookUser,PermissionGroup")] User user) { if (ModelState.IsValid) { context.Entry(user).State = EntityState.Modified; context.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Edit([Bind(Include = "SalesOrderID,Units,TotalPrice,Brewery_BreweryId")] SalesOrder salesOrder) { if (ModelState.IsValid) { db.Entry(salesOrder).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Brewery_BreweryId = new SelectList(db.Breweries, "BreweryId", "Name", salesOrder.Brewery_BreweryId); return(View(salesOrder)); }
public ActionResult Edit([Bind(Include = "EmployeeId,FirstName,LastName,Salary,DateOfBirth,StartTime,Email,DocumentTypeId,Document")] Employee employee) { if (ModelState.IsValid) { db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DocumentTypeId = new SelectList(db.DocumentTypes, "DocumentTypeId", "Description", employee.DocumentTypeId); return(View(employee)); }
public ActionResult Edit([Bind(Include = "CustomerId,Identification,Name,LastName,Address,Email,PhoneNumber,DocumentTypeId")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DocumentTypeId = new SelectList(db.DocumentTypes, "DocumentTypeId", "Description", customer.DocumentTypeId); return(View(customer)); }
public ActionResult Edit([Bind(Include = "ID,UserID,BeerID,Score,Comment")] Rating rating) { if (ModelState.IsValid) { db.Entry(rating).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BeerID = new SelectList(db.Beers, "ID", "Name", rating.BeerID); ViewBag.UserID = new SelectList(db.Users, "ID", "Username", rating.UserID); return(View(rating)); }
public ActionResult Edit([Bind(Include = "ProductId,ProductCode,ProductName,Price,Stock,Image")] Product product) { HttpPostedFileBase http = Request.Files[0]; WebImage webImage = new WebImage(http.InputStream); product.Image = webImage.GetBytes(); if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public async Task <IActionResult> PutUser([FromRoute] long id, [FromBody] User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (String.IsNullOrEmpty(user.Name) || !user.ResourceVersion.HasValue) { return(BadRequest()); } var _user = _context.Users.Find(id); if (_user == null) { return(NotFound()); } user.Id = id; user.CartId = _user.CartId; user.Cart = _user.Cart; user.Favorites = _user.Favorites; _context.Entry(_user).State = EntityState.Detached; _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { return(Conflict()); } } user.ResourceVersion++; _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(NoContent()); }
public async Task <IActionResult> PutBeer(int id, Beer beer) { if (id != beer.Id) { return(BadRequest()); } _context.Entry(beer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!BeerExists(id)) { return(NotFound()); } return(NoContent()); }
public void Put(SalesOrder model) { db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); }
public void Put(Brewery model) { db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); }
public async Task <IHttpActionResult> PutRecipe(int id, Recipe recipe) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != recipe.ID) { return(BadRequest()); } try { var originalRecipe = db.Recipes .Where(p => p.ID == recipe.ID) .Include(p => p.Recipe_Hops) .Include(p => p.Recipe_Malts) .Include(p => p.Recipe_Others) .SingleOrDefault(); var parentEntry = db.Entry(originalRecipe); parentEntry.CurrentValues.SetValues(recipe); //HOPS foreach (var hop in recipe.Recipe_Hops) { var originalhop = originalRecipe.Recipe_Hops .Where(c => c.ID == hop.ID && c.ID != 0) .SingleOrDefault(); if (originalhop != null) { var childEntry = db.Entry(originalhop); childEntry.CurrentValues.SetValues(hop); } else { hop.ID = 0; originalRecipe.Recipe_Hops.Add(hop); } } foreach (var originalhop in originalRecipe.Recipe_Hops.Where(c => c.ID != 0).ToList()) { if (!recipe.Recipe_Hops.Any(c => c.ID == originalhop.ID)) { db.Recipe_Hops.Remove(originalhop); } } //Malts foreach (var malt in recipe.Recipe_Malts) { var originalmalt = originalRecipe.Recipe_Malts .Where(c => c.ID == malt.ID && c.ID != 0) .SingleOrDefault(); if (originalmalt != null) { var childEntry = db.Entry(originalmalt); childEntry.CurrentValues.SetValues(malt); } else { malt.ID = 0; originalRecipe.Recipe_Malts.Add(malt); } } foreach (var originalmalt in originalRecipe.Recipe_Malts.Where(c => c.ID != 0).ToList()) { if (!recipe.Recipe_Malts.Any(c => c.ID == originalmalt.ID)) { db.Recipe_Malts.Remove(originalmalt); } } //other foreach (var other in recipe.Recipe_Others) { var originalother = originalRecipe.Recipe_Others .Where(c => c.ID == other.ID && c.ID != 0) .SingleOrDefault(); if (originalother != null) { var childEntry = db.Entry(originalother); childEntry.CurrentValues.SetValues(other); } else { other.ID = 0; originalRecipe.Recipe_Others.Add(other); } } foreach (var originalother in originalRecipe.Recipe_Others.Where(c => c.ID != 0).ToList()) { if (!recipe.Recipe_Others.Any(c => c.ID == originalother.ID)) { db.Recipe_Others.Remove(originalother); } } await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RecipeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }