Esempio n. 1
0
        public async Task <IActionResult> Index(Signup model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var profileValidation = await ValidateProfile(model);

                    if (profileValidation.NameVerified)
                    {
                        var json = await SlackInvite(model);

                        var ok = (bool)json["ok"];
                        if (ok)
                        {
                            if (!String.IsNullOrWhiteSpace((string)json["warning"]))
                            {
                                Logger.Error($"Attempted to invite {model.Email} and received the following warnings: {(string)json["warning"]}.");
                            }

                            var postData = $":white_check_mark: Invitation sent for {model.ToSlackMessage()}\n{profileValidation.ToSlackMessage()}";
                            await SendSlackMessage(postData);

                            return(View("Thanks"));
                        }
                        else
                        {
                            Logger.Error($"Attempted to invite {model.Email} and received the following error: {(string)json["error"]}.");
                            ModelState.AddModelError("", TranslateSlackError((string)json["error"]));
                        }
                    }
                    else
                    {
                        var nameVerificationFailedMessage = $"Profile validation failed for { model.ToSlackMessage()}\n{ profileValidation.ToSlackMessage()}\n\t\t Expected to see `{ profileValidation.NameExpected}` but found `{ profileValidation.NameFound}` instead.";
                        await SendSlackMessage($":x: {nameVerificationFailedMessage}");

                        Logger.Error(nameVerificationFailedMessage);
                        ModelState.AddModelError("ProfileLink", $"The name we found in your MVP profile doesn't match the name you entered.");
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(e, $"Attempted to invite {model.Email} and received an error.");
                    ModelState.AddModelError("", "An error occurred.");
                }
            }

            return(View(model));
        }