/// <summary> /// 修改用户个人信息 /// </summary> /// <param name="profile">个人信息</param> public GetProfileDTO EditProfile(EditProfileDTO profile) { var userid = HttpContext.Current.User.Identity.Name; using (var db = new AspodesDB()) { var user = db.Users.FirstOrDefault(c => c.UserId == userid); if (user != null) { //user.UserId = profile.Email; //user.Person.Email = profile.Email; user.Person.Phone = profile.Phone; user.Person.Address = profile.Address; //判断是否为专家 //var expertInfo = db.ExpertInfos.FirstOrDefault(c => c.ExpertInfoId == userid); //if (expertInfo != null) //{ // expertInfo.ExpertInfoId = profile.Email; //} db.SaveChanges(); return(Mapper.Map <GetProfileDTO>(user.Person)); } else { throw new NotFoundException("找不到用户!"); } } }
public async Task <IActionResult> EditProfile(EditProfileDTO model, IFormFile file) { //model.Image = file; await _userService.EditUser(model); return(RedirectToAction(nameof(HomeController.Index), "Home")); }
public async Task <IActionResult> EditProfile(EditProfileDTO model) { string id = User.Claims.First(x => x.Type == "UserID").Value; User temp = await manager.FindByIdAsync(id); temp.FullName = model.body.FullName; temp.UserName = model.body.Username; temp.Role = model.body.Role; temp.Email = model.body.Email; temp.CrewID = model.body.CrewID; temp.StreetID = (await data.Streets.FirstOrDefaultAsync(x => x.Name == model.body.Street)).Id; temp.DOB = model.body.DOB; await manager.UpdateAsync(temp); if (!string.IsNullOrWhiteSpace(model.body.Password)) { if ((await manager.ChangePasswordAsync(temp, model.currentPassword, model.body.Password)).Succeeded) { return(Ok(new { msg = "changedpass" })); } else { return(Ok(new { msg = "error" })); } } return(Ok(new { msg = "ok" })); }
public async Task <Models.Profile> UpdateUserProfile(EditProfileDTO ProfileDTO) { var formatedSkillsToString = string.Join(",", ProfileDTO.Skills); var profile = new Models.Profile { IdProfile = ProfileDTO.IdProfile, Phone = ProfileDTO.Phone, Country = ProfileDTO.Country, DateOfBirth = ProfileDTO.DateOfBirth, Major = ProfileDTO.Major, Skills = formatedSkillsToString, Experiences = ProfileDTO.Experiences, Semester = ProfileDTO.Semester }; profile = await _profileRepository.UpdateUserProfile(profile); var user = new User { IdUser = ProfileDTO.IdUser, FirstName = ProfileDTO.FirstName, LastName = ProfileDTO.LastName, Email = ProfileDTO.Email }; user = await _userRepository.UpdateProfileUser(user); return(profile); }
public async Task <WriteUserResponseDTO> EditProfile(int userId, EditProfileDTO data) { IUserDataValidator validator = new UserDataValidator(); var userData = new UserDataDTO { Email = data.Email, Name = data.Name, Surname = data.Surname }; var editResponce = new WriteUserResponseDTO { IsSuccessful = true, PropertyInfos = new List <WriteUserResponseDTO.PropertyInfo>() }; var user = _unitOfWork.Users.Find(u => u.Email.Equals(data.Email) && u.UserId != userId).FirstOrDefault(); validator.EditProfileValidation(user, userData, editResponce); if (editResponce.IsSuccessful) { EditUserData(userId, userData); await AddUserInfo(userId, data); } return(editResponce); }
public async Task <OperationDetails> Edit(EditProfileDTO model) { Profile profile = Database.ProfileManager.FindById(model.Id); User user = await Database.UserManager.FindByIdAsync(model.Id); if (model.UserName != null) { User clone = await Database.UserManager.FindByEmailAsync(model.UserName); if (model.UserName != user.UserName && clone != null) { return(new OperationDetails(false, "Username is being use", "")); } user.UserName = model.UserName; } if (model.Location != null) { if (Database.LocationRepository.FindClone(model.Location) == null) { Location l = Database.LocationRepository.Add(model.Location); profile.Location = l; } } if (model.Birthday != null) { profile.Birthday = model.Birthday; } await Database.SaveAsync(); return(new OperationDetails(true, "Ok", "")); }
public HttpResponseMessage Edit(int conferenceId, int id, [FromBody] EditProfileDTO data) { data.DisplayName = data.DisplayName.UnNull().Trim(); data.LastName = data.LastName.UnNull().Trim(); data.FirstName = data.FirstName.UnNull().Trim(); data.Biography = data.Biography.UnNull().Trim(); data.ShortBiography = data.ShortBiography.UnNull().Trim(); data.Company = data.Company.UnNull().Trim(); var attendee = AttendeeRepository.Instance.GetAttendee(conferenceId, id); if (attendee != null) { attendee.Company = data.Company; AttendeeRepository.Instance.UpdateAttendee(attendee.GetAttendeeBase(), UserInfo.UserID); } var speaker = SpeakerRepository.Instance.GetSpeaker(conferenceId, UserInfo.UserID); if (speaker != null) { speaker.Description = data.Biography; speaker.DescriptionShort = data.ShortBiography; speaker.Company = data.Company; SpeakerRepository.Instance.UpdateSpeaker(speaker, UserInfo.UserID); } var user = UserController.Instance.GetUserById(PortalSettings.PortalId, id); if (user != null) { user.Profile.Biography = data.Biography; user.Profile.FirstName = data.FirstName; user.Profile.LastName = data.LastName; user.FirstName = data.FirstName; user.LastName = data.LastName; user.DisplayName = data.DisplayName; FixDnnController.SetUserProfileProperty(PortalSettings.PortalId, user.UserID, "Company", data.Company); UserController.UpdateUser(PortalSettings.PortalId, user); } var res = new EditProfileDTO(); attendee = AttendeeRepository.Instance.GetAttendee(conferenceId, id); if (attendee != null) { res.Company = attendee.Company; } speaker = SpeakerRepository.Instance.GetSpeaker(conferenceId, UserInfo.UserID); if (speaker != null) { res.Biography = speaker.Description; res.ShortBiography = speaker.DescriptionShort; } user = UserController.Instance.GetUserById(PortalSettings.PortalId, id); if (user != null) { res.DisplayName = user.DisplayName; res.LastName = user.Profile.LastName; res.FirstName = user.Profile.FirstName; } return(Request.CreateResponse(HttpStatusCode.OK, res)); }
public HttpResponseMessage Put(EditProfileDTO profile) { try { return(ResponseWrapper.SuccessResponse(repository.EditProfile(profile))); } catch (Exception e) { return(ResponseWrapper.ExceptionResponse(e)); } }
public async Task <IActionResult> UserAccountEdit(EditProfileDTO model, IFormFile file) { if (ModelState.IsValid) { if (file != null) { model.Image = file; } await _appUserService.EditUser(model); } return(RedirectToAction("UsersAccount", "Home")); }
public async Task EditUser(EditProfileDTO editProfileDTO) { var user = await _unitOfWork.AppUser.GetById(editProfileDTO.Id); if (user != null) { if (editProfileDTO.CompanyId != null || editProfileDTO.CompanyId > 0) { user.CompanyId = editProfileDTO.CompanyId; user.Status = Status.Active; } if (editProfileDTO.Image != null) { using var image = Image.Load(editProfileDTO.Image.OpenReadStream()); image.Mutate(x => x.Resize(256, 256)); string newName = Guid.NewGuid().ToString(); image.Save($"wwwroot/images/users/{newName}.jpg"); user.ImagePath = ($"/images/users/{newName}.jpg"); } if (editProfileDTO.Password != null) { user.PasswordHash = _userManager.PasswordHasher.HashPassword(user, editProfileDTO.Password); await _userManager.UpdateAsync(user); } if (editProfileDTO.UserName != null) { var isUserNameExist = await _userManager.FindByNameAsync(editProfileDTO.UserName.ToUpper()); if (isUserNameExist == null) { await _userManager.SetUserNameAsync(user, editProfileDTO.UserName); } } if (editProfileDTO.Email != user.Email) { var isEmailExist = await _userManager.FindByEmailAsync(editProfileDTO.Email); if (isEmailExist == null) { await _userManager.SetEmailAsync(user, editProfileDTO.Email); } } user.FullName = editProfileDTO.FullName; _unitOfWork.AppUser.Update(user); await _unitOfWork.Commit(); } }
public async Task EditUser(EditProfileDTO model) { var user = await _unitOfWork.AppUserRepository.GetById(model.Id); if (user != null) { if (model.Image != null) { using var image = Image.Load(model.Image.OpenReadStream()); image.Mutate(x => x.Resize(256, 256)); image.Save("wwwroot/images/users/" + user.UserName + ".jpg"); user.ImagePath = ("/images/users/" + user.UserName + ".jpg"); _unitOfWork.AppUserRepository.Update(user); await _unitOfWork.Commit(); } if (model.Password != null) { user.PasswordHash = _userManager.PasswordHasher.HashPassword(user, model.Password); await _userManager.UpdateAsync(user); } if (model.UserName != user.UserName) { var isUserNameExist = await _userManager.FindByNameAsync(model.UserName); if (isUserNameExist == null) { await _userManager.SetUserNameAsync(user, model.UserName); user.UserName = model.UserName; await _signInManager.SignInAsync(user, isPersistent : true); } } if (model.Name != user.Name) { user.Name = model.Name; _unitOfWork.AppUserRepository.Update(user); await _unitOfWork.Commit(); } if (model.Email != user.Email) { var isEmailExist = await _userManager.FindByEmailAsync(model.Email); if (isEmailExist == null) { await _userManager.SetEmailAsync(user, model.Email); } } } }
public async Task EditUser(EditProfileDTO editProfileDTO) { AppUser user = await _unitOfWork.AppUserRepository.GetById(editProfileDTO.Id); if (user != null) { if (editProfileDTO.Image != null) { using var image = Image.Load(editProfileDTO.Image.OpenReadStream()); image.Mutate(x => x.Resize(100, 100)); image.Save("wwwroot/images/users/" + user.UserName + ".jpg"); user.ImagePath = ("/images/users/" + user.UserName + ".jpg"); } if (editProfileDTO.Password != null) { user.PasswordHash = _userManager.PasswordHasher.HashPassword(user, editProfileDTO.Password); await _userManager.UpdateAsync(user); } if (editProfileDTO.UserName != null) { var isUserNameExist = _unitOfWork.AppUserRepository.FirstOrDefault(x => x.UserName == editProfileDTO.UserName); if (isUserNameExist == null) { await _userManager.SetUserNameAsync(user, editProfileDTO.UserName); //user.UserName = editProfileDTO.UserName; //await _userManager.UpdateAsync(user); } } if (editProfileDTO.Email != null) { var isEmailExist = _unitOfWork.AppUserRepository.FirstOrDefault(x => x.Email == editProfileDTO.Email); if (isEmailExist == null) { await _userManager.SetEmailAsync(user, editProfileDTO.Email); } } if (editProfileDTO.Name != null) { //var isNameExsist = _unitOfWork.AppUserRepository.FirstOrDefault(x => x.Name == editProfileDTO.Name); user.Name = editProfileDTO.Name; } _unitOfWork.AppUserRepository.Update(user); await _unitOfWork.Commit(); } }
public async Task <IActionResult> UpdateUserProfile(EditProfileDTO profileDTO) { await _profileService.UpdateUserProfile(profileDTO); return(StatusCode(200, profileDTO)); }
public async Task <WriteUserResponseDTO> EditProfile([FromHeader] string Authorization, EditProfileDTO data) { try { var response = await _personService.EditProfile(TokenParcer.GetUserIdByToken(Authorization), data); if (!response.IsSuccessful) { HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict; } return(response); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("\n"); Console.WriteLine(e.StackTrace); HttpContext.Response.StatusCode = (int)HttpStatusCode.NoContent; return(null); } }