Esempio n. 1
0
        public ActionResult EditProfile()
        {
            if (Session["userId"] == null)
            {
                return(Redirect("~"));
            }
            var AdminViewObj = new AdminProfileView((int)Session["userId"]);
            var Admin        = AdminViewObj.GetAdminProfile();
            var model        = new AdminProfileEditViewModel();

            AutoMapper.Mapper.Map(Admin, model);
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult EditProfile(AdminProfileEditViewModel model, string returnUrl)
        {
            if (Session["userId"] == null)
            {
                return(Redirect("~"));
            }
            Users user = new Users();

            AutoMapper.Mapper.Map(model, user);
            user.Id = (int)Session["userId"];
            if (string.IsNullOrEmpty(model.NewPassword))
            {
                user.Password = model.Password;
            }
            else
            {
                user.Password = model.NewPassword;
            }
            AdminEdit Admin = new AdminEdit();

            try
            {
                if (Admin.UpdateAdmin(user))
                {
                    return(RedirectToAction("Profile"));
                }
                else
                {
                    return(RedirectToAction("Profile/Edit"));
                }
            }
            catch (EmailAlreadyExistsEx ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(model));
            }
            catch (PhoneAlreadyExistsEx ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(model));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "Unable to update information");
                return(View(model));
            }
        }