public ActionResult Edit([Bind(Include = "ID,Name,Description")] Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public void UpdateCategory(Category category) { using (var context = new GSDBContext()) { context.Entry(category).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void SaveCategory(Category category) { using (var context = new GSDBContext()) { context.Categories.Add(category); context.SaveChanges(); } }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Message message = db.Messages.Find(id); if (message == null) { return(HttpNotFound()); } message.isRead = true; db.Entry(message).State = EntityState.Modified; db.SaveChanges(); return(View(message)); }
public void DeleteCategory(int ID) { using (var context = new GSDBContext()) { var category = context.Categories.Where(x => x.ID == ID).Include(x => x.Products).FirstOrDefault(); context.Products.RemoveRange(category.Products); //first delete products of this category context.Categories.Remove(category); context.SaveChanges(); } }
public ActionResult Create(NewProductViewModel model) { if (ModelState.IsValid) { var newProduct = new Product(); newProduct.Name = model.Name; newProduct.Description = model.Description; newProduct.OriginalPrice = model.OriginalPrice; newProduct.SellingPrice = model.SellingPrice; newProduct.stock = model.stock; newProduct.Tags = model.Tags; newProduct.Category = db.Categories.Find(model.CategoryID); newProduct.ImageURL = model.ImageURL; newProduct.CreatedOn = DateTime.Now; newProduct.UpdatedOn = DateTime.Now; db.Products.Add(newProduct); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public JsonResult ChangeStatus(string status, int ID) { JsonResult result = new JsonResult(); result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; var order = db.Orders.Find(ID); order.Status = status; db.Entry(order).State = EntityState.Modified; result.Data = new { Success = db.SaveChanges() > 0 }; return(result); }
public JsonResult PlaceOrder(Order model) { JsonResult result = new JsonResult(); result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; Order newOrder = new Order(); newOrder.UserID = User.Identity.GetUserId(); newOrder.Datetime = DateTime.Now; newOrder.Status = "Pending"; newOrder.FirstName = model.FirstName; newOrder.LastName = model.LastName; newOrder.PhoneNumber = model.PhoneNumber; newOrder.Address1 = model.Address1; newOrder.Address2 = model.Address2; newOrder.City = model.City; newOrder.ZipCode = model.ZipCode; newOrder.TotalAmount = model.TotalAmount; newOrder.PaymentType = model.PaymentType; if (Session["cart"] != null) { List <Item> cart = (List <Item>)Session["cart"]; List <OrderItem> orderitems = new List <OrderItem>(); foreach (var item in cart) { if (item.Quantity > 0) { OrderItem orderItem = new OrderItem(); orderItem.Quantity = item.Quantity; orderItem.ProductID = item.Product.ID; Product p = db.Products.Find(item.Product.ID); p.stock = p.stock - item.Quantity; orderitems.Add(orderItem); } } newOrder.OrderItems = orderitems; db.Orders.Add(newOrder); db.SaveChanges(); Session["cart"] = null; result.Data = new { Success = true, Message = "Product Updated to cart successfully" }; } return(result); }