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.")); }