public ActionResult Edit(int id)
        {
            var service = CreateRegistryEventService();
            var detail  = service.GetRegistryEventById(id);
            var model   =
                new RegistryEventEdit
            {
                RegistryEventId          = detail.RegistryEventId,
                UserProfileId            = detail.UserProfileId,
                UserProfile              = detail.UserProfile,
                RegistryEventTitle       = detail.RegistryEventTitle,
                RegistryEventDescription = detail.RegistryEventDescription,
                EventLocation            = detail.EventLocation,
                EventDate = detail.EventDate
            };

            return(View(model));
        }
        public bool UpdateRegistryEvent(RegistryEventEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .RegistryEvents
                    .Single(e => e.RegistryEventId == model.RegistryEventId && e.UserProfileId == _thisUserProfileId);

                entity.UserProfileId            = model.UserProfileId;
                entity.UserProfile              = model.UserProfile;
                entity.RegistryEventId          = model.RegistryEventId;
                entity.RegistryEventTitle       = model.RegistryEventTitle;
                entity.RegistryEventDescription = model.RegistryEventDescription;
                entity.EventLocation            = model.EventLocation;
                entity.EventDate = model.EventDate;

                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Edit(int id, RegistryEventEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.RegistryEventId != id)
            {
                ModelState.AddModelError("", "ID Mismatch");
                return(View(model));
            }

            var service = CreateRegistryEventService();

            if (service.UpdateRegistryEvent(model))
            {
                TempData["SaveResult"] = "Your Event was updated";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your Event could not be updated.");
            return(View(model));
        }