// TODO: Add security public async Task <bool> UpdateUser(InputProfileSettingsModel model) { var entity = this.userRepository.All().Where(x => x.Id == model.Id).FirstOrDefault(); if (entity == null) { return(false); } entity.UserName = model.UserName; entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.AboutMe = model.AboutMe; entity.BirthDate = model.BirthDate; entity.PhoneNumber = model.PhoneNumber; var profileImageName = Guid.NewGuid().ToString(); var profileImageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, model.ProfileImageSource, profileImageName); if (!string.IsNullOrEmpty(profileImageUrl)) { entity.ProfileImage = new Media() { Url = profileImageUrl, Name = profileImageName, Creator = entity, }; } var coverImageName = Guid.NewGuid().ToString(); var coverImageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, model.CoverImageSource, coverImageName); if (!string.IsNullOrEmpty(coverImageUrl)) { entity.CoverImage = new Media() { Url = coverImageUrl, Name = coverImageName, Creator = entity, }; } this.userRepository.Update(entity); await this.userRepository.SaveChangesAsync(); return(true); }
public async Task <IActionResult> Settings(InputProfileSettingsModel model) { await this.usersService.UpdateUser(model); return(this.RedirectToAction(nameof(this.Index), new { username = model.UserName })); }