public async Task <IHttpActionResult> PutGuest([FromBody] Guest guest, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != guest.GuestId)
            {
                return(BadRequest());
            }

            db.Entry(guest).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GuestExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PutPendingQuestion(int id, PendingQuestion question)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != question.Id)
            {
                return(BadRequest());
            }

            db.Entry(question).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PendingQuestionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#3
0
        public ActionResult RSVP(RsvpViewModel viewModel)
        {
            var identity = Thread.CurrentPrincipal as ClaimsPrincipal;

            string    guestCode = null;
            GuestCode dbCode    = null;
            Guest     dbGuest   = null;

            using (var db = new WeddingManagementContext())
            {
                viewModel.GuestCode = (viewModel.GuestCode ?? string.Empty).ToUpper();

                dbCode = db.GuestCodes.FirstOrDefault(gc => gc.GuestCode1.ToUpper() == viewModel.GuestCode);

                if (dbCode != null && dbCode.GuestId != null)
                {
                    dbGuest = db.Guests.FirstOrDefault(g => g.GuestId == dbCode.GuestId);

                    if (dbGuest != null)
                    {
                        if (viewModel.Attending == true)
                        {
                            if (viewModel.NumberOfGuests <= 0)
                            {
                                ModelState.AddModelError("NumberOfGuests", "We need to know how many people are attending.");
                            }

                            if (viewModel.NumberOfGuests > dbGuest.MaxAllowed)
                            {
                                ModelState.AddModelError("NumberOfGuests", "Too many people attending.");
                            }
                        }
                        else if (viewModel.Attending == null)
                        {
                            ModelState.AddModelError("Attending", "We need to know if you plan to attend.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("GuestCode", "No guest found for this guest code.");
                    }
                }
                else
                {
                    ModelState.AddModelError("GuestCode", "Invalid guest code.");
                }

                if (ModelState.IsValid)
                {
                    db.Entry(dbGuest).State = System.Data.Entity.EntityState.Modified;

                    dbGuest.RSVPFlag = true;

                    if (viewModel.Attending == true)
                    {
                        dbGuest.NumberAttending = viewModel.NumberOfGuests;
                    }
                    else
                    {
                        dbGuest.NumberAttending = -1;
                    }

                    db.SaveChanges();

                    return(View("RSVP_Confirmed", viewModel));
                }
                else
                {
                    return(View(viewModel));
                }
            }
        }