public ActionResult Create([Bind(Include = "ID,Product_ID,Origin,Remain,Product_Date")] Quantity quantity) { if (ModelState.IsValid) { db.Quantities.Add(quantity); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Product_ID = new SelectList(db.Products, "ID", "Name", quantity.Product_ID); return(View(quantity)); }
public ActionResult Create([Bind(Include = "ID,Username,Password,Fullname,Email,DateOfBirth,Phone,Address,Is_Delete,Role_ID,Avatar")] User user, HttpPostedFileBase file) { string folderPath = Server.MapPath("~/Images/"); string fileName = Path.GetFileName(file.FileName); //Check whether Directory (Folder) exists. if (!Directory.Exists(folderPath)) { //If Directory (Folder) does not exists. Create it. Directory.CreateDirectory(folderPath); } user.Avatar = "/Images/" + fileName; file.SaveAs(folderPath + fileName); if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Role_ID = new SelectList(db.Roles, "ID", "Name", user.Role_ID); return(View(user)); }
public ActionResult Create([Bind(Include = "ID,Name,Description,Is_Delete,Category_ID")] Product product, Photo photoModel, HttpPostedFileBase file, Quantity quantity, int origin, DateTime product_date, decimal origin_price, decimal promotion_price, Price price) { string folderPath = Server.MapPath("~/Images/"); string fileName = Path.GetFileName(file.FileName); //Check whether Directory (Folder) exists. if (!Directory.Exists(folderPath)) { //If Directory (Folder) does not exists. Create it. Directory.CreateDirectory(folderPath); } photoModel.PhotoName = "/Images/" + fileName; file.SaveAs(folderPath + fileName); if (ModelState.IsValid) { price.Origin_Price = origin_price; price.Promotion_Price = promotion_price; price.Final_Price = origin_price - (origin_price * (promotion_price / 100)); quantity.Product_Date = product_date; quantity.Origin = origin; quantity.Remain = origin; product.Photos = new List <Photo>(); product.Quantities = new List <Quantity>(); product.Prices = new List <Price>(); product.Photos.Add(photoModel); product.Quantities.Add(quantity); product.Prices.Add(price); db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.photoName = db.Photos.Select(x => x.PhotoName); ViewBag.Category_ID = new SelectList(db.Categories, "ID", "Name", product.Category_ID); ViewBag.ID = new SelectList(db.Photos, "ID", "PhotoName", product.ID); return(View(product)); }