public static StripeAccountViewModel MapStripeAccountDTOToStripeAccount(StripeAccountDTO stripeDTO) { if (stripeDTO == null) { throw new NullReferenceException("stripe dto is null"); } return(new StripeAccountViewModel { StripeAccountId = stripeDTO.StripeAccountId, UserEmail = stripeDTO.UserEmail }); }
public static StripeAccount MapStripeAccountDTOToStripeAccountModel(StripeAccountDTO stripeAccountDTO) { if (stripeAccountDTO == null) { throw new NullReferenceException("stripe account DTO is null"); } return(new StripeAccount { Id = stripeAccountDTO.Id, StripeAccountId = stripeAccountDTO.StripeAccountId, UserEmail = stripeAccountDTO.UserEmail, }); }
public Response <StripeAccountDTO> Create(StripeAccountDTO stripeAccountDTO) { try { StripeAccountValidator validator = new StripeAccountValidator(); ValidationResult results = validator.Validate(stripeAccountDTO); if (results.IsValid) { var account = StripeAccountMapper.MapStripeAccountDTOToStripeAccountModel(stripeAccountDTO); var accountResponse = _stripeRepository.Add(account); _stripeRepository.SaveChanges(); var accountEntityDTO = StripeAccountMapper.MapStripeAccountModelToStripeAccountDTO(accountResponse); var response = new Response <StripeAccountDTO> { DTO = accountEntityDTO }; return(response); } else { return(new Response <StripeAccountDTO>() { Errors = results.Errors.Select(x => new Error() { Type = ErrorType.ValidationError, Message = x.ErrorMessage }).ToList() }); } } catch (Exception ex) { return(new Response <StripeAccountDTO>() { Errors = new List <Error>() { new Error() { Type = ErrorType.Exception, Message = ex.Message } } }); } }