public ActionResult Create([Bind(Include = "StaffID,FirstName,LastName,Email,Phone,Address,Password," + " ConfirmPassword,CreatedDate,DivisionID," + "ProfileImg,StoreID,Gender,Salary,Role,Status")] Staff staff, HttpPostedFileBase ProfileImg) { if (ModelState.IsValid) { var isExist = IsEmailExist(staff.Email); if (!isExist) { string postedFileName = System.IO.Path.GetFileName(ProfileImg.FileName); //Lưu hình đại diện về Server var path = Server.MapPath("~/Assets/images/Staffs/" + postedFileName); ProfileImg.SaveAs(path); staff.ProfileImg = "~/Assets/images/Staffs/" + postedFileName; staff.CreatedDate = DateTime.Now; db.Staffs.Add(staff); db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Email already exist"); } } ViewBag.StoreID = new SelectList(db.Stores, "StoreID", "StoreName", staff.StoreID); ViewBag.DivisionID = new SelectList(db.Divisions, "DivisionID", "Name", staff.DivisionID); return(View(staff)); }
public ActionResult Create([Bind(Include = "ProductID,Name,BrandID,CategoryID,Price,ProductImg, Description, Status")] Product product, HttpPostedFileBase ProductImg) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { var isExist = IsProductNameExist(product.Name); if (!isExist) { string postedFileName = Path.GetFileName(ProductImg.FileName); var path = Server.MapPath("/Assets/images/" + postedFileName); ProductImg.SaveAs(path); product.ProductImg = "/Assets/images/" + postedFileName; product.Status = true; db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Product already exists"); } } ViewBag.BrandID = new SelectList(db.Brands, "BrandID", "Name", product.BrandID); ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name", product.CategoryID); return(View(product)); }
public ActionResult Create([Bind(Include = "OrderID,ProductID,Quanlity,Price")] OrderItem orderItem) { var product = db.Products.Where(d => d.ProductID == orderItem.ProductID).FirstOrDefault(); var stock = db.Stocks.Where(d => d.ProductID == orderItem.ProductID).FirstOrDefault(); var maMax = db.Orders.ToList().Select(n => n.OrderID).Max(); orderItem.OrderID = maMax; if (ModelState.IsValid) { if (orderItem.Quanlity > stock.Quantity || orderItem.Quanlity <= 0) { ViewBag.Message = "This amount of product is not availble, there are only " + stock.Quantity + " left!"; ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "OrderID", orderItem.OrderID); ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Name", orderItem.ProductID); return(View()); } orderItem.Price = product.Price; db.OrderItems.Add(orderItem); db.SaveChanges(); ViewBag.Message = "Added successfully!"; ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "OrderID", orderItem.OrderID); ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Name", orderItem.ProductID); return(View()); } return(View(orderItem)); }
public ActionResult Create([Bind(Include = "Id,DivisionID,Name,ManagerID")] Division division) { if (ModelState.IsValid) { db.Divisions.Add(division); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "FullName"); return(View(division)); }
public ActionResult Create([Bind(Include = "Id,Name,Message,Email,DateSent,Subject")] Conntact conntact) { if (ModelState.IsValid) { db.Conntacts.Add(conntact); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(conntact)); }
public ActionResult Create([Bind(Include = "StoreID,StoreName,Address,Phone")] Store store) { if (ModelState.IsValid) { db.Stores.Add(store); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(store)); }
public ActionResult Create([Bind(Include = "CategoryID,Name")] Category category) { if (ModelState.IsValid) { category.Status = true; db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "StoreID,ProductID,Quantity")] Stock stock) { if (ModelState.IsValid) { db.Stocks.Add(stock); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Name", stock.ProductID); ViewBag.StoreID = new SelectList(db.Stores, "StoreID", "StoreName", stock.StoreID); return(View(stock)); }
public ActionResult Registration(Customer customer) { // Model Validation if (ModelState.IsValid) { var isExist = IsEmailExist(customer.Email); if (isExist) { ModelState.AddModelError("", "Email already exist"); return(View(customer)); } customer.Password = Crypto.Hash(customer.Password); customer.ConfirmPassword = Crypto.Hash(customer.ConfirmPassword); using (ESDatabaseEntities dc = new ESDatabaseEntities()) { dc.Customers.Add(customer); dc.SaveChanges(); } ViewBag.Message = "Account created successfully, please log-in!"; } return(View("Login")); }
public ActionResult Create([Bind(Include = "BrandID,Name,BrandImg")] Brand brand, HttpPostedFileBase BrandImg) { if (ModelState.IsValid) { string postedFileName = System.IO.Path.GetFileName(BrandImg.FileName); //Lưu hình đại diện về Server var path = Server.MapPath("/Assets/images/" + postedFileName); BrandImg.SaveAs(path); brand.BrandImg = "/Assets/images/" + postedFileName; brand.Status = true; db.Brands.Add(brand); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brand)); }
public ActionResult Create([Bind(Include = "OrderID,CustomerID,StaffID," + "OrderDate,ShippedDate,StoreID,OrderStatus,Total,Status")] Order order) { if (ModelState.IsValid) { order.OrderDate = DateTime.Now; order.Status = true; db.Orders.Add(order); db.SaveChanges(); } var id = db.Orders.ToList().Select(n => n.OrderID).Max(); return(RedirectToAction("Index", "OrderItems", new { id })); //ViewBag.StoreID = new SelectList(db.Stores, "StoreID", "StoreName", order.StoreID); //ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "FirstName", order.CustomerID); //ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "FirstName", order.StaffID); //return View(order); }
public ActionResult Create([Bind(Include = "CustomerID, FirstName, LastName, Email" + ",Address, Password, ConfirmPassword, CreatedDate, ProfileImg, Status")] Customer customer) { if (ModelState.IsValid) { var isExist = IsEmailExist(customer.Email); if (isExist) { ModelState.AddModelError("", "Email already exists"); return(View(customer)); } try { customer.Password = Crypto.Hash(customer.Password); customer.ConfirmPassword = Crypto.Hash(customer.ConfirmPassword); customer.CreatedDate = DateTime.Now; customer.Status = true; db.Customers.Add(customer); db.SaveChanges(); // your code for insert here } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Contact(Conntact contact) { if (ModelState.IsValid) { contact.DateSent = DateTime.Now; db.Conntacts.Add(contact); db.SaveChanges(); } return(View()); }