public SubCategory CreateSubCategory(SubCategory subCategory) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } _context.SubCategories.Add(subCategory); _context.SaveChanges(); return(subCategory); }
public ActionResult Create([Bind(Include = "Id,Name,Icons")] Category category) { Category selectedCategory = db.Categories.FirstOrDefault(ct => ct.Name.ToLower() == category.Name.ToLower()); if (ModelState.IsValid) { if (selectedCategory == null) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(category)); }
public ActionResult Edit([Bind(Include = "Id,Title,Description,AboutImage")] AboutU aboutUs) { if (ModelState.IsValid) { db.Entry(aboutUs).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aboutUs)); }
public ActionResult Create([Bind(Include = "id,BrendImg")] Brend brend, HttpPostedFileBase Photo) { if (ModelState.IsValid) { if (Photo != null) { WebImage image = new WebImage(Photo.InputStream); FileInfo photoInfo = new FileInfo(Photo.FileName); string newPhoto = Guid.NewGuid().ToString() + photoInfo.Extension; image.Save("~/Uploads/Brands/" + newPhoto); brend.BrendImg = "/Uploads/Brands/" + newPhoto; } db.Brends.Add(brend); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brend)); }
public ActionResult Create([Bind(Include = "Id,SlideImg")] Slide slide, HttpPostedFileBase Photo) { if (ModelState.IsValid) { if (Photo != null) { WebImage image = new WebImage(Photo.InputStream); FileInfo photoInfo = new FileInfo(Photo.FileName); string newPhoto = Guid.NewGuid().ToString() + photoInfo.Extension; image.Save("~/Uploads/ProjectImage/" + newPhoto); slide.SlideImg = "/Uploads/ProjectImage/" + newPhoto; } db.Slides.Add(slide); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(slide)); }
public ActionResult Edit([Bind(Include = "Id,Phone,HomePhone,Email,WorkDate,Adress")] Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public ActionResult Create([Bind(Include = "Id,Name,Description")] Option options, int id) { ViewBag.proList = db.Products.ToList(); if (ModelState.IsValid) { Option opt = db.Options.Add(options); db.SaveChanges(); db.ProductOptions.Add(new ProductOption { OptionsId = opt.Id, ProductId = id }); db.SaveChanges(); return(RedirectToAction("Index", new { id = id })); } return(View(options)); }
public ActionResult Create([Bind(Include = "Id,Name,CategoryId,isPcCollect")] SubCategory subCategory, bool isPcCollectVal = false) { if (ModelState.IsValid) { if (isPcCollectVal) { subCategory.isPcCollect = 1; } else { subCategory.isPcCollect = 0; } db.SubCategories.Add(subCategory); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", subCategory.CategoryId); return(View(subCategory)); }
public ActionResult Create([Bind(Include = "Id,Name,CategoryImg")] Category category, HttpPostedFileBase Photo) { Category selectedCategory = db.Categories.FirstOrDefault(ct => ct.Name.ToLower() == category.Name.ToLower()); if (ModelState.IsValid) { if (selectedCategory == null && Photo == null) { WebImage image = new WebImage(Photo.InputStream); FileInfo photoInfo = new FileInfo(Photo.FileName); string newPhoto = Guid.NewGuid().ToString() + photoInfo; image.Save("~/Uploads/" + newPhoto); category.CategoryImg = "/Uploads/" + newPhoto; db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(category)); }
public ActionResult Edit(int id, [Bind(Include = "Id,Name,Description,Image")] ImageCategory imageCategory, HttpPostedFileBase Photo) { if (ModelState.IsValid) { ImageCategory selected = db.ImageCategories.SingleOrDefault(nt => nt.Id == id); if (Photo != null) { WebImage image = new WebImage(Photo.InputStream); FileInfo photoInfo = new FileInfo(Photo.FileName); string newPhoto = Guid.NewGuid().ToString() + photoInfo; image.Save("~/Uploads/ProjectImage/" + newPhoto); imageCategory.Image = "/Uploads/ProjectImage/" + newPhoto; } selected.Image = imageCategory.Image; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(imageCategory)); }
private int CheckMarkaName(string markaname) { Marka selectedmarka = db.Markas.FirstOrDefault(mr => mr.MarkaName.ToUpper() == markaname.ToUpper()); if (selectedmarka == null) { Marka newMarka = db.Markas.Add(new Marka { MarkaName = markaname }); db.SaveChanges(); return(newMarka.Id); } return(selectedmarka.Id); }
public ActionResult Index(int?Id, string quantity) { object data = null; if (Id == null) { data = new { status = 404, message = "Id not Found", response = "", Url = "Home/Index" }; return(Json(data, JsonRequestBehavior.AllowGet)); } ; var prc = db.Products.Select(pr => new { pr.Id, pr.Name, pr.Price, }).FirstOrDefault(pc => pc.Id == Id); if (prc == null) { data = new { status = 404, message = "Id doesn't exist", response = "", Url = "Home/Index" }; return(Json(data, JsonRequestBehavior.AllowGet)); } ; if (!(Session["user"] is ApplicationUser appUser)) { return(RedirectToAction("Index", "Home")); } if (appUser != null) { int quant = Convert.ToInt32(quantity); db.Orders.Add(new Order { ProductId = prc.Id, OrderDate = DateTime.Now, Quantity = quant, UserId = appUser.Id, Price = (double)prc.Price, TotalPrice = quant * (double)prc.Price }); db.SaveChanges(); data = new { status = 200, message = "Succes", response = prc }; } return(Json(data, JsonRequestBehavior.AllowGet)); }