public async Task <UserProfileResponse> EditProfile([FromBody] EditUserProfileRequest req) { var payload = (UserPayload)HttpContext.Items["User"]; req.UserId = payload.Id; var profile = await _userProfileService.EditUserProfileAsync(req); return(profile); }
public Result <ServiceResponse> EditUserProfile(EditUserProfileRequest request) { // new TransientGrantingPermissionService(new PermissionService()).Grant("Administration:User:Modify"); return(this.UseConnection("Default", connection => { request.CheckNotNull(); var user = (UserDefinition)Serenity.Authorization.UserDefinition; if (request.DisplayName.IsEmptyOrNull()) { throw new ArgumentNullException("name"); } if (request.Email.IsEmptyOrNull()) { throw new ArgumentNullException("email"); } var saveRequest = new SaveRequest <UserRow>(); saveRequest.Entity = new UserRow(); saveRequest.EntityId = user.UserId; saveRequest.Entity.UserId = user.UserId; saveRequest.Entity.DisplayName = request.DisplayName; saveRequest.Entity.Email = request.Email; saveRequest.Entity.Info = request.Info; if (!request.UserImage.IsNullOrEmpty()) { saveRequest.Entity.UserImage = request.UserImage; } saveRequest.Entity.EmailSignature = request.EmailSignature; saveRequest.Entity.WebSite = request.WebSite; saveRequest.Entity.PhoneNumber = request.PhoneNumber; var uow = new UnitOfWork(connection); new UserRepository().Update(uow, saveRequest); uow.Commit(); UserRetrieveService.RemoveCachedUser(user.UserId, user.Username); return new ServiceResponse(); })); }
public async Task <UserProfileResponse> EditUserProfileAsync(EditUserProfileRequest req) { var profileModel = await _dbContext.UserProfiles.Include(prof => prof.User).Where(x => x.User.Id == req.UserId).FirstOrDefaultAsync(); if (profileModel == null) { var errorResp = new UserProfileResponse { Succes = false, Errors = new List <string>() }; errorResp.Errors.Add("User with such id does not exist!"); return(errorResp); } profileModel.ProfileDescription = req.ProfileDescription; _dbContext.UserProfiles.Update(profileModel); _dbContext.SaveChanges(); var resp = _mapper.Map <UserProfileModel, UserProfileResponse>(profileModel); return(await Task.FromResult <UserProfileResponse>(resp)); }