public async Task <string> UpdateAsync(UserEditInputModel inputModel) { var user = await this.usersRepository .All() .FirstOrDefaultAsync(u => u.Id == inputModel.Id); if (user == null) { return(null); } user.FirstName = inputModel.FirstName; user.LastName = inputModel.LastName; user.Email = inputModel.Email; user.Age = inputModel.Age; user.Gender = inputModel.Gender; user.PhoneNumber = inputModel.PhoneNumber; if (inputModel.NewImage != null) { var oldImageId = user.AvatarImageId; var newImage = await this.imagesService.CreateAsync(inputModel.NewImage); user.AvatarImageId = newImage.Id; await this.imagesService.DeleteAsync(oldImageId); } this.usersRepository.Update(user); await this.usersRepository.SaveChangesAsync(); return(user.Id); }
public async Task UpdateAsyncSetsAllProperiestCorrect() { var inputModel = new UserEditInputModel { Id = this.User.Id, Email = this.User.Email, FirstName = this.User.FirstName, LastName = this.User.LastName, PhoneNumber = "0881111111", }; var userId = await this.Service.UpdateAsync(inputModel); var user = await this.DbContext.ApplicationUsers.FirstOrDefaultAsync(c => c.Id == userId); Assert.Equal(inputModel.Email, user.Email); Assert.Equal(inputModel.FirstName, user.FirstName); Assert.Equal(inputModel.LastName, user.LastName); Assert.Equal(inputModel.PhoneNumber, user.PhoneNumber); Assert.Null(user.Age); Assert.Null(user.Gender); Assert.Null(user.AvatarImageId); Assert.Null(user.AvatarImage); Assert.Null(user.CarId); Assert.Null(user.Car); Assert.False(user.HasUsersToReview); Assert.Equal(0, user.TripsCountAsDriver); Assert.Equal(0, user.TripsCountAsPassenger); Assert.Equal(0, user.Rating); Assert.Equal(0, user.RatingsCount); Assert.Equal(0, user.TravelledDistance); }
public async Task <string> EditUserProfileAsync(UserEditInputModel model) { var user = await this.GetLoggedInUserAsync(); user.PhoneNumber = model.PhoneNumber; user.Email = model.Email; user.ProfileImage = await ApplicationCloudinary.UploadImage(cloudinary, model.ProfilePicture, Guid.NewGuid().ToString()); this.dbContext.Update(user); await this.dbContext.SaveChangesAsync(); return(user.Id); }
public async Task UpdateAsyncReturnsTheUserId() { var inputModel = new UserEditInputModel { Id = this.User.Id, Email = this.User.Email, FirstName = this.User.FirstName, LastName = this.User.LastName, PhoneNumber = "0881111111", }; var userId = await this.Service.UpdateAsync(inputModel); Assert.Equal(this.User.Id, userId); }
public async Task UpdateAsyncReturnsNullWhenUserDoesNotExist() { var inputModel = new UserEditInputModel { Id = "testId", Email = this.User.Email, FirstName = this.User.FirstName, LastName = this.User.LastName, PhoneNumber = "0881111111", }; var userId = await this.Service.UpdateAsync(inputModel); Assert.Null(userId); }
public async Task <IActionResult> Edit(UserEditInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.RedirectToAction("Edit", new { id = inputModel.Id })); } var userId = await this.usersService.UpdateAsync(inputModel); if (userId == null) { return(this.RedirectToAction("BadRequest", "Errors")); } this.TempData["Notification"] = "Your profile was successfully edited."; return(this.RedirectToAction("Details", new { id = userId })); }
public IResultObjectModel <UserDto> Edit(IUserInputModel inputModel) { IResultObjectModel <UserDto> resultObjectModel = new ResultObjectModel <UserDto>(); try { //UserEditInputModel için özel bir validationOperation'da tercih edilebilir. UserEditInputModel userEditInputModel = (UserEditInputModel)inputModel; IResultObjectModel <UserDto> editResult = EditUserDtoByInputModel(inputModel, userEditInputModel); resultObjectModel = UpdateByEditResult(resultObjectModel, editResult); } catch (System.Exception ex) { resultObjectModel.IsSuccess = false; ExceptionManager exceptionManager = new ExceptionManager(ex); resultObjectModel.Messages.AddRange(exceptionManager.GetMessages()); } resultObjectModel.SetResult(); return(resultObjectModel); }
public UserDto Edit(UserDto userDto, IUserInputModel inputModel) { UserEditInputModel editInputModel = (UserEditInputModel)inputModel; NullCheck(editInputModel); try { userDto.Name = editInputModel.Name; userDto.Surname = editInputModel.Surname; userDto.Address = editInputModel.Address; return(userDto); } catch (Exception ex) { throw new BusinessOperationException(new BusinesOperationExceptionModel { ClassName = "UserRegisterInputBusinessOperation", MethodName = "Create", OriginalMessage = ex.Message }, ex); } }
public async Task <IActionResult> Edit(UserEditInputModel model) { var userId = await this.userService.EditUserProfileAsync(model); return(Redirect($"/Details/{userId}")); }
public async Task <bool> UpdateUserAsync(UserEditInputModel userInfo) { var responce = await _httpClient.PostAsJsonAsync("api/users/update", userInfo); return(responce.IsSuccessStatusCode); }
private IResultObjectModel <UserDto> EditUserDtoByInputModel(IUserInputModel inputModel, UserEditInputModel userEditInputModel) { IResultObjectModel <UserDto> getResult = Get(userEditInputModel.Id); if (getResult.IsSuccess) { IUserEditInputBusinessOperation userEditBusinessOperation = IoCManager.Resolve <IUserEditInputBusinessOperation>(); getResult.Data = userEditBusinessOperation.Edit(getResult.Data, inputModel); } getResult.SetResult(); return(getResult); }