public ActionResult EditProfile(UserProfileUpdateViewModel model)
        {
            ApplicationUser applicationUser = db.Users.Find(model.Id);

            if (db.Users.Where(x => x.Id != model.Id).Any(n => n.UserName == model.UserName))
            {
                ModelState.AddModelError("UserName", "Name is busy");
            }
            if (model.AvatarImageFile != null)
            {
                string fileName  = Path.GetFileNameWithoutExtension(model.AvatarImageFile.FileName);
                string extention = Path.GetExtension(model.AvatarImageFile.FileName);
                fileName     = fileName + DateTime.Now.ToString("yymmssfff") + extention;
                model.Avatar = "~/Images/Avatars/" + fileName;
                fileName     = Path.Combine(Server.MapPath("~/Images/Avatars/"), fileName);
                model.AvatarImageFile.SaveAs(fileName);
            }

            if (ModelState.IsValid)
            {
                if (model.Avatar != null && model.AvatarImageFile != null)
                {
                    applicationUser.Avatar          = model.Avatar;
                    applicationUser.AvatarImageFile = model.AvatarImageFile;
                }
                applicationUser.Id          = model.Id;
                applicationUser.PhoneNumber = model.Number;
                applicationUser.UserName    = model.UserName;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Post([FromBody] UserProfileUpdateViewModel model)
        {
            if (model == null)
            {
                return(null);
            }

            var userId     = _caller.Claims.Single(c => c.Type == "id");
            var OnlineUser = await _userManager.FindByIdAsync(userId.Value);

            if (OnlineUser == null)
            {
                return(BadRequest());
            }

            OnlineUser.FullName    = model.FullName;
            OnlineUser.Address     = model.Address;
            OnlineUser.Email       = model.Email;
            OnlineUser.PhoneNumber = model.Phone;
            OnlineUser.City        = model.City;

            var result = await _userManager.UpdateAsync(OnlineUser);

            if (!result.Succeeded)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Пример #3
0
        // Update Profile
        public ActionResult Update(int Id)
        {
            var model = new UserProfileUpdateViewModel
            {
                UserProfile = _userProfileService.GetById(Id)
            };

            return(View(model));
        }
        // GET: ApplicationUsers/Edit/5
        public ActionResult EditProfile()
        {
            var user = UserManager.FindById(User.Identity.GetUserId());
            UserProfileUpdateViewModel UserModelUpdate = new UserProfileUpdateViewModel();

            UserModelUpdate.Avatar          = user.Avatar;
            UserModelUpdate.AvatarImageFile = user.AvatarImageFile;
            UserModelUpdate.Id       = user.Id;
            UserModelUpdate.Number   = user.PhoneNumber;
            UserModelUpdate.UserName = user.UserName;
            return(View(UserModelUpdate));
        }
Пример #5
0
        //GET: Edit Profile
        public ActionResult Edit()
        {
            string             username     = User.Identity.Name;
            CustomIdentityUser identityUser = _userManager.FindByNameAsync(username).Result;
            //Fetch userProfile
            UserProfile user = _userProfileService.GetAll().FirstOrDefault(x => x.UserId.Equals(identityUser.Id));

            ////Construct the model
            UserProfileUpdateViewModel model = new UserProfileUpdateViewModel();

            model.UserProfile = user;
            model.DepId       = user.DepId;
            model.LanguageID  = user.LanguageID;
            model.Departments = _departmentService.GetAll();
            model.Languages   = _languageService.GetAll();

            return(View(model));
        }
Пример #6
0
        public ActionResult Edit(UserProfileUpdateViewModel userProfileViewModel, IFormFile Photo)
        {
            if (ModelState.IsValid)
            {
                // Add User Photo to the profile
                var filename = string.Empty;
                // upload Photo
                if (Photo != null)
                {
                    // Find route path
                    filename = Path.Combine("UserImages", Guid.NewGuid() + Photo.FileName);

                    var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", filename); //extract the filname of the pic
                    Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                }


                // Editing Part...

                string             username     = User.Identity.Name;
                CustomIdentityUser identityUser = _userManager.FindByNameAsync(username).Result;

                //Get userProfile
                UserProfile user = _userProfileService.GetAll().FirstOrDefault(x => x.UserId.Equals(identityUser.Id));


                //user profile Id is connected to Logged in User
                user.UserId = identityUser.Id;

                //Update the profile
                user.Project    = userProfileViewModel.UserProfile.Project;
                user.SKills     = userProfileViewModel.UserProfile.SKills;
                user.DepId      = userProfileViewModel.DepId;
                user.LanguageID = userProfileViewModel.LanguageID;
                user.Experience = userProfileViewModel.UserProfile.Experience;
                user.CGPA       = userProfileViewModel.UserProfile.CGPA;
                user.Education  = userProfileViewModel.UserProfile.Education;
                user.UserPhoto  = filename;
                _userProfileService.Update(user);
            }

            return(RedirectToAction("Details", new { area = "User" }));
        }
        public async Task <IActionResult> Put([FromBody][Required] UserProfileUpdateViewModel model)
        {
            var response = await _jwtHttpServiceClient
                           .PutAsync <UserProfileUpdateViewModel, UserProfileUpdateViewModel>(InternalUserProfileRoute, model);

            _logger.LogInformation($"Call {InternalUserProfileRoute} return {response.StatusCode}.");

            if (response.IsSuccessStatusCode)
            {
                return(Ok(response.Value));
            }

            switch (response.StatusCode)
            {
            case HttpStatusCode.Unauthorized:
                return(Unauthorized());

            case HttpStatusCode.Forbidden:
                return(new ForbidResult());
            }

            throw new Exception($"A problem happened while calling the API: {response.Message}");
        }
        public ActionResult Edit(HeaderInfoController headerInfoController, UserProfileUpdateViewModel userProfile)
        {
            var user = _accountService.GetUserById(userProfile.UserId);
            if (user == null)
                throw new System.IO.FileNotFoundException();

            user.BirthDate = userProfile.Birthday;
            user.DisplayName = userProfile.DisplayName;
            user.Email = userProfile.Email;
            user.Location = userProfile.Location;
            user.PreferredUserName = userProfile.DisplayName;
            user.RealName = userProfile.RealName;
            user.TwitterUserName = userProfile.TwitterUserName;

            if (!user.IsValid)
            {
                ModelState.AddModelErrors(user.RuleViolations);
                return View(userProfile);
            }

            _accountService.UpdateUser(user);

            return RedirectToAction("Display", new { id = userProfile.UserId, userName = userProfile.DisplayName });
        }