public ActionResult Specials(SpecialsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var repo = SpecialsRepositoryFactory.GetRepository();

                try
                {
                    Specials special = new Specials();
                    special.SpecialTitle       = model.SpecialToAdd.SpecialTitle;
                    special.SpecialDescription = model.SpecialToAdd.SpecialDescription;

                    repo.AddSpecial(special);

                    return(RedirectToAction("Specials"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return(View(model));
            }
        }
Exemple #2
0
        public ActionResult editSpecial(SpecialsViewModel vm)
        {
            SpecialMockRepo specialRepo = new SpecialMockRepo();

            specialRepo.Create(vm.Special);
            return(RedirectToAction("editSpecial"));
        }
        public ActionResult Specials(SpecialsViewModel specialsVM)
        {
            if (ModelState.IsValid)
            {
                var specialsRepo = SpecialsFactory.GetRepository();

                specialsRepo.AddSpecial(specialsVM.Specials);

                specialsVM.SpecialsList = specialsRepo.GetSpecials();

                List <SpecialsViewModel> viewModel = specialsVM.SpecialsList.Select(x => new SpecialsViewModel
                {
                    SpecialsID    = x.SpecialsID,
                    Title         = x.Title,
                    Description   = x.Description,
                    ImageFileName = x.ImageFileName
                }).ToList();

                return(View(specialsVM));
            }
            else
            {
                return(View(specialsVM));
            }
        }
Exemple #4
0
        public ActionResult editSpecial()
        {
            SpecialMockRepo   specialRepo = new SpecialMockRepo();
            SpecialsViewModel vm          = new SpecialsViewModel();

            vm.Specials = specialRepo.GetAllSpecials();
            return(View(vm));
        }
Exemple #5
0
        public ActionResult Specials()
        {
            SpecialsViewModel model = new SpecialsViewModel();

            model.Specials = _specialsRepo.GetAll().ToList();

            return(View(model));
        }
Exemple #6
0
        public ActionResult Specials()
        {
            var vm = new SpecialsViewModel {
                Specials = specialsRepository.GetAll()
            };

            return(View(vm));
        }
        public ActionResult Specials(SpecialsViewModel model)
        {
            var repo = VehicleRepositoryFactory.GetRepository();

            repo.AddSpecial(model.newSpecial);
            model            = new SpecialsViewModel();
            model.specials   = repo.GetSpecials();
            model.newSpecial = null;
            return(View(model));
        }
        public ActionResult Specials()
        {
            var repo = VehicleRepositoryFactory.GetRepository();

            Session.Abandon();
            var model = new SpecialsViewModel();

            model.specials = repo.GetSpecials();
            return(View(model));
        }
        public ActionResult Specials()
        {
            {
                var repo  = SpecialsRepositoryFactory.GetRepository();
                var model = new SpecialsViewModel();

                model.SpecialsList = repo.GetAllSpecials().ToList();
                model.SpecialToAdd = new Specials();

                return(View(model));
            }
        }
        public ActionResult Special(int id)
        {
            var repo = VehicleRepositoryFactory.GetRepository();

            repo.DeleteSpecial(id);
            Session.Abandon();
            var model = new SpecialsViewModel();

            model.specials   = repo.GetSpecials();
            model.newSpecial = null;
            return(View("Specials", model));
        }
Exemple #11
0
        public ActionResult Specials()
        {
            var model = new SpecialsViewModel();

            var specialsRepo = SpecialsFactory.GetRepository();

            model.SpecialsList = specialsRepo.GetSpecials();

            List <SpecialsViewModel> viewModel = model.SpecialsList.Select(x => new SpecialsViewModel
            {
                SpecialsID    = x.SpecialsID,
                Title         = x.Title,
                Description   = x.Description,
                ImageFileName = x.ImageFileName
            }).ToList();

            return(View(model));
        }
        public bool EditSpecial(SpecialsViewModel special)
        {
            // a different special already exists with this title
            if (specials.Any(s => s.Title == special.Title && s.SpecialId != special.SpecialId))
            {
                return(false);
            }

            // no specials found with that ID
            if (!DeleteSpecial(special.SpecialId))
            {
                return(false);
            }

            specials.Add(new Special
            {
                Title       = special.Title,
                Description = special.Description
            });
            return(true);
        }
        public ActionResult EditSpecial(SpecialsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var success = DataManager.Instance.EditSpecial(model);
                if (success)
                {
                    return(RedirectToAction("Specials", new { Message = "Successfully edited special" }));
                }

                if (!DataManager.Instance.GetSpecials().Any(s => s.SpecialId == model.SpecialId))
                {
                    return(RedirectToAction("Specials", new { Message = "That Special no longer exists" }));
                }

                ModelState.AddModelError("Title", $"A Special already exists titled '{model.Title}'");
            }

            // if we got here then the model was invalid
            return(View(model));
        }
        public ActionResult Specials(SpecialsViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool success = DataManager.Instance.AddSpecial(model.Title, model.Description);
                if (success)
                {
                    return(RedirectToAction("Specials", new { Message = "Successfully created a new Special" }));
                }

                // if we got here then a special already exists with the given title
                ModelState.AddModelError("Title", $"A Special already exists titled '{model.Title}'");
            }

            // if we got here the model was invalid
            ViewBag.Specials = from s in DataManager.Instance.GetSpecials()
                               select new SpecialsViewModel {
                SpecialId = s.SpecialId, Title = s.Title, Description = s.Description
            };
            return(View(model));
        }
        public bool EditSpecial(SpecialsViewModel special)
        {
            var db = ApplicationDbContext.Create();

            // a different special already exists with this title
            if (db.Specials.Any(s => s.Title == special.Title && s.SpecialId != special.SpecialId))
            {
                return(false);
            }

            var entry = db.Specials.Where(s => s.SpecialId == special.SpecialId).FirstOrDefault();

            // no special with this ID found
            if (entry == null)
            {
                return(false);
            }

            entry.Title       = special.Title;
            entry.Description = special.Description;
            db.SaveChanges();
            return(true);
        }