Ejemplo n.º 1
0
        public ActionResult EditUserName(EditDisplayNameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.IndexMessage = "There was an error editing your account. Please try again. If the problem persists, please contact a system administrator.";
                return(View(model));
            }
            try
            {
                if (model.Client)
                {
                    var client = SatChilddb.Clients.First(a => a.ContactEmail.Equals(model.Email));
                    client.DisplayName = model.DisplayName;
                }
                else
                {
                    var employee = SatChilddb.Employees.First(a => a.Email.Equals(model.Email));
                    employee.DisplayName = model.DisplayName;
                }

                SatChilddb.SaveChangesAsync();
                return(RedirectToAction("Index", "MembersController"));
            }
            catch
            {
                ViewBag.IndexMessage = "There was an error editing your account. Please try again. If the problem persists, please contact an administrator.";
                return(View(model));
            }
        }
Ejemplo n.º 2
0
        public ActionResult EditUserName()
        {
            var user = HttpContext.User.Identity.Name; // in this case, this is the email
            var name = !HttpContext.User.IsInRole("user") ? SatChilddb.Employees.First(a => a.Email.Equals(user)).DisplayName
                                                          : SatChilddb.Clients.First(a => a.ContactEmail.Equals(user)).DisplayName;
            var model = new EditDisplayNameViewModel
            {
                DisplayName = name,
                Email       = user,
                Client      = HttpContext.User.IsInRole("user")
            };

            return(View(model));
        }