public async Task <IActionResult> PutUserProfile(int id, UserProfile userProfile) { if (id != userProfile.UserID) { return(BadRequest()); } _context.Entry(userProfile).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserProfileExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutShoppingList([FromRoute] int id, [FromBody] ShoppingList shoppingList) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != shoppingList.Id) { return(BadRequest()); } _context.Entry(shoppingList).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShoppingListExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutItem(int id, Item item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != item.Id) { return(BadRequest()); } db.Entry(item).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ItemExists(id)) { return(NotFound()); } else { throw; } } return(Ok(item)); }
public IHttpActionResult PutShoppingList(int id, Models.ShoppingList shoppingList) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != shoppingList.Id) { return(BadRequest()); } db.Entry(shoppingList).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ShoppingListExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutShoppingListItem(int id, ShoppingListItem shoppingListItem) { if (id != shoppingListItem.ItemID) { return(BadRequest()); } _context.Entry(shoppingListItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShoppingListItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Update(TKey id, T t) { var find = dbSet.Find(id); dbContext.Entry(find).CurrentValues.SetValues(t); Save(); }
public ActionResult Edit([Bind(Include = "ID,Name")] List list) { if (ModelState.IsValid) { db.Entry(list).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(list)); }
public ActionResult Edit([Bind(Include = "ID,ListId,Name,Checked")] Item item) { if (ModelState.IsValid) { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(item)); }
private async Task StoreModifiedListAsync(Entities.ShoppingList existingShoppingListEntity, IShoppingList shoppingList, CancellationToken cancellationToken) { var shoppingListEntityToStore = toEntityConverter.ToEntity(shoppingList); var onListMappings = existingShoppingListEntity.ItemsOnList.ToDictionary(map => map.ItemId); dbContext.Entry(shoppingListEntityToStore).State = EntityState.Modified; foreach (var map in shoppingListEntityToStore.ItemsOnList) { cancellationToken.ThrowIfCancellationRequested(); if (onListMappings.TryGetValue(map.ItemId, out var existingMapping)) { // mapping was modified map.Id = existingMapping.Id; dbContext.Entry(map).State = EntityState.Modified; onListMappings.Remove(map.ItemId); } else { // mapping was added dbContext.Entry(map).State = EntityState.Added; } } // mapping was deleted foreach (var map in onListMappings.Values) { dbContext.Entry(map).State = EntityState.Deleted; } cancellationToken.ThrowIfCancellationRequested(); await dbContext.SaveChangesAsync(); }