public async Task <IActionResult> Create([FromForm] ParticipantBindingModel model) { var entity = _mapper.Map <Participant>(model); entity.PlainPassword = ExtensionMethods.GeneratePassword(6, 1); entity.Password = _passwordHasher.Hash(entity.PlainPassword); entity.Username = model.Email; entity.CreatedBy = UserId; if (model.Photo != null && model.Photo.Length > 0) { var fileName = model.Photo.FileName.ToUniqueFileName(); var savePath = Path.Combine(_hostEnvironment.WebRootPath, UploadFolders.UPLOAD_PATH, UploadFolders.PARTICIPANTS, fileName); await model.Photo.CopyToAsync(new FileStream(savePath, FileMode.Create)); entity.PhotoUrl = (new string[] { UploadFolders.UPLOAD_PATH, UploadFolders.PARTICIPANTS, fileName }).ToWebFilePath(); // Create Thumbnail Image var thumbnailImagePath = fileName.ToThumbnailImagePath(); savePath = Path.Combine(_hostEnvironment.WebRootPath, UploadFolders.UPLOAD_PATH, UploadFolders.PARTICIPANTS, thumbnailImagePath); var thumbnailImage = _imageHelper.ResizeImage(model.Photo, 100, 100, false); using var fileStream = new FileStream(savePath, FileMode.Create); await thumbnailImage.CopyToAsync(fileStream); } await _repository.AddAsync(entity); return(Ok()); }
public async Task <IActionResult> Update([FromForm] ParticipantBindingModel model) { var entity = await _participantRepository.FindAsync(UserId); if (entity == null) { return(BadRequest(new BadRequestResponseModel(ErrorTypes.BadRequest, ErrorMessages.ItemNotFound))); } entity.Title = model.Title; entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.EmailCorp = model.EmailCorp; entity.EmailPersonal = model.EmailPersonal; entity.Phone = model.Phone; entity.PhoneCorp = model.PhoneCorp; //entity.Active = model.Active; entity.LinkedinUrl = model.LinkedinUrl; entity.CompanyName = model.CompanyName; if (model.Photo != null && model.Photo.Length > 0) { var fileName = model.Photo.FileName.ToUniqueFileName(); var savePath = Path.Combine(_hostEnvironment.WebRootPath, UploadFolders.UPLOAD_PATH, UploadFolders.PARTICIPANTS, fileName); await model.Photo.CopyToAsync(new FileStream(savePath, FileMode.Create)); entity.PhotoUrl = (new string[] { UploadFolders.UPLOAD_PATH, UploadFolders.PARTICIPANTS, fileName }).ToWebFilePath(); // Create Thumbnail Image var thumbnailImagePath = fileName.ToThumbnailImagePath(); savePath = Path.Combine(_hostEnvironment.WebRootPath, UploadFolders.UPLOAD_PATH, UploadFolders.PARTICIPANTS, thumbnailImagePath); var thumbnailImage = _imageHelper.ResizeImage(model.Photo, 100, 100, false); using var fileStream = new FileStream(savePath, FileMode.Create); await thumbnailImage.CopyToAsync(fileStream); } entity.UpdatedBy = UserId; entity.UpdatedAt = DateTime.Now; await _participantRepository.UpdateAsync(entity); return(Ok()); }