public async Task <IActionResult> Edit(List <string> Names, int?id) { if (id == null) { return(RedirectToAction("error", "home")); } List <ColorLanguage> colorLanguages = await db.ColorLanguage.Where(cl => cl.ColorId == id).Include(cl => cl.Language).ToListAsync(); if (colorLanguages == null) { return(RedirectToAction("error", "home")); } if (Checker.CheckList(Names)) { for (int i = 0; i < colorLanguages.Count; i++) { colorLanguages[i].Name = Names[i]; db.SaveChanges(); } } else { ModelState.AddModelError("", "Fill all Blanks"); return(View(colorLanguages)); } return(RedirectToAction("index", "color")); }
public async Task <IActionResult> Edit(List <string> Texts, string Link, int?id) { if (id == null) { return(RedirectToAction("error", "home")); } List <NotiLanguage> notiLanguage = await db.NotiLanguage.Where(nl => nl.NotiId == id).Include(nl => nl.Language).ToListAsync(); if (notiLanguage == null) { return(RedirectToAction("error", "home")); } if (Checker.CheckList(Texts)) { for (int i = 0; i < notiLanguage.Count; i++) { notiLanguage[i].Text = Texts[i]; db.SaveChanges(); } } else { ModelState.AddModelError("", "Fill all Blanks"); return(View(notiLanguage)); } return(RedirectToAction("index", "noti")); }
public static void Main(string[] args) { IWebHost webHost = CreateWebHostBuilder(args).Build(); using (IServiceScope scope = webHost.Services.CreateScope()) { using (DahlizDb db = scope.ServiceProvider.GetRequiredService <DahlizDb>()) { if (!db.Languages.Any()) { Language az = new Language() { Key = "az", Value = "Azerbaijan", Icon = "az.png" }; Language en = new Language() { Key = "en", Value = "English", Icon = "en.png" }; db.Languages.AddRange(az, en); db.SaveChanges(); } Seed.UserCreator(scope, db).Wait(); } } webHost.Run(); }
public IActionResult Edit(List <string> Names, int CategoryId) { List <CategoryLanguage> categoryLanguages = db.CategoryLanguages.Where(cl => cl.CategoryId == CategoryId).Include(cl => cl.Language).ToList(); if (Checker.CheckList(Names)) { for (int i = 0; i < categoryLanguages.Count; i++) { categoryLanguages[i].Name = Names[i]; } db.SaveChanges(); } else { ModelState.AddModelError("", "Fill all Blanks"); return(View(categoryLanguages)); } return(RedirectToAction("index", "category")); }
public IActionResult Delete(int?subcategoryId) { if (subcategoryId == null) { return(RedirectToAction("error", "home")); } List <SubcategoryLanguage> subcategoryLanguages = db.SubcategoryLanguages.Where(cl => cl.SubcategoryId == subcategoryId).ToList(); Subcategory subcategory = db.Subcategories.Find(subcategoryId); db.Subcategories.Remove(subcategory); db.SubcategoryLanguages.RemoveRange(subcategoryLanguages); db.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public async Task <JsonResult> Review(ReviewModel model) { if (ModelState.IsValid) { string productId = HttpContext.Session.GetString("product_id"); User user = await db.Users.Where(u => u.Id == HttpContext.GetUserInfoFromSession("user_id")).FirstOrDefaultAsync(); if (user != null && productId != null) { ProductReview productReview = new ProductReview(); productReview.User = user; productReview.Desc = model.Text; productReview.CreatedDate = DateTime.Now; productReview.ProductId = Convert.ToInt32(productId); productReview.Rating = Convert.ToInt32(Convert.ToDouble(model.Rate)); productReview.Status = false; db.ProductReviews.Add(productReview); db.SaveChanges(); return(Json(new { status = 200, data = productReview })); } else { return(Json(new { status = 400, error = "User is not logged in" })); } } else { return(Json(new { status = 400, error = "Modelstate is not valid" })); } }
public IActionResult Add(ProductModel model) { if (ModelState.IsValid) { if (model.SubCategoryId != 0 && model.CategoryId != 0) { #region Product Static Properties Add Product product = new Product(); product.CreatedDate = DateTime.Now; product.DiscountPercent = Convert.ToInt32(model.DiscountPercent); product.Price = Math.Ceiling(Convert.ToDecimal(model.Price)); product.SubcategoryId = model.SubCategoryId; for (int i = 0; i < model.Count.Count; i++) { product.Quantity += Convert.ToInt32(model.Count[i]); } //product.Quantity = Convert.ToInt32(model.Quantity); db.Products.Add(product); #endregion List <Language> languages = db.Languages.ToList(); if (Checker.CheckList(model.Names) && Checker.CheckList(model.Sizes) && Checker.CheckList(model.Count) && Checker.CheckList(model.Descriptions) && Checker.CheckList(model.Photos)) { #region Product Language Add for (int i = 0; i < languages.Count; i++) { ProductLanguage productLanguage = new ProductLanguage(); productLanguage.LanguageId = languages[i].Id; productLanguage.Name = model.Names[i]; productLanguage.ProductId = product.Id; productLanguage.Description = model.Descriptions[i]; db.ProductLanguages.Add(productLanguage); } #endregion #region Product Size Add for (int i = 0; i < model.Sizes.Count; i++) { ProductSizeCount productSizeCount = new ProductSizeCount(); productSizeCount.ProductId = product.Id; productSizeCount.SizeId = model.Sizes[i]; productSizeCount.Count = Convert.ToInt32(model.Count[i]); db.ProductSizeCounts.Add(productSizeCount); } #endregion //#region Product Color Add //for (int i = 0; i < model.Colors.Count; i++) //{ // ProductColor productColor = new ProductColor(); // productColor.ProductId = product.Id; // productColor.ColorId = model.Colors[i]; // db.ProductColors.Add(productColor); //} //#endregion #region Product Photo Add for (int i = 0; i < model.Photos.Count; i++) { ProductPhoto productPhoto = new ProductPhoto(); productPhoto.Product = product; productPhoto.PhotoPath = model.Photos[i]; db.ProductPhotos.Add(productPhoto); } #endregion db.SaveChanges(); HttpContext.Session.SetString("productId", product.Id.ToString()); return(RedirectToAction(nameof(Index))); } else { ModelState.AddModelError("", "Category or Subcategory not selected"); return(RedirectToAction(nameof(Add))); } } else { ModelState.AddModelError("", "Make sure that you fill all required blanks!"); return(RedirectToAction(nameof(Add))); } } else { ModelState.AddModelError("", "Make sure that you fill all required blanks!"); return(RedirectToAction(nameof(Add))); } }