Ejemplo n.º 1
0
        //
        // GET: /Account/Manage/UpdateProfile
        public ActionResult UpdateProfile()
        {
            var user = UserManager.FindById(User.Identity.GetUserId());
            UpdateProfileViewModel model = new UpdateProfileViewModel();

            model.Email     = user.Email;
            model.FirstName = user.FirstName;
            model.LastName  = user.LastName;
            model.Title     = user.Title;
            model.TimeZone  = user.TimeZone;
            model.Avatar    = user.Avatar;
            model.Roles     = new List <string>();
            foreach (var role in RoleManager.Roles.ToList())
            {
                foreach (var u in role.Users)
                {
                    if (u.UserId == user.Id)
                    {
                        model.Roles.Add(role.Name);
                    }
                }
            }
            ViewData["Form"] = new UpdateProfileForm().Init(model, User);
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult UpdateProfile(UpdateProfileViewModel model)
        {
            ViewData["Form"] = new UpdateProfileForm().Init(model, User);
            if (ModelState.IsValid)
            {
                var user = UserManager.FindById(User.Identity.GetUserId());
                System.Diagnostics.Debug.WriteLine(user);
                if (user != null)
                {
                    user.FirstName = model.FirstName;
                    user.LastName  = model.LastName;
                    user.Title     = model.Title;
                    user.TimeZone  = model.TimeZone;

                    IdentityResult result = UserManager.Update(user);
                    if (!result.Succeeded)
                    {
                        ModelState.AddModelError("", "Could not update your profile.");
                    }
                    else
                    {
                        this.TempData["Success"] = "Saved!";
                    }
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 3
0
        public IHttpActionResult UpdateProfile([FromBody] UpdateProfileForm form)
        {
            if (!ModelState.IsValid)
            {
                Dictionary <string, string> errorList = AppUtils.Validation.GetErrorDictionary(ModelState);
                return(Content(
                           HttpStatusCode.BadRequest,
                           new ResponseWrapper <object>(HttpStatusCode.BadRequest, errorList)
                           ));
            }

            var  userId = Convert.ToUInt32(RequestContext.Principal.Identity.Name);
            User user   = new User();

            if (!user.DAL_Load(userId))
            {
                return(NotFound());
            }

            user.FullName     = form.FullName;
            user.Designation  = form.Designation;
            user.MobileNumber = form.MobileNumber;
            user.ModifiedBy   = userId;

            if (user.DAL_UpdateProfile())
            {
                return(Ok(new ResponseWrapper <bool>(HttpStatusCode.OK, true)));
            }

            return(InternalServerError());
        }
Ejemplo n.º 4
0
        private void updateProfileToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            if ((updateProfileForm == null) || (updateProfileForm.IsDisposed))
            {
                updateProfileForm = new UpdateProfileForm();

                updateProfileForm.MdiParent = this;
            }

            updateProfileForm.Show();
        }
Ejemplo n.º 5
0
 private void UpdateProfileToolStripMenuItem_Click(object sender, System.EventArgs e)
 {
     if (updateProfileForm == null || updateProfileForm.IsDisposed == true)
     {
         updateProfileForm = new UpdateProfileForm
         {
             MdiParent = this,
         };
         updateProfileForm.Show();
     }
 }
Ejemplo n.º 6
0
        public async Task <IActionResult> UpdateProfile(UpdateProfileForm model)
        {
            var user = _userHelper.GetUser(User);

            if (!ModelState.IsValid)
            {
                ViewBag.ModelForm = model;
                ModelState.AddModelError("updateError", "");
                return(View("Index", _mapper.Map <ApplicationUserViewModel>(user)));
            }


            user.UserProfile.Name              = model.Name;
            user.UserProfile.Birthplace        = model.Birthplace;
            user.UserProfile.Birthdate         = model.Birthdate;
            user.UserProfile.Address           = model.Address;
            user.UserProfile.Photo             = model.Photo;
            user.PhoneNumber                   = model.Phone;
            user.UserProfile.MobilePhoneNumber = model.MobilePhoneNumber;
            user.UserProfile.HomePhoneNumber   = model.HomePhoneNumber;
            user.UserProfile.Description       = model.Description;
            user.Email             = model.Email;
            user.UserProfile.Email = model.Email;

            if (string.IsNullOrWhiteSpace(model.Username))
            {
                user.UserName = model.Email;
            }

            var result = await _userManager.UpdateAsync(user);

            if (result.Succeeded)
            {
                if (!string.IsNullOrWhiteSpace(model.Photo) && (model.Photo != user.UserProfile.Photo))
                {
                    var attachment = model.Photo.ConvertToAttachment();
                    if (attachment != null)
                    {
                        var newPath = $"{_userDir}/{user.Id}";
                        attachment.CropedPath = _fileHelper.CreateCropped(attachment);
                        attachment.Path       = _fileHelper.FileMove(attachment.Path,
                                                                     newPath,
                                                                     user.Id);
                        attachment.CropedPath = _fileHelper.FileMove(attachment.CropedPath,
                                                                     newPath,
                                                                     user.Id + _cropSuffix);
                        user.UserProfile.Photo = attachment.ConvertToString();
                        result = await _userManager.UpdateAsync(user);

                        if (result.Succeeded)
                        {
                            TempData["Success"] = true;
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            AddError(result.Errors, "updateError");
                        }
                    }
                }

                TempData["Success"] = true;
                return(RedirectToAction("Index"));
            }
            else
            {
                TempData["Success"] = false;
                AddError(result.Errors, "updateError");
            }

            return(RedirectToAction("Index"));
        }