コード例 #1
0
        public ActionResult AddUserInCompetition(UserInCompetition userInCompetition)
        {
            try
            {
                //HACK the competition property is set NULL in AddUserInCompetition.
                //this is needed to send email
                Competition competition = null;
                if (userInCompetition.SendEmail)
                {
                    competition = userInCompetition.Competition;
                }

                using (CompetitionRepository repository = new CompetitionRepository())
                {
                    repository.AddUserInCompetition(userInCompetition, AccountRepository.AllUsersPassword);
                }

                if (userInCompetition.SendEmail)
                {
                    userInCompetition.Competition = competition;
                    using (var msg = new SendMail().UserInCompetitionAdded(userInCompetition, true))
                    {
                        //msg.SendAsync(userState: userInCompetition.Email);
                        msg.Send();
                        //msg.Dispose();
                    }
                }

                TempData[ControllerHelpers.PURR] = new Purr()
                {
                    Title = "Success", Message = "The User was successfully added to the Competition."
                };

                //entire page gets refreshed when this view calls parent.location.reload.
                //TODO: put the users table on a partial view and update it via a JSON call.
                return(View("../Shared/ClosePopup"));
            }
            catch (RepositoryException ex)
            {
                //clear model errors for DateInvited
                ModelState.Clear();
                ModelState.AddModelError("AddUserInCompetition", ex.Message);
            }
            return(View(userInCompetition));
        }