Ejemplo n.º 1
0
        public async Task <ActionResult> Edit(InvitationEditFormModel editModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(editModel));
            }

            // If the email is already being used to authenticate into the system, it cannot be used
            bool userExists = await _context.Users
                              .AnyAsync(u => u.Email.Equals(editModel.Email, StringComparison.OrdinalIgnoreCase));


            if (userExists)
            {
                return(RedirectToAction <InvitationsController>(c => c.Index())
                       .WithError("It appears there is an existing User with this email address."));
            }

            // if there is an invitation for the same year, same email, this is invalid.
            bool invitationExists = await _context.Invitations.AnyAsync(i =>
                                                                        i.Email.Equals(editModel.Email, StringComparison.OrdinalIgnoreCase) &&
                                                                        i.Id != editModel.Id);

            if (invitationExists)
            {
                return(RedirectToAction <InvitationsController>(c => c.Index())
                       .WithError("It appears that this email has an invitation already."));
            }
            Invitation invitation = await _context.Invitations.SingleOrDefaultAsync(i => i.Id == editModel.Id);

            if (invitation == null)
            {
                return(RedirectToAction <InvitationsController>(c => c.Index())
                       .WithError("Could not load the Invitation."));
            }
            invitation.InviteeName     = editModel.InviteeName;
            invitation.Email           = editModel.Email;
            invitation.IsTeacher       = editModel.IsTeacher;
            invitation.HasBeenRedeemed = editModel.HasBeenRedeemed;

            _context.Entry(invitation).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(RedirectToAction <InvitationsController>(c => c.Index()).WithSuccess("Invitation updated."));
        }
Ejemplo n.º 2
0
        // GET: Invitations/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            InvitationEditFormModel invitation =
                await _context.Invitations.Project().To <InvitationEditFormModel>()
                .SingleOrDefaultAsync(i => i.Id == id.Value);

            if (invitation == null)
            {
                return(RedirectToAction <InvitationsController>(c => c.Index())
                       .WithError("Could not load the Invitation."));
            }
            return(View(invitation));
        }