Ejemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            var customerId = ((Customer)Session["Customer"]).Id;
            var flavor     = db.Flavors.Where(q => q.Id == id && q.UserId == customerId && q.UserType == Flavor.CUSTOMER)
                             .FirstOrDefault();

            if (flavor == null)
            {
                return(HttpNotFound());
            }

            FlavorViewModel flavorVM = new FlavorViewModel
            {
                Id              = flavor.Id,
                Name            = flavor.Name,
                Description     = flavor.Description,
                Images          = flavor.DecodedImages()[0],
                Ingredients     = flavor.Ingredients,
                PreparationTime = flavor.PreparationTime,
                Recipe          = flavor.Recipe,
                TotalTime       = flavor.TotalTime
            };

            Session["Image"] = flavorVM.Images;
            return(View(flavorVM));
        }
Ejemplo n.º 2
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());
            }
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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());
     }
 }
Ejemplo n.º 5
0
 public JavaScriptResult Create(FlavorViewModel flavorVm)
 {
     try
     {
         _flavorService.Add(Mapper.Map <Flavor>(flavorVm));
         return(JavaScript($"ShowResult('{"Data saved successfully."}','{"success"}','{"redirect"}','{"/Flavor"}')"));
     }
     catch (Exception ex)
     {
         return(JavaScript($"ShowResult('{ex.Message}','{"failure"}')"));
     }
 }
Ejemplo n.º 6
0
 public ActionResult Tut117(FlavorViewModel fvm)
 {
     using (user7221204 db = new user7221204())
     {
         bzFlav flav = new bzFlav
         {
             Address = fvm.Flavor.Address,
             Email = fvm.Flavor.Email,
             Flavor = fvm.Flavor.Flavor,
             Name = fvm.Flavor.Name,
             Phone = fvm.Flavor.Phone,
             Serial = fvm.Flavor.Serial
         };
         db.bzFlavs.Add(flav);
         db.SaveChanges();
     }
     return View(fvm);
 }
Ejemplo n.º 7
0
 public ActionResult Tut117()
 {
     FlavorViewModel fvm = new FlavorViewModel();
     return View(fvm);
 }