public async Task <IActionResult> UpdateProfileImage(IFormFile file) { try { var userInformation = await _manager.FindByEmailAsync(User.FindFirst(ClaimTypes.Email).Value); if (userInformation == null) { return(NotFound()); } if (file != null) { if (file.Length == 0) { return(BadRequest("Empty File")); } if (file.Length > _photoAppSettings.MaxBytes) { return(BadRequest("Maximum file size exceeded")); } if (!_photoAppSettings.IsSupported(file.FileName)) { return(BadRequest("Invalid file type")); } var awsServiceclientSettings = new AwsServiceClientSettings(file, _awsAppSettings.BucketName, _awsAppSettings.SubFolderProfile, _awsAppSettings.BucketLocation, _awsAppSettings.PublicDomain); var photoUrl = await _awsServiceClient.UploadAsync(awsServiceclientSettings); userInformation.ProfilePictureFileName = photoUrl; if (!string.IsNullOrWhiteSpace(photoUrl)) { var result = await _manager.UpdateAsync(userInformation); if (result.Succeeded) { return(Ok(userInformation)); } var sb = new StringBuilder(); foreach (var error in result.Errors) { sb.Append(error); sb.Append("\n"); } return(BadRequest(sb.ToString())); } } return(NotFound("Please select an Image for update")); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public async Task <IActionResult> PostInvoice(SaveInvoiceResource resource, IFormFile file) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var awsServiceclientSettings = new AwsServiceClientSettings(file, _awsAppSettings.BucketName, _awsAppSettings.SubFolderW9, _awsAppSettings.BucketLocation, _awsAppSettings.PublicDomain); var documentUrl = ""; if (file != null) { if (file.Length > _photoAppSettings.MaxBytes) { return(BadRequest("Maximum file size exceeded")); } else { if (!_photoAppSettings.IsSupported(file.FileName)) { return(BadRequest("Invalid file type")); } else { documentUrl = await _awsServiceClient.UploadAsync(awsServiceclientSettings); } } } var invoice = _mapper.Map <SaveInvoiceResource, Invoices>(resource); invoice.FilePath = documentUrl; invoice.BankId = await GetUserId(); _repository.Add(invoice); await _unitOfWork.CompleteAsync(); var result = _mapper.Map(invoice, resource); return(Ok(result)); }
public async Task <object> Update(UpdateProfileRequest resource, IFormFile file) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var awsServiceclientSettings = new AwsServiceClientSettings(file, _awsAppSettings.BucketName, _awsAppSettings.SubFolderProfile, _awsAppSettings.BucketLocation, _awsAppSettings.PublicDomain); var documentUrl = ""; if (file != null) { if (file.Length > _photoAppSettings.MaxBytes) { return(BadRequest("Maximum file size exceeded")); } else { if (!_photoAppSettings.IsSupported(file.FileName)) { return(BadRequest("Invalid file type")); } else { documentUrl = await _awsServiceClient.UploadAsync(awsServiceclientSettings); } } } var email = User.FindFirst(ClaimTypes.Email).Value; var currentUser = await _userManager.FindByEmailAsync(email); currentUser.FirstName = resource.FirstName; currentUser.LastName = resource.LastName; currentUser.Country = resource.Country; currentUser.Address = resource.Address; currentUser.State = resource.State; currentUser.PhoneNumber = resource.PhoneNumber; currentUser.BusinessName = resource.BusinessName; currentUser.RoutingNumber = resource.RoutingNumber; currentUser.AccountNumber = resource.AccountNumber; currentUser.TaxId = resource.TaxId; currentUser.OriginatingPartyName = resource.OriginatingPartyName; currentUser.ReceivingPartyName = resource.ReceivingPartyName; currentUser.BankName = resource.BankName; currentUser.W9 = ""; var result = await _userManager.UpdateAsync(currentUser); if (result.Succeeded) { return(Ok("Profile is succesfully updated.")); } return(BadRequest(result.Errors)); } catch (Exception e) { return(BadRequest(e.ToString())); } }
public async Task <object> Register(RegisterResource resource, IFormFile file) { if (!ModelState.IsValid) { log.Error(BadRequest((ModelState))); return(BadRequest(ModelState)); } var awsServiceclientSettings = new AwsServiceClientSettings(file, _awsAppSettings.BucketName, _awsAppSettings.SubFolderW9, _awsAppSettings.BucketLocation, _awsAppSettings.PublicDomain); var documentUrl = ""; if (file != null) { if (file.Length > _photoAppSettings.MaxBytes) { log.Error("Maximum file size exceeded"); return(BadRequest("Maximum file size exceeded")); } else { if (!_photoAppSettings.IsSupported(file.FileName)) { log.Error("Invalid file type"); return(BadRequest("Invalid file type")); } else { documentUrl = await _awsServiceClient.UploadAsync(awsServiceclientSettings); log.Info(documentUrl); } } } var userExist = await _userManager.FindByEmailAsync(resource.Email); log.Info(userExist); if (userExist != null) { log.Error("Email already is in use."); return(BadRequest("Email already is in use.")); } var user = new ApplicationUser { UserName = resource.Email, Email = resource.Email, FirstName = resource.FirstName, LastName = resource.LastName, Country = resource.Country, Address = resource.Address, State = resource.State, PhoneNumber = resource.PhoneNumber, BusinessName = resource.BusinessName, RoutingNumber = resource.RoutingNumber, AccountNumber = resource.AccountNumber, TaxId = resource.TaxId, OriginatingPartyName = resource.OriginatingPartyName, ReceivingPartyName = resource.ReceivingPartyName, BankName = resource.BankName, W9 = "" }; var result = await _userManager.CreateAsync(user, resource.Password); log.Info(result); if (result.Succeeded) { var roleAdd = await _userManager.AddToRoleAsync(user, resource.RoleName); log.Info(roleAdd); if (roleAdd.Succeeded) { user = await _userManager.FindByEmailAsync(resource.Email); log.Info(user); return(new LoginResourceResponse { User = user, Roles = new[] { resource.RoleName }, Token = GenerateJwtToken(user.Email, user) }); } log.Error("Error during adding role to the user."); return(BadRequest("Error during adding role to the user.")); } log.Error("Error during user creation."); return(BadRequest("Error during user creation.")); }
public async Task <IActionResult> Upload(int serviceId, List <IFormFile> files) { try { var servicePhoto = await _serviceRepository.GetServiceAsync(serviceId); if (servicePhoto == null) { return(NotFound()); } if (files != null && files.Count == 0) { return(BadRequest("Null file")); } var photos = await _repository.GetPhotos(serviceId); var numberOfphotos = 0; foreach (var ph in photos) { numberOfphotos++; } if (numberOfphotos >= 8) { return(BadRequest("Number of allowed photos limited to 8.")); } var results = new List <ServicePhotoResource>(); if (files != null) { foreach (var file in files) { if (file.Length == 0) { return(BadRequest("Empty file")); } if (file.Length > _photoAppSettings.MaxBytes) { return(BadRequest("Maximum file size exceeded")); } if (!_photoAppSettings.IsSupported(file.FileName)) { return(BadRequest("Invalid file type")); } var awsServiceSettings = new AwsServiceClientSettings(file, _awsAppSettings.BucketName, _awsAppSettings.SubFolderService, _awsAppSettings.BucketLocation, _awsAppSettings.PublicDomain); var photoUrl = await _awsServiceClient.UploadAsync(awsServiceSettings); var photo = new ServicePhoto { Url = photoUrl }; servicePhoto.Photos.Add(photo); await _unitOfWork.CompleteAsync(); results.Add(_mapper.Map <ServicePhoto, ServicePhotoResource>(photo)); } } if (results.Count > 0) { return(Ok(results)); } else { return(BadRequest("Unable to upload")); } } catch (Exception ex) { var message = $"Message: {ex.Message}\n Source:{ex.Source} \n Expection:{ex.InnerException}"; return(BadRequest(message)); } }