public string SaveRegistrationInfo(ITaxAuthorityView registrationInfo, out int registrationId) { if (registrationInfo == null) { throw new ArgumentNullException(nameof(registrationInfo)); } var result = string.Empty; var newRecord = new UserRegistration { Password = registrationInfo.Password, FirstName = registrationInfo.FirstName, Email = registrationInfo.Email, DateVerified = DateTime.Now, LastName = registrationInfo.LastName, IsActive = registrationInfo.IsActive, PhoneNumber = registrationInfo.PhoneNumber, DateCreated = DateTime.Now, IsUserVerified = false }; using ( var dbContext = (PitalyticsEntities)dbContextFactory.GetDbContext()) { dbContext.UserRegistrations.Add(newRecord); dbContext.SaveChanges(); } registrationId = newRecord.UserRegistrationId; return(result); ; }
/// <summary> /// Creates the updated registraion view. /// </summary> /// <param name="taxAuthorityView">The tax authority view.</param> /// <param name="processingMessage">The processing message.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">taxAuthorityView</exception> public ITaxAuthorityView CreateUpdatedRegistraionView(ITaxAuthorityView taxAuthorityView, IList <IJurisdiction> jurisdictions, IList <IInlandRevenue> inlandRevenues, string processingMessage) { if (taxAuthorityView == null) { throw new ArgumentNullException(nameof(taxAuthorityView)); } var inlandRevenueNameDDL = GetInlandRevenueDropdown.GetInlandRevnue(inlandRevenues, -1); var jurisdictionDDL = GetJurisdictionDropdown.GetJurisdicions(jurisdictions, -1); taxAuthorityView.ProcessingMessage = processingMessage; taxAuthorityView.InlandRevenueNames = inlandRevenueNameDDL; taxAuthorityView.JurisdictionNames = jurisdictionDDL; return(taxAuthorityView); }
/// <summary> /// Gets the updated registration view. /// </summary> /// <param name="taxAuthorityView">The tax authority view.</param> /// <param name="processingMessage">The processing message.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">taxAuthorityView</exception> public ITaxAuthorityView GetUpdatedRegistrationView(ITaxAuthorityView taxAuthorityView, string processingMessage) { if (taxAuthorityView == null) { throw new ArgumentNullException(nameof(taxAuthorityView)); } var jurisidctionList = this.generalRepository.GetJurisdiction(); jurisidctionList = jurisidctionList.Where(x => x.IsActive == true).ToList(); var inlandRevenueNameList = this.generalRepository.GetInlandRevenue(); inlandRevenueNameList = inlandRevenueNameList.Where(x => x.IsActive == true).ToList(); return(this.accountViewsModelFactory.CreateUpdatedRegistraionView(taxAuthorityView, jurisidctionList, inlandRevenueNameList, processingMessage)); }
/// <summary> /// Saves the agentof deduction information. /// </summary> /// <param name="agentOfDeductionView">The agent of deduction view.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">agentOfDeductionView</exception> public string saveTaxAuthorityInfo(ITaxAuthorityView taxAuthorityView, int registrationId) { if (taxAuthorityView == null) { throw new ArgumentNullException(nameof(taxAuthorityView)); } var result = string.Empty; var newRecord = new TaxAuthority { DateCreated = DateTime.Now, UserRegistrationId = registrationId, Description = taxAuthorityView.Description, InlandRevenueId = taxAuthorityView.InlandRevenueId, JurisdictionId = taxAuthorityView.JurisdictionId, IsActive = true }; try { using ( var dbContext = (PitalyticsEntities)dbContextFactory.GetDbContext()) { dbContext.TaxAuthorities.Add(newRecord); dbContext.SaveChanges(); } } catch (Exception e) { throw new Exception($"Save Tax Authority - {e.Message} , {(e.InnerException != null ? e.InnerException.Message : "")}"); } return(result); ; }
/// <summary> /// Processes the tax authority registration information. /// </summary> /// <param name="taxAuthorityView">The tax authority view.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">taxAuthorityView</exception> public ITaxAuthorityView ProcessTaxAuthorityRegistrationInfo(ITaxAuthorityView taxAuthorityView) { if (taxAuthorityView == null) { throw new System.ArgumentNullException(nameof(taxAuthorityView)); } var processingMessage = string.Empty; var isDataOkay = true; //checks if similar email does exist in the database var registrationData = this.accountRepository.GetRegistrationByEmail(taxAuthorityView.Email); var IsRecordExist = (registrationData != null); if (IsRecordExist) { isDataOkay = false; processingMessage = Messages.IsEmailExist; } else { var checkTaxAuthority = this.accountRepository.GetTaxAuthority(taxAuthorityView.InlandRevenueId, taxAuthorityView.JurisdictionId); if (checkTaxAuthority.Count > 0) { isDataOkay = false; processingMessage = Messages.TaxAuthorityExist; } } var jurisdictionList = this.generalRepository.GetJurisdiction(); jurisdictionList = jurisdictionList.Where(x => x.IsActive == true).ToList(); var inlandRevenueNameList = this.generalRepository.GetInlandRevenue(); inlandRevenueNameList = inlandRevenueNameList.Where(x => x.IsActive == true).ToList(); var returnViewModel = this.accountViewsModelFactory.CreateUpdatedRegistraionView(taxAuthorityView, jurisdictionList, inlandRevenueNameList, processingMessage); if (!isDataOkay) { return(returnViewModel); } //save data to database var registrationId = 0; taxAuthorityView.Password = this.encryptionService.Encrypt(taxAuthorityView.Password); taxAuthorityView.IsActive = false; var savedData = this.accountRepository.SaveRegistrationInfo(taxAuthorityView, out registrationId); var saveInfo = this.accountRepository.saveTaxAuthorityInfo(taxAuthorityView, registrationId); var getRole = this.accountRepository.GetAdminRoleUserRoles(EnvironmentValues.TaxAuthority); // this.accountRepository.CreateUserRole(taxAuthorityView.Email, getRole.AdminRoleId); if (savedData == string.Empty) { //Send activation Link to the User, //Genenrate Activation Code var activationCode = CodeGenerators.GenerateActivationCode(); //Get The registered User Information var user = this.accountRepository.GetRegistrationByEmail(taxAuthorityView.Email); //Pass the Code and the user ID to store to Database var result = this.accountRepository.SaveUserActivationCode(user.UserRegistrationId, activationCode); // email send implementation here var emailDetail = this.emailFactory.CreateRegistrationRequestEmail(taxAuthorityView.Email, taxAuthorityView.FirstName, activationCode); //999 is the registrationId from database var emailKey = this.environment[EnvironmentValues.EmailKey]; this.emailService.Send(emailKey, "*****@*****.**", "Pitalytics Team", emailDetail.Subject, emailDetail.Recipients, emailDetail.Recipients, "", emailDetail.Body); } return(returnViewModel); }