Exemplo n.º 1
0
        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());
            }
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
 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());
     }
 }
Exemplo n.º 4
0
 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"));
 }
Exemplo n.º 5
0
 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"));
 }