Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Dinner dinner = repo.GetDinner(id);

            repo.Delete(dinner);
            repo.Save();
            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(int id, string confirmButton)
        {
            Dinners dinner = dinnerRepository.GetDinner(id);

            if (dinner == null)
            {
                return(View("NotFound"));
            }
            dinnerRepository.Delete(dinner);
            dinnerRepository.Save();
            return(View("Deleted"));
        }
Beispiel #3
0
        public ActionResult Index(int dinnerCount = 100)
        {
            const string name = "Nerd";
            var          membershipService = new AccountMembershipService();

            if (membershipService.ValidateUser(name, "password") == false)
            {
                membershipService.CreateUser(name, "password", "*****@*****.**");
            }
            var repo = new DinnerRepository();

            foreach (var d in repo.All)
            {
                repo.Delete(d.DinnerID);
            }
            for (var i = 0; i < dinnerCount; i++)
            {
                var dinner = new Dinner {
                    Title        = "Nerd-Out",
                    Description  = "Nerding out with the nerds",
                    EventDate    = DateTime.Now.Add(new TimeSpan(30, 0, 0, 0)),
                    ContactPhone = "403-999-9999",
                    Address      = "Calgary, AB",
                    Country      = "Canada",
                    HostedById   = name,
                    HostedBy     = name
                };
                var rsvp = new RSVP {
                    AttendeeNameId = name, AttendeeName = name
                };
                dinner.RSVPs = new List <RSVP> {
                    rsvp
                };
                repo.InsertOrUpdate(dinner);
            }
            try {
                repo.Save();
            }
            catch (DbEntityValidationException e) {
                var error = e.EntityValidationErrors.First().ValidationErrors.First();
                return(new ContentResult {
                    Content = string.Format("{0}: {1}", error.PropertyName, error.ErrorMessage)
                });
            }
            return(new ContentResult {
                Content = "Success"
            });
        }
        public ActionResult Delete(int id, string confirmButton)
        {
            Dinner dinner = dinnerRepository.GetDinner(id);

            if (!dinner.IsHostedBy(User.Identity.Name))
            {
                return(View("InvalidOwner"));
            }

            if (dinner == null)
            {
                return(View("NotFound"));
            }
            dinnerRepository.Delete(dinner);
            dinnerRepository.Save();
            return(View("Deleted"));
        }
        private ViewResult DeletePost(int id)
        {
            Dinner dinner = _dinnerRepository.TryGetDinner(id);

            if (dinner == null)
            {
                return(View(ViewNames.NotFound));
            }

            ViewResult viewResult = ModificationNotAuthorized(dinner);

            if (viewResult != null)
            {
                return(viewResult);
            }

            _dinnerRepository.Delete(dinner);
            _dinnerRepository.Save();

            return(View(ViewNames.Deleted));
        }