public async Task <ActionResult> Create(int?sectionId, int?categoriId, SectionCategory sectionCategory) { ViewBag.sections = db.Sections.ToList(); ViewBag.categories = db.Categories.ToList(); if (sectionId == null || categoriId == null) { ModelState.AddModelError("allError", "Please Enter All Info"); return(View(sectionCategory)); } sectionCategory.SectionId = (int)sectionId; sectionCategory.CategoryId = (int)categoriId; var dbcheck = db.Sections.Find(sectionId); var dbcheck2 = db.Categories.Find(categoriId); if (dbcheck == null || dbcheck2 == null) { ModelState.AddModelError("allError", "Null Database Data"); return(View(sectionCategory)); } if (!ModelState.IsValid) { return(View(sectionCategory)); } db.SectionCategories.Add(sectionCategory); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create([Bind(Include = "ProductId,ColorId,Amount")] ProductColorSize productS, int SizeId) { ViewBag.products = db.Products.ToList(); ViewBag.colors = db.Colors.ToList(); if (ModelState.IsValid) { if (productS.ProductId == 0) { ModelState.AddModelError("allError", "No product selected"); return(View(productS)); } Product product = db.Products.Find(productS.ProductId); if (product == null) { ModelState.AddModelError("allError", "Product is not valid"); return(View(productS)); } if (SizeId == 0) { ModelState.AddModelError("allError", "Size must be selected"); return(View(productS)); } Size size = db.Sizes.Find(SizeId); productS.SizeId = size.Id; if (size == null) { ModelState.AddModelError("allError", "Size is not valid"); return(View(productS)); } if (productS.ColorId == 0) { ModelState.AddModelError("allError", "Color must be selected"); return(View(productS)); } Color color = db.Colors.Find(productS.ColorId); if (size == null) { ModelState.AddModelError("allError", "Color is not valid"); return(View(productS)); } if (productS.Amount == 0) { ModelState.AddModelError("allError", "Product amount must be included"); return(View(productS)); } db.ProductColorSize.Add(productS); await db.SaveChangesAsync(); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Create([Bind(Include = "Name")] Size size) { if (!ModelState.IsValid) { return(View(size)); } db.Sizes.Add(size); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create([Bind(Include = "Photo,ProductId")] Image image) { ViewBag.products = db.Products.ToList(); if (image.ProductId == 0) { ModelState.AddModelError("allError", "Product must be selected"); return(View(image)); } if (ModelState.IsValid) { if (image.Photo != null) { if (!image.Photo.IsImage()) { ModelState.AddModelError("allError", "Photo type is not valid"); return(View(image)); } image.ImageSource = image.Photo.SaveImage("e-commerce", "~/Assets/img"); } db.Images.Add(image); await db.SaveChangesAsync(); } else { return(View(image)); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Photo")] Section section) { if (!ModelState.IsValid) { return(View(section)); } Section sectionDb = db.Sections.Find(section.Id); if (section.Photo != null) { if (!section.Photo.IsImage()) { ModelState.AddModelError("Photo", "Photo is not valid"); return(View(section)); } RemoveImage(sectionDb.Image, "~/Assets/img/"); sectionDb.Image = section.Photo.SaveImage("e-commerce", "~/Assets/img"); } sectionDb.Name = section.Name; await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create([Bind(Include = "Name,Description,AdditionDate,Price,Photo")] Product product, int?CategoryId, int?SectionId) { ViewBag.sections = db.Sections.ToList(); if (ModelState.IsValid) { if (product.Photo != null) { if (!product.Photo.IsImage()) { ModelState.AddModelError("allError", "Photo is not valid"); return(View(product)); } product.Image = product.Photo.SaveImage("e-commerce", "~/Assets/img"); } if (SectionId == null || CategoryId == null) { ModelState.AddModelError("allError", "Category or Section Id is not found"); return(View(product)); } else { var sectionCat = db.SectionCategories.Where(id => id.SectionId == SectionId && id.CategoryId == CategoryId).First(); if (sectionCat == null) { ModelState.AddModelError("allError", "Section Category is not found"); return(View()); } product.SectionCategoryId = sectionCat.Id; } db.Products.Add(product); await db.SaveChangesAsync(); } else { return(View(product)); } return(RedirectToAction("Index")); }
public async Task <ActionResult> RemoveFavourite(int id) { var user = Session["user"] as User; var favId = db.Favorites.Where(f => f.UserId == user.Id && f.ProductId == id).First(); db.Favorites.Remove(favId); await db.SaveChangesAsync(); return(Redirect(Request.UrlReferrer.ToString())); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Title,Information,Address,Number,Map")] Contact contact) { Contact contactDb = db.Contact.First(); if (!ModelState.IsValid) { ModelState.AddModelError("", "All information should be included"); return(View(contact)); } contactDb.Title = contact.Title; contactDb.Address = contact.Address; contactDb.Number = contact.Number; contactDb.Map = contact.Map; await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Photo")] GlobalSale sale) { GlobalSale saleDb = db.GlobalSales.First(); if (sale.Photo != null) { if (!sale.Photo.IsImage()) { ModelState.AddModelError("Photo", "Photo is not valid"); return(View(sale)); } RemoveImage(saleDb.Image, "~/Assets/img"); saleDb.Image = sale.Photo.SaveImage("e-commerce", "~/Assets/img"); } await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Title,Photo")] MainHeader header) { MainHeader headerDb = db.MainHeader.First(); if (header.Photo != null) { if (!header.Photo.IsImage()) { ModelState.AddModelError("Photo", "Photo is not valid"); return(View(header)); } RemoveImage(headerDb.Image, "~/Assets/img"); headerDb.Image = header.Photo.SaveImage("e-commerce", "~/Assets/img"); } headerDb.Title = header.Title; await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Email,Password,NewPassword,Image")] _Admin admin, HttpPostedFileBase photo) { var adminDb = db.Admin.Find(admin.Id); if (photo != null) { if (!photo.IsImage()) { ModelState.AddModelError("Photo", "Photo is not valid"); return(View(admin)); } //RemoveImage(adminDb.Image, "~/Assets/img"); adminDb.Image = photo.SaveImage("e-commerce", "~/Assets/img"); } if (admin.NewPassword != null) { adminDb.Password = Crypto.HashPassword(admin.NewPassword); } await db.SaveChangesAsync(); return(RedirectToAction("Index", "MainHeader")); }
public async Task <ActionResult> Register([Bind(Include = "Name,Surname,Email,Password,ConfirmPassword")] User user) { if (!ModelState.IsValid) { ModelState.AddModelError("", "All information must be filled out "); return(View(user)); } if (user.ConfirmPassword != user.Password) { ModelState.AddModelError("ConfirmPassword", "Password confirmation is not correct"); return(View(user)); } user.Password = Crypto.HashPassword(user.Password); db.Users.Add(user); await db.SaveChangesAsync(); Session["user"] = user; User currentUser = Session["user"] as User; return(RedirectToAction("Login", "Account")); }