コード例 #1
0
ファイル: UserEmailsController.cs プロジェクト: sparg/tripod
        public virtual async Task <ActionResult> Put(int emailAddressId, UpdateEmailAddress command)
        {
            if (command == null)
            {
                return(View(MVC.Errors.Views.BadRequest));
            }

            if (!ModelState.IsValid)
            {
                var firstError = ModelState.Values.SelectMany(x => x.Errors.Select(y => y.ErrorMessage)).First();
                var message    = string.Format("Could not update email address: **{0}**", firstError);
                TempData.Alerts(message, AlertFlavor.Danger, true);
            }
            else
            {
                var email = await _queries.Execute(new EmailAddressBy(emailAddressId));

                if (email != null)
                {
                    await _commands.Execute(command);

                    var message = string.Format("Successfully updated email address **{0}**.", email.Value);
                    TempData.Alerts(message, AlertFlavor.Success, true);

                    // changing the primary email address also changes gravatar
                    if (email.IsPrimary != command.IsPrimary)
                    {
                        Response.ClientCookie(User.Identity.GetUserId(), _queries);
                    }
                }
            }

            return(RedirectToAction(await MVC.UserEmails.Index()));
        }
コード例 #2
0
        public virtual async Task<ActionResult> Put(int emailAddressId, UpdateEmailAddress command)
        {
            if (command == null) return View(MVC.Errors.Views.BadRequest);

            if (!ModelState.IsValid)
            {
                var firstError = ModelState.Values.SelectMany(x => x.Errors.Select(y => y.ErrorMessage)).First();
                var message = string.Format("Could not update email address: **{0}**", firstError);
                TempData.Alerts(message, AlertFlavor.Danger, true);
            }
            else
            {
                var email = await _queries.Execute(new EmailAddressBy(emailAddressId));
                if (email != null)
                {
                    await _commands.Execute(command);
                    var message = string.Format("Successfully updated email address **{0}**.", email.Value);
                    TempData.Alerts(message, AlertFlavor.Success, true);

                    // changing the primary email address also changes gravatar
                    if (email.IsPrimary != command.IsPrimary)
                        Response.ClientCookie(User.Identity.GetUserId(), _queries);
                }
            }

            return RedirectToAction(await MVC.UserEmails.Index());
        }