Example #1
0
        public async Task <IActionResult> Edit(Guid id, [FromForm] SignupInputModel input, string redirectTo = null)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(Edit), new { id }));
            }

            var model = await _database.GetEditableEvent(id);

            if (model == null)
            {
                return(NotFound());
            }

            var user = await _database.GetEditableUser(GetUserId());

            if (user.GetEditableEvent(id) is EventSignup eventSignup)
            {
                eventSignup.AuditLog.Add($"Changed signup\n\n{eventSignup.Role} -> {input.Role}\n\n{eventSignup.PartnerEmail} -> {input.PartnerEmail}", user);

                eventSignup.Role         = input.Role;
                eventSignup.PartnerEmail = input.PartnerEmail?.Trim().Normalize().ToUpperInvariant();

                try
                {
                    if (model.Survey != null)
                    {
                        if (eventSignup.Response == null)
                        {
                            eventSignup.Response = new Response
                            {
                                Survey = model.Survey,
                                User   = user
                            };
                        }

                        eventSignup.Response.Answers = model.Survey.Questions
                                                       .JoinWithAnswers(input.Answers)
                                                       .ToList();
                    }
                }
                catch (ModelErrorException error)
                {
                    ModelState.AddModelError(error.Key, error.Message);
                    return(RedirectToAction(nameof(Edit), new { id }));
                }

                await _database.SaveChangesAsync();
            }

            if (redirectTo == null)
            {
                return(RedirectToAction(nameof(Event), new { id }));
            }
            else
            {
                return(Redirect(redirectTo));
            }
        }
Example #2
0
        public async Task <IActionResult> Event(Guid id, [FromForm] SignupInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(Event), new { id }));
            }

            var model = await _database.GetEditableEvent(id);

            if (model == null)
            {
                return(NotFound());
            }

            if (!model.IsOpen())
            {
                return(RedirectToAction(nameof(Event), new { id }));
            }

            var user = await _database.GetEditableUser(GetUserId());

            if (user.IsSignedUpFor(id))
            {
                return(RedirectToAction(nameof(Event), new { id }));
            }

            var autoAccept = model.ShouldAutoAccept(input.Role);

            var signup = user.AddEventSignup(id, input.Role, input.PartnerEmail, autoAccept);

            try
            {
                signup.Answers = model.Questions
                                 .JoinWithAnswers(input.Answers)
                                 .ToList();
            }
            catch (ModelErrorException error)
            {
                ModelState.AddModelError(error.Key, error.Message);
                return(RedirectToAction(nameof(Event), new { id }));
            }

            await _database.SaveChangesAsync();

            if (autoAccept)
            {
                return(RedirectToAction(nameof(Event), new { id }));
            }
            else
            {
                return(RedirectToAction(nameof(ThankYou), new { id }));
            }
        }