public ActionResult Create([Bind(Include = "Id,ParentId,Name,SortOrder,Status")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } // BEGIN: Tạo ra dropdownlist cho trường Status var statusItems = new[] { new { Id = "ACTIVE", Name = "Active" }, new { Id = "DEACTIVE", Name = "Deactive" }, }; ViewBag.Status = new SelectList(statusItems, "Id", "Name"); // END: Tạo ra dropdownlist cho trường Status // BEGIN: Tạo ra dropdownlist cho trường ParentId var categories = db.Categories.Where(x => x.ParentId == 0).ToList(); var root = new Category(); root.Id = 0; root.Name = ""; categories.Add(root); ViewBag.ParentId = new SelectList(categories, "Id", "Name"); // END: Tạo ra dropdownlist cho trường ParentId return(View(category)); }
public ActionResult Create([Bind(Include = "Id,Name,ImageUrl,Price,Discount,Stock,Description,CategoryId,SupplierId")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } var parentCategories = db.Categories.Where(x => x.ParentId == 0).OrderBy(x => x.SortOrder).ToList(); ViewBag.ParentCategoryId = new SelectList(parentCategories, "Id", "Name"); var categories = new List <Category> { new Category() { Id = 0, Name = "[Select a category]", ParentId = 0, SortOrder = -1, Status = true } }; ViewBag.CategoryId = new SelectList(categories, "Id", "Name"); return(View(product)); }
public 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 { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "Id,ParentId,Name,SortOrder,Status")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "Id,Code,CreatedDate,ContactName,ContactAddress,ContactPhone,ContactEmail,Status,CustomerId")] Order order) { if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(order)); }
public ActionResult Create([Bind(Include = "Id,Name,SubTitle,ImageUrl,TargetUrl,SortOrder,Status")] Slider slider) { if (ModelState.IsValid) { db.Sliders.Add(slider); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(slider)); }
//[ValidateInput(false)] public ActionResult Create([Bind(Include = "Id,CategoryId,Code,Name,Price,Stock,Description,Notes,Discount,DisplayPosition,Status,SortOrder")] Product product) { if (ModelState.IsValid) { product.CreatedDate = DateTime.Now; product.ImageUrl = "#"; db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId); return(View(product)); }
public ActionResult CheckOut([Bind(Include = "ContactName,ContactAddress,ContactPhone,ContactEmail")] Order order) { using (var db = new OnlineShopDb()) { order.CreatedDate = DateTime.Now; order.Status = "PENDING"; order.CustomerId = null; // var userId = User.Identity.GetUserId(); order.Code = Guid.NewGuid().ToString(); var shoppingCart = (ShoppingCart)Session["ShoppingCart"]; foreach (var item in shoppingCart.ShoppingCartItems) { var orderDetail = new OrderDetail(); orderDetail.ProductId = item.Item.Id; orderDetail.Quantity = item.Quantity; orderDetail.Discount = item.Item.Discount; orderDetail.Price = item.Item.Price; order.OrderDetails.Add(orderDetail); } db.Orders.Add(order); db.SaveChanges(); Session["ShoppingCart"] = null; return(RedirectToAction("Index", "Home")); } }
public ActionResult DeleteProductImage(int deleteId) { using (var db = new OnlineShopDb()) { var item = db.ProductImages.Find(deleteId); if (item != null) { // XÓA HÌNH var pathToDetele = Server.MapPath(item.ImageUrl); if (System.IO.File.Exists(pathToDetele)) { System.IO.File.Delete(pathToDetele); } // XÓA TRONG DATABASE var productId = item.ProductId; db.ProductImages.Remove(item); db.SaveChanges(); return(RedirectToAction("UploadDetailsImages", "ManageProducts", new { id = productId })); } return(HttpNotFound()); } }