public User UpdateUser(User user) { _ctx.Attach(user).State = EntityState.Modified; _ctx.Entry(user).Reference(u => u.Customer).IsModified = true; _ctx.Entry(user).Reference(u => u.Employee).IsModified = true; _ctx.SaveChanges(); return(user); }
public async Task <IActionResult> Edit(int id, [Bind("CategoryId,Name,Description,IconFile")] Category category) { if (id != category.CategoryId) { return(NotFound()); } if (ModelState.IsValid) { var old_category = db.Categories.Find(id); if (category.IconFile != null && category.IconFile.Length > 0) { var fileName = old_category.Icon; var filePath = Path.Combine("wwwroot/Content/Categories/", fileName); category.Icon = fileName; using (var stream = System.IO.File.Create(filePath)) { await category.IconFile.CopyToAsync(stream); } } else { category.Icon = old_category.Icon; } db.Entry(old_category).State = EntityState.Detached; db.Categories.Update(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public async Task <IActionResult> Edit(int id, [Bind("OrderId,FirstName,LastName,Address,City,PostalCode,Email,Comment,CreatedAt,State,Price")] Order order) { if (id != order.OrderId) { return(NotFound()); } if (ModelState.IsValid) { var old_order = db.Orders.Find(id); order.CreatedAt = old_order.CreatedAt; db.Entry(old_order).State = EntityState.Detached; try { db.Orders.Update(order); await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(order.OrderId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(order)); }
public ActionResult Edit(CommentViewModel model) { if (ModelState.IsValid) { using (var db = new WebShopContext()) { //get comment var comment = db.Comments .FirstOrDefault(p => p.Id == model.Id); var productId = comment.ProductId; //set the same props comment.Id = model.Id; comment.Content = model.Content; //save in db db.Entry(comment).State = EntityState.Modified; db.SaveChanges(); //redirect to /product/details/productID return(RedirectToAction("Details", "Product", new { id = productId })); } } return(View(model)); }
public async Task <IActionResult> PutProducts(string id, Products products) { if (id != products.Id) { return(BadRequest()); } _context.Entry(products).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsExists(id)) { return(NotFound()); } else { throw; } } return(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 IHttpActionResult PutOrder(int id, Order order) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != order.OrderID) { 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 async Task <IActionResult> PutProduct([FromRoute] int id, [FromBody] Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.Id) { return(BadRequest()); } _context.Entry(product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "ShoppingCartId")] ShoppingCart shoppingCart) { if (ModelState.IsValid) { db.Entry(shoppingCart).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shoppingCart)); }
public Customer Update(Customer cust) { _ctx.Attach(cust).State = EntityState.Modified; _ctx.Entry(cust).Collection(c => c.Orders).IsModified = true; if (cust.Orders == null) { cust.Orders = new List <Order>(); } var orders = _ctx.Orders.Where(o => o.Customer.ID == cust.ID && !cust.Orders.Exists(co => co.ID == o.ID)); foreach (var order in orders) { order.Customer = null; _ctx.Entry(order).Reference(o => o.Customer).IsModified = true; } _ctx.SaveChanges(); return(cust); }
public ActionResult Edit([Bind(Include = "ProductID,ProductQuantity,ProductNumber,ProductName,ProductDescription,ProductPrice,ProductImagePath")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Edit([Bind(Include = "OrderID,OrderRef,OrderPrice,OrderDate")] Order order) { if (ModelState.IsValid) { db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(order)); }
public ActionResult Edit([Bind(Include = "Id,Name")] Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Edit([Bind(Include = "OrderItemID,OrderItemProductNumber,OrderItemName,OrderItemDescription,OrderItemPrice,OrderItemImagePath,OrderCount,OrderID")] OrderItem orderItem) { if (ModelState.IsValid) { db.Entry(orderItem).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "OrderRef", orderItem.OrderID); return(View(orderItem)); }
public ActionResult Edit([Bind(Include = "Id,Name,Price,Description,LastUpdated,CategoryId")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId); return(View(product)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Description")] Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("CategoriesList")); } return(View(category)); }
public ActionResult Edit([Bind(Include = "Id,Name,Description,Price,Discount,DiscountPrice,ImageUrl,Warranty,Available,NewProduct,CategoryId")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId); return(View(product)); }
public async Task <IActionResult> Edit(int id, [Bind("ProductId,Name,CategoryId,Description,Image,Price,CreatedAt,IsActive,File")] Product product) { if (id != product.ProductId) { return(NotFound()); } if (ModelState.IsValid) { var old_product = db.Products.Find(id); product.CreatedAt = old_product.CreatedAt; if (product.File != null && product.File.Length > 0) { var fileName = old_product.Image; var filePath = Path.Combine("wwwroot/Content/Products/", fileName); product.Image = fileName; using (var stream = System.IO.File.Create(filePath)) { await product.File.CopyToAsync(stream); } } else { product.Image = old_product.Image; } db.Entry(old_product).State = EntityState.Detached; try { db.Products.Update(product); await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.ProductId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(db.Set <Category>(), "CategoryId", "Name", product.CategoryId); return(View(product)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Description,Price,Discount,CategoryId")] Item item, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image != null) { DeleteImage(item); item = InsertImage(item, image); } db.Entry(item).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("ItemsList")); } ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", item.CategoryId); return(View(item)); }
public ActionResult Edit(ProductViewModel model, HttpPostedFileBase file) { if (ModelState.IsValid) { using (var db = new WebShopContext()) { //get products var product = db.Products .FirstOrDefault(p => p.Id == model.Id); if (!IsUserAuthorizedToEdit(product)) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } if (file != null) { string ImageName = System.IO.Path.GetFileName(file.FileName); string physicalPath = Server.MapPath("~/UploadedImages/" + ImageName); file.SaveAs(physicalPath); product.ImageUrl = ImageName; } //set the same props product.Name = model.Name; product.Price = model.Price; product.Review = model.Review; //save in db db.Entry(product).State = EntityState.Modified; db.SaveChanges(); //redirect to /product/list return(RedirectToAction($"Details/{product.Id}")); } } return(View(model)); }
public void Edit(Admin admin) { _ctx.Entry(admin).State = EntityState.Modified; _ctx.SaveChanges(); }