public IHttpActionResult PutShopKeeper(int id, ShopKeeper shopKeeper) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != shopKeeper.ID) { return(BadRequest()); } db.Entry(shopKeeper).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ShopKeeperExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "ID,BrandName")] Brand brand) { if (ModelState.IsValid) { db.Brands.Add(brand); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brand)); }
public ActionResult Create([Bind(Include = "ID,Name,BrandID")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BrandID = new SelectList(db.Brands, "ID", "BrandName", product.BrandID); return(View(product)); }
public ActionResult Delete(int id) { if (Session["SignIn"] == null) { return(RedirectToAction("SignUp", "MainProcess")); } else { User b = (User)Session["SignIn"]; if (b.role == "admin") { ComputerShopEntities data = new ComputerShopEntities(); var u = data.InfoProducts.Where(x => x.Id == id).FirstOrDefault(); var y = data.Images.Where(k => k.idProduct == id).FirstOrDefault(); if (u != null) { if (y != null) { data.Images.Remove(y); } data.InfoProducts.Remove(u); data.SaveChanges(); } return(RedirectToAction("IndexAdmin", "MainProcess")); } else { return(RedirectToAction("ThongBao", new { tenaction = "Contact" })); } } }
public ActionResult SignUp(ClassSignUp SignUp) { ComputerShopEntities data = new ComputerShopEntities(); int a = data.Users.Where(x => x.UserName.Equals(SignUp.userName)).Count(); if (a == 0) { User user = new User(); user.UserName = SignUp.userName; user.PassWord = SignUp.passWord; user.Address = SignUp.address; user.Phone = SignUp.Phone; user.role = "Member"; if (SignUp.rePassWord != SignUp.passWord) { ViewBag.a = "Mật Khẩu và Nhập Lại Mật Khẩu Không Đúng"; return(View()); } else { ViewBag.a = "Đăng kí thành công"; data.Users.Add(user); data.SaveChanges(); return(View()); } } else { ViewBag.b = "Tên đăng nhập đã tồn tại"; return(View()); } }
public ActionResult AddProduct(ClassProduct a, Image imageModel, HttpPostedFileBase ImageFile) { ComputerShopEntities data = new ComputerShopEntities(); InfoProduct b = new InfoProduct(); b.Name = a.Name; b.Price = a.price; b.Description = a.description; b.idProductType = a.idProduct; data.InfoProducts.Add(b); data.SaveChanges(); imageModel.idProduct = b.Id; imageModel.Title = b.Name; string fileName = Path.GetFileNameWithoutExtension(ImageFile.FileName); string extension = Path.GetExtension(ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; imageModel.ImagePath = fileName; fileName = Path.Combine(Server.MapPath("~/img/"), fileName); ImageFile.SaveAs(fileName); using (ComputerShopEntities db = new ComputerShopEntities()) { db.Images.Add(imageModel); db.SaveChanges(); ViewBag.a = "Thêm sản phẩm thành cống"; } ModelState.Clear(); return(View()); }
public ActionResult Edit(ClassProduct a, Image imageModel, HttpPostedFileBase ImageFile) { ComputerShopEntities data = new ComputerShopEntities(); var u = data.InfoProducts.Where(x => x.Id == a.id).FirstOrDefault(); var y = data.Images.Where(k => k.idProduct == a.id).FirstOrDefault(); if (u != null) { if (y != null) { data.Images.Remove(y); } data.InfoProducts.Remove(u); data.SaveChanges(); } InfoProduct b = new InfoProduct(); b.Name = a.Name; b.Price = a.price; b.Description = a.description; b.idProductType = a.idProduct; data.InfoProducts.Add(b); data.SaveChanges(); imageModel.idProduct = b.Id; imageModel.Title = b.Name; string fileName = Path.GetFileNameWithoutExtension(ImageFile.FileName); string extension = Path.GetExtension(ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; imageModel.ImagePath = fileName; fileName = Path.Combine(Server.MapPath("~/img/"), fileName); ImageFile.SaveAs(fileName); using (ComputerShopEntities db = new ComputerShopEntities()) { db.Images.Add(imageModel); db.SaveChanges(); ViewBag.a = "Sửa thành công"; } ModelState.Clear(); return(View()); }
public ActionResult AddToCart(string name, int amount, float TotalPrice) { try { if (Session["SignIn"] != null) { User b = (User)Session["SignIn"]; if (b.role == "admin" || b.role == "Member") { ComputerShopEntities data = new ComputerShopEntities(); cart c = new cart(); c.Name = name; c.Amount = amount; c.TotalPrice = TotalPrice; c.Name = b.UserName; c.Phone = b.Phone; c.Address = b.Address; data.carts.Add(c); data.SaveChanges(); return(Json(1)); } else { return(RedirectToAction("ThongBao", new { tenaction = "Contact" })); } } else { return(Json(0)); } } catch (Exception ex) { throw ex; } }