public ActionResult Create([Bind(Include = "IdContact,FirstName,LastName,Email,Message")] Contact contact) { if (ModelState.IsValid) { db.Contacts.Add(contact); db.SaveChanges(); return(RedirectToAction("ContactSuccsess")); } return(View(contact)); }
public ActionResult Create([Bind(Include = "CategoryID,ShowOnHome,CategoryName,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,MetaKeywords")] Category category) { if (ModelState.IsValid) { category.CreatedDate = DateTime.Now; db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "SupplierID,SupplierName,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy")] Supplier supplier) { if (ModelState.IsValid) { supplier.CreatedDate = DateTime.Now; db.Suppliers.Add(supplier); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
public ActionResult Create([Bind(Include = "ID,Image,DisplayOrder,Link,Description,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,Status")] Slide slide, HttpPostedFileBase Image) { if (ModelState.IsValid) { if (Image != null) { var fileName = Path.GetFileName(Image.FileName); slide.Image = fileName; string path = Path.Combine(Server.MapPath("~/Images"), fileName); Image.SaveAs(path); } db.Slides.Add(slide); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(slide)); }
public ActionResult Create(Customer cus) { cus.CreatedDay = DateTime.Now; db.Customers.Add(cus); db.SaveChanges(); return(RedirectToAction("Order_Success", "ShoppingCart")); //try //{ // if (ModelState.IsValid) // { // db.Customers.Add(cus); // db.SaveChanges(); // return RedirectToAction("ShowToCart", "ShoppingCart"); // } // return View(); //} //catch //{ // return Content("Error"); //} }
public ActionResult ProceedOrder(Customer cus) { var check = db.Customers.Where(s => s.Email_Cus.Equals(cus.Email_Cus) && s.Password.Equals(cus.Password)).FirstOrDefault(); if (check == null) { return(Content("Error checkout!!!!!")); } else { try { Cart cart = Session["Cart"] as Cart; var result = from r in db.Customers where r.Email_Cus == cus.Email_Cus select r; var cus2 = result.ToList().First(); Order _order = new Order(); _order.OrderDate = DateTime.Now; _order.Email_Cus = cus2.Email_Cus; _order.SDT_Cus = cus2.Phone_Cus; _order.Password_cus = cus2.Password; _order.Descriptions = cus2.Address_Cus; _order.CodeCus = cus2.CodeCus; db.Orders.Add(_order); foreach (var item in cart.Items) { OrderDetail _order_Detail = new OrderDetail(); _order_Detail.IDOrder = _order.IDOrder; _order_Detail.IDProduct = item._shopping_product.IDProduct; _order_Detail.UnitPriceSale = item._shopping_product.Price; _order_Detail.QuantitySale = item._shopping_quantity; db.OrderDetails.Add(_order_Detail); } db.SaveChanges(); cart.ClearCart(); return(RedirectToAction("Shopping_Success", "ShoppingCart")); } catch { return(Content("Error checkout!!!!!")); } } }
public ActionResult Register(User _user) { if (ModelState.IsValid) { var check = _db.Users.FirstOrDefault(s => s.Email == _user.Email); if (check == null) //email chua co nguoi dang ky { _user.Password = GetMD5(_user.Password); _db.Configuration.ValidateOnSaveEnabled = false; _db.Users.Add(_user); _db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.error = "Email already exist! Use another email!"; return(View()); } } return(View()); }
public ActionResult Edit([Bind(Include = "IDProduct,ProductName,MetaTitle,Description,Image,MoreImage1,MoreImage2,MoreImage3,Price,Entryprice,PromotionPrice,IncludedVAT,Quantity,CategoryID,SupplierID,Detail,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy")] Product product, HttpPostedFileBase Image, HttpPostedFileBase MoreImage1, HttpPostedFileBase MoreImage2, HttpPostedFileBase MoreImage3) { if (ModelState.IsValid) { if (product.Image != null) { try { var fileName = Path.GetFileName(Image.FileName); product.Image = fileName; var path = Path.Combine(Server.MapPath("~/Images"), fileName); Image.SaveAs(path); } catch { } } if (MoreImage1 != null && MoreImage1.ContentLength > 0) { try { var fileName1 = Path.GetFileName(MoreImage1.FileName); product.MoreImage1 = fileName1; var path1 = Path.Combine(Server.MapPath("~/Images"), fileName1); Image.SaveAs(path1); } catch { } } if (MoreImage2 != null && MoreImage2.ContentLength > 0) { try { var fileName2 = Path.GetFileName(MoreImage2.FileName); product.MoreImage2 = fileName2; var path2 = Path.Combine(Server.MapPath("~/Images"), fileName2); Image.SaveAs(path2); } catch { } } if (MoreImage3 != null && MoreImage3.ContentLength > 0) { try { var fileName3 = Path.GetFileName(MoreImage3.FileName); product.MoreImage3 = fileName3; var path3 = Path.Combine(Server.MapPath("~/Images"), fileName3); Image.SaveAs(path3); } catch { } } product.ModifiedDate = DateTime.Now; db.Entry(product).State = EntityState.Modified; if (Image == null) { db.Entry(product).Property(m => m.Image).IsModified = false; } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID); ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", product.SupplierID); return(View(product)); }