public async Task <BusinessProfileResponse> SaveAsync(BusinessProfile businessProfile) { Account account = new Account(); account.User = businessProfile.Email; account.Password = businessProfile.Password; account.RolId = 1; account.SubscriptionPlanId = 1; // Por defecto tiene el plan free account.BusinessProfile = businessProfile; account.Rol = _rolRepository.FindByIdAsync(2).Result; try { if (businessProfile.Owner) // si eres propietario { Provider provider = new Provider(); provider.BusinessName = ""; provider.Address = ""; provider.Description = ""; provider.Email = ""; provider.Field = ""; provider.Region = ""; await _providerRepository.AddAsyn(provider); businessProfile.Provider = provider; businessProfile.ProviderId = provider.Id; } await _businessRepository.AddAsyn(businessProfile); await _accountRepository.AddAsyn(account); await _unitOfWork.CompleteAsync(); return(new BusinessProfileResponse(businessProfile)); } catch (Exception ex) { return(new BusinessProfileResponse($"An error ocurred while saving the businessProfile: {ex.Message}")); } }
public async Task <ProviderResponse> SaveAsync(Provider servicesProvider) { Account account = new Account(); account.User = servicesProvider.Email; // account.Password = servicesProvider.Password; account.RolId = 2; account.Rol = _rolRepository.FindByIdAsync(2).Result; try { await _servicesProviderRepository.AddAsyn(servicesProvider); await _accountRepository.AddAsyn(account); await _unitOfWork.CompleteAsync(); return(new ProviderResponse(servicesProvider)); } catch (Exception ex) { return(new ProviderResponse($"An error ocurred while saving the servicesProvider: {ex.Message}")); } }