public ActionResult Edit(HttpPostedFileBase avatarFile, FlavorViewModel flavorVM) { try { var flavor = db.Flavors.Find(flavorVM.Id); if (flavor.IsApproved == true) { return(RedirectToAction("Flavors", "Customer")); } flavor.Name = flavorVM.Name; if (avatarFile != null) { flavor.Images = SaveImages.SaveImagesFile(avatarFile, flavorVM.Name); } flavor.Description = flavorVM.Description; flavor.PreparationTime = flavorVM.PreparationTime; flavor.TotalTime = flavorVM.TotalTime; flavor.Ingredients = flavorVM.Ingredients; flavor.Slug = Slugify.GenerateSlug(flavor.Name); flavor.UpdatedAt = DateTime.Now; flavor.Recipe = flavorVM.Recipe; flavor.IsApproved = false; db.Entry(flavor).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Flavors", "Customer")); } catch { return(View()); } }
public ActionResult Create(HttpPostedFileBase avatarFile, FlavorViewModel flavorVM) { try { Flavor flavor = new Flavor() { UserId = ((Staff)Session["Staff"]).Id, UserType = Flavor.STAFF, Name = flavorVM.Name, Description = flavorVM.Description, Images = SaveImages.SaveImagesFile(avatarFile, flavorVM.Name), PreparationTime = flavorVM.PreparationTime, TotalTime = flavorVM.TotalTime, Ingredients = flavorVM.Ingredients, Recipe = flavorVM.Recipe, IsApproved = true, Slug = Slugify.GenerateSlug(flavorVM.Name), CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; Session["Image"] = "/" + ConfigurationManager.AppSettings["CusImages"] + flavor.Images; db.Flavors.Add(flavor); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(HttpPostedFileBase avatarFile, FlavorViewModel flavorViewModel) { if (ModelState.IsValid) { Flavor flavor = new Flavor() { UserId = ((Customer)Session["Customer"]).Id, UserType = Flavor.CUSTOMER, Name = flavorViewModel.Name, Description = flavorViewModel.Description, Images = SaveImages.SaveImagesFile(avatarFile, flavorViewModel.Name), PreparationTime = flavorViewModel.PreparationTime, TotalTime = flavorViewModel.TotalTime, Ingredients = flavorViewModel.Ingredients, Recipe = flavorViewModel.Recipe, IsApproved = false, Slug = Slugify.GenerateSlug(flavorViewModel.Name), CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; Session["Image"] = "/" + ConfigurationManager.AppSettings["CusImages"] + flavor.Images; db.Flavors.Add(flavor); db.SaveChanges(); return(RedirectToAction("Flavors", "Customer")); } return(View()); }
public ActionResult Create(BookCategoryViewModel model) { if (ModelState.IsValid) { var check = db.BookCategories.Where(x => x.Name == model.Name).FirstOrDefault(); if (check == null) { BookCategory bookCategory = new BookCategory() { Name = model.Name, Slug = Slugify.GenerateSlug(model.Name), CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; db.BookCategories.Add(bookCategory); db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.statusCheck = "Name already exists"; } } return(View()); }
private void SeedBookCategories() { var categories = Builder <BookCategory> .CreateListOfSize(10) .All() .With(c => c.Name = string.Join(" ", Faker.Lorem.Words(3))) .With(c => c.Slug = Slugify.GenerateSlug(string.Join(" ", Faker.Lorem.Words(3)))) .With(c => c.CreatedAt = DateTime.Now) .With(c => c.UpdatedAt = DateTime.Now) .With(c => c.DeletedAt = null) .With(c => c.DeletedBy = null) .Build(); db.BookCategories.AddRange(categories); db.SaveChanges(); }
public ActionResult Edit(HttpPostedFileBase avatarFile, BookViewModel viewModel) { SetViewBag(viewModel.CategoryId); if (ModelState.IsValid) { var book = db.Books.Where(x => x.Id == viewModel.Id).FirstOrDefault(); book.Name = viewModel.Name; book.Price = viewModel.Price; book.Slug = Slugify.GenerateSlug(viewModel.Name); book.CategoryId = viewModel.CategoryId; book.Images = SaveImages.SaveImagesFile(avatarFile, viewModel.Name); book.Description = viewModel.Description; book.Discount = viewModel.Discount; book.UpdatedAt = DateTime.Now; db.Entry(book).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(HttpPostedFileBase avatarFile, BookViewModel viewModel) { SetViewBag(); if (ModelState.IsValid) { Random rd = new Random(); var book = MappingProfile.mapper.Map <BookViewModel, Book>(viewModel); book.StaffId = ((Staff)Session["Staff"]).Id; book.Slug = Slugify.GenerateSlug(book.Name); book.CreatedAt = DateTime.Now; book.UpdatedAt = DateTime.Now; book.Sku = rd.Next(1000, 9999).ToString(); book.Images = SaveImages.SaveImagesFile(avatarFile, viewModel.Name); db.Books.Add(book); db.SaveChanges(); } ; return(RedirectToAction("Index")); }
public ActionResult Create(LevelViewModel model) { try { db.Levels.Add(new Level() { Name = model.Name, Key = Slugify.GenerateSlug(model.Name), Permissions = db.Permissions.Where(q => model.Permissions.Contains(q.Id)).ToList(), CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(RedirectToAction("Create")); } }
public ActionResult Edit(BookCategoryViewModel model) { if (ModelState.IsValid) { var check = db.BookCategories.Where(x => x.Name == model.Name).FirstOrDefault(); if (check == null) { var category = db.BookCategories.Where(x => x.Id == model.Id).FirstOrDefault(); category.Name = model.Name; category.Slug = Slugify.GenerateSlug(model.Name); category.UpdatedAt = DateTime.Now; db.Entry(category).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.statusCheck = "Name already exists"; } } return(View()); }
public ActionResult Edit(LevelViewModel model, int id) { var level = db.Levels.Find(id); if (level == null) { return(HttpNotFound()); } foreach (Permission permission in level.Permissions.ToList()) { level.Permissions.Remove(permission); } level.Name = model.Name; level.Key = Slugify.GenerateSlug(model.Name); level.UpdatedAt = DateTime.Now; level.Permissions = db.Permissions.Where(q => model.Permissions.Contains(q.Id)).ToList(); db.Entry(level).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }