public async Task <IActionResult> PutCart(Guid id, Cart cart) { if (id != cart.Id) { return(BadRequest()); } _context.Entry(cart).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CartExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutTransaction(int id, Transaction transaction) { if (id != transaction.Id) { return(BadRequest()); } _context.Entry(transaction).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TransactionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IHttpActionResult> PutCategory(int id, Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.id) { return(BadRequest()); } db.Entry(category).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutOrder(int id, Order order) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != order.id) { return(BadRequest()); } db.Entry(order).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public int Add(Product aType) { int key = -1; try { _db.Entry(aType).State = EntityState.Added; _db.SaveChanges(); key = aType.ProductId; } catch (Exception) { throw; } return(key); }
public IHttpActionResult PutPolicy(int id, PolicyModel policyModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var policy = db.Predicates.Include(x => x.Groups).FirstOrDefault(x => x.id == policyModel.id); if (id != policyModel.id || policy == null) { return(BadRequest()); } var oldGroupIds = policy.Groups.Select(x => x.id); var newGroupIds = policyModel.GroupIds.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x)); var groupsIdsToAdd = newGroupIds.Except(oldGroupIds); var groupsIdsToRemove = oldGroupIds.Except(newGroupIds); var groupsToAdd = db.Groups.Where(x => groupsIdsToAdd.Contains(x.id)); var groupsToRemove = db.Groups.Where(x => groupsIdsToRemove.Contains(x.id)); foreach (var group in groupsToAdd) { policy.Groups.Add(group); } foreach (var group in groupsToRemove) { policy.Groups.Remove(group); } policy.TableName = policyModel.TableName; policy.Value = policyModel.PredicateValue; db.Entry(policy).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PolicyExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit([Bind(Include = "ID,Name,MetaTitle,ParentID,DisplayOrder,SeoTitle,CreatedDate,CreatedBy,ModifiedDate,ModefiedBy,MetaKeywords,MetakeyDescriptions,Status,ShowOnHome")] Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Edit([Bind(Include = "ProductID,Price,Descrption,Name,Stock")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Edit(Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Edit([Bind(Include = "Id,Username,Password")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Login,Password")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(user)); }
public async Task <int> IncreaseShoppingCartItemQuantityAsync(int pieId, int quantity) { var shoppingCartItem = await GetShoppingCartItemAsync(pieId); if (shoppingCartItem == null) { context.ShoppingCartItem.Add(new ShoppingCartItem { ShoppingCartId = shoppingCartId, PieId = pieId, Quantity = quantity }); } else { shoppingCartItem.Quantity += quantity; context.Entry(shoppingCartItem).State = EntityState.Modified; } int count = await context.SaveChangesAsync(); return(count); }
public async Task <ActionResult> Edit([Bind(Include = "UserName,Password,Name,Gender,PhoneNumber,Email,Birthday,Address,CreateDate,Status")] Account account) { if (ModelState.IsValid) { db.Entry(account).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(account)); }
public ActionResult Edit([Bind(Include = "Id,Name,ImageData,CategoryId")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId); return(View(product)); }
public IHttpActionResult PutGroup(int id, GroupModel groupModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var group = db.Groups.Include(x => x.Employees).FirstOrDefault(x => x.id == groupModel.id); if (id != groupModel.id || group == null) { return(BadRequest()); } var oldEmployeeIds = group.Employees.Select(x => x.id); var newEmployeeIds = groupModel.EmployeeIds.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x)); var employeeIdsToAdd = newEmployeeIds.Except(oldEmployeeIds); var employeeIdsToRemove = oldEmployeeIds.Except(newEmployeeIds); var employeesToAdd = db.Employees.Where(x => employeeIdsToAdd.Contains(x.id)); var employeesToRemove = db.Employees.Where(x => employeeIdsToRemove.Contains(x.id)); foreach (var employee in employeesToAdd) { group.Employees.Add(employee); } foreach (var employee in employeesToRemove) { group.Employees.Remove(employee); } db.Entry(group).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!GroupExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void EditProduct([Bind(Include = "Id,Name,ImageData,ImageFile,CategoryId")] Product product) { var file = product.ImageFile; if (file != null && file.ContentLength > 0) { if (product.ImageData != "default.png") { System.IO.File.Delete(Server.MapPath("~/Content/Images/" + product.ImageData)); } file.SaveAs(Server.MapPath("~/Content/Images/" + file.FileName)); product.ImageData = file.FileName; } db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return; }
public override async Task <T> Select(Object PkId, IEnumerable <string> navproperties = null) { var model = await table.FindAsync(PkId); if (model != null && navproperties != null) { foreach (var property in navproperties) { try { _dbContext.Entry(model).Collection(property).Load(); } catch (Exception ex) { } } } return(model); }
/// <summary> /// Updates table entity passed to it /// </summary> /// <param name="entity"></param> public void Update(Tbl_Entity entity) { _dbSet.Attach(entity); _DBEntity.Entry(entity).State = EntityState.Modified; }
public virtual void Update(T entity) { dbset.Attach(entity); dataContext.Entry(entity).State = EntityState.Modified; }