public ActionResult DatHang() { // Kiem tra don dat hang if (Session["GioHang"] == null) { RedirectToAction("index", "Home"); } // Them don hang Order order = new Order(); List <Cart> cart = GetCart(); order.CreatedDate = DateTime.Now; db.Orders.Add(order); db.SaveChanges(); // Them chi tiet don hang foreach (var item in cart) { OrderDetail order_Detail = new OrderDetail(); order_Detail.OrderID = order.id; order_Detail.ProductID = item.iMaSP; order_Detail.Quantity = (int)item.isoLuong; db.OrderDetails.Add(order_Detail); } db.SaveChanges(); return(RedirectToAction("index", "Home")); }
public ActionResult Create([Bind(Include = "CategoryID,NameCategory")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Edit(Order order) { if (ModelState.IsValid) { db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(order)); var statusItems = new[] { new { Id = "0", Name = "Đang chờ xác nhận" }, new { Id = "1", Name = "Đã nhận" }, new { Id = "2", Name = "Đang xử lý và đóng gói " }, new { Id = "3", Name = "Đang trên đường giao hàng" }, new { Id = "4", Name = "Đã nhận hàng" } }; }
public ActionResult Create(Contact contact, string message, string Feedback_Detail) { if (ModelState.IsValid) { using (var scope = new TransactionScope()) { try { Convert.ToInt32(contact.Phone); } catch (Exception) { return(View(contact)); } try { contact.Status = 0; db.Contacts.Add(contact); db.SaveChanges(); var detail = new ContactDetail(); detail.ContactID = contact.ContactID; detail.CreatedDate = DateTime.Now; detail.Message = message; detail.EmployeeName = ""; db.ContactDetails.Add(detail); db.SaveChanges(); scope.Complete(); return(RedirectToAction("Index")); } catch (Exception) { } } } return(View(contact)); }
public ActionResult Create(Product product) { checkProductCode(product); checkPrice(product); //Kiểm tra giá trị giá gốc và giá bán phải lớn hơn 0. checkProductCodeCreate(product); //Kiểm tra mã sản phẩm đã tồn tại hay chưa. checkQuantityAndStatus(product); //Kiểm tra mốc số lượng và tình trạng if (ModelState.IsValid) { using (var scope = new TransactionScope()) { //thêm model vào database product.CreatedDate = DateTime.Now; product.UpdateDate = DateTime.Now; db.Products.Add(product); db.SaveChanges(); //gán hình vào file app_data var path = Server.MapPath("~/Content/Images"); path = System.IO.Path.Combine(path, product.ID.ToString()); //file ảnh sản phẩm sẽ có tên là id của sẩn phẩm. Request.Files["Image"].SaveAs(path); product.ImageURL = path; //ImageURL sẽ lưu đường dẫn tới file ảnh. //All done successfully db.SaveChanges(); scope.Complete(); return(RedirectToAction("Index")); } } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "NameCategory", product.CategoryID); var statusItems = new[] { new { Id = "DEACTIVE", Name = "Hết hàng" }, new { Id = "ACTIVE", Name = "Còn hàng" }, }; ViewBag.Status = new SelectList(statusItems, "Id", "Name"); return(View(product)); }
public ActionResult Edit(ContactDetail ct) { if (ModelState.IsValid) { try { db.Entry(ct).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { } } return(View(ct)); }