public ActionResult EditGuest(int id)
        {
            var service = CreateGuestService();
            var detail  = service.GetGuestById(id);
            var model   =
                new GuestEdit
            {
                GuestId     = detail.GuestId,
                FullName    = detail.FullName,
                Address     = detail.Address,
                PhoneNumber = detail.PhoneNumber,
                IsAttending = detail.IsAttending
            };

            return(View(model));
        }
예제 #2
0
        public IHttpActionResult Put(GuestEdit guest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateGuestService();

            if (!service.UpdateGuest(guest))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
예제 #3
0
        // GET: Guest/Edit/{id} aka Update
        public ActionResult Edit(int id)
        {
            var service = CreateGuestService();
            var detail  = service.GetGuestById(id);
            var model   =
                new GuestEdit
            {
                GuestId       = detail.GuestId,
                FirstName     = detail.FirstName,
                LastName      = detail.LastName,
                ContactNumber = detail.ContactNumber,
                FullAddress   = detail.FullAddress,
                Notes         = detail.Notes,
            };

            return(View(model));
        }
예제 #4
0
        // Update -- Guest
        public bool UpdateGuest(GuestEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Guests
                    .Single(e => e.GuestId == model.GuestId);

                entity.FirstName     = model.FirstName;
                entity.LastName      = model.LastName;
                entity.ContactNumber = model.ContactNumber;
                entity.FullAddress   = model.FullAddress;
                entity.Notes         = model.Notes;

                return(ctx.SaveChanges() == 1);
            }
        }
        public bool UpdateGuest(GuestEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Guests
                    .Single(e => e.GuestId == model.GuestId && e.OwnerId == _userId);

                entity.FullName    = model.FullName;
                entity.Address     = model.Address;
                entity.PhoneNumber = model.PhoneNumber;
                entity.IsAttending = model.IsAttending;
                entity.EventId     = model.EventId;

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #6
0
        public ActionResult Edit(int id, GuestEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.GuestId != id)
            {
                ModelState.AddModelError("", "Guest Id Mismatch");
                return(View(model));
            }

            var service = CreateGuestService();

            if (service.UpdateGuest(model))
            {
                TempData["SaveResult"] = "Your Guest Was Updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your Guest Could Not Be Updated.");
            return(View(model));
        }
        public ActionResult EditGuest(int id, GuestEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.GuestId != id)
            {
                ModelState.AddModelError("", "Invalid ID Number");
                return(View(model));
            }

            var service = CreateGuestService();

            if (service.UpdateGuest(model))
            {
                TempData["SaveResult"] = "Your guest was successfully updated!";
                return(RedirectToAction("Index"));
            }

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