public override object AssociatePrefAttorneyProviderWithCompany(int PrefAttorneyProviderId, int CompanyId) { Company CompanyDB = _context.Companies.Where(p => p.id == CompanyId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))) .FirstOrDefault(); if (CompanyDB == null) { return(new BO.ErrorObject { ErrorMessage = "Company dosent exists.", errorObject = "", ErrorLevel = ErrorLevel.Information }); } Company AttorneyProviderCompanyDB = _context.Companies.Where(p => p.id == PrefAttorneyProviderId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))) .FirstOrDefault(); if (AttorneyProviderCompanyDB == null) { return(new BO.ErrorObject { ErrorMessage = "AttorneyProvider Company dosent exists.", errorObject = "", ErrorLevel = ErrorLevel.Information }); } var AttorneyProviderDB = _context.PreferredAttorneyProviders.Where(p => p.PrefAttorneyProviderId == PrefAttorneyProviderId && p.CompanyId == CompanyId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))) .FirstOrDefault(); bool AttorneyProvider = false; if (AttorneyProviderDB == null) { AttorneyProviderDB = new PreferredAttorneyProvider(); AttorneyProvider = true; } AttorneyProviderDB.PrefAttorneyProviderId = PrefAttorneyProviderId; AttorneyProviderDB.CompanyId = CompanyId; AttorneyProviderDB.IsDeleted = false; if (AttorneyProvider == true) { _context.PreferredAttorneyProviders.Add(AttorneyProviderDB); } _context.SaveChanges(); BO.PreferredAttorneyProvider acc_ = Convert <BO.PreferredAttorneyProvider, PreferredAttorneyProvider>(AttorneyProviderDB); if (acc_ == null) { return(new BO.ErrorObject { ErrorMessage = "No record found.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } return((object)acc_); }
public override T Convert <T, U>(U entity) { PreferredAttorneyProvider preferredAttorneyProvider = entity as PreferredAttorneyProvider; if (preferredAttorneyProvider == null) { return(default(T)); } BO.PreferredAttorneyProvider boPreferredAttorneyProvider = new BO.PreferredAttorneyProvider(); boPreferredAttorneyProvider.ID = preferredAttorneyProvider.Id; boPreferredAttorneyProvider.PrefAttorneyProviderId = preferredAttorneyProvider.PrefAttorneyProviderId; boPreferredAttorneyProvider.CompanyId = preferredAttorneyProvider.CompanyId; boPreferredAttorneyProvider.IsCreated = preferredAttorneyProvider.IsCreated; boPreferredAttorneyProvider.IsDeleted = preferredAttorneyProvider.IsDeleted; boPreferredAttorneyProvider.CreateByUserID = preferredAttorneyProvider.CreateByUserID; boPreferredAttorneyProvider.UpdateByUserID = preferredAttorneyProvider.UpdateByUserID; if (preferredAttorneyProvider.Company != null) { BO.Company Company = new BO.Company(); if (preferredAttorneyProvider.Company.IsDeleted.HasValue == false || (preferredAttorneyProvider.Company.IsDeleted.HasValue == true && preferredAttorneyProvider.Company.IsDeleted.Value == false)) { using (CompanyRepository sr = new CompanyRepository(_context)) { Company = sr.Convert <BO.Company, Company>(preferredAttorneyProvider.Company); Company.Locations = null; } } boPreferredAttorneyProvider.Company = Company; } if (preferredAttorneyProvider.Company1 != null) { BO.Company Company = new BO.Company(); if (preferredAttorneyProvider.Company1.IsDeleted.HasValue == false || (preferredAttorneyProvider.Company1.IsDeleted.HasValue == true && preferredAttorneyProvider.Company1.IsDeleted.Value == false)) { using (CompanyRepository sr = new CompanyRepository(_context)) { Company = sr.Convert <BO.Company, Company>(preferredAttorneyProvider.Company1); Company.Locations = null; } } boPreferredAttorneyProvider.PrefAttorneyProvider = Company; } return((T)(object)boPreferredAttorneyProvider); }
public override object Save <T>(T entity) { BO.PreferredAttorneyProviderSignUp preferredAttorneyProviderBO = (BO.PreferredAttorneyProviderSignUp)(object) entity; PreferredAttorneyProvider preferredMedicalProviderDB = new PreferredAttorneyProvider(); BO.Company companyBO = preferredAttorneyProviderBO.Company; BO.Signup prefAttProviderBO = preferredAttorneyProviderBO.Signup; Guid invitationDB_UniqueID = Guid.NewGuid(); User userDB = new User(); UserCompany UserCompanyDB = new UserCompany(); PreferredAttorneyProvider prefAttProvider = new PreferredAttorneyProvider(); bool IsEditMode = false; IsEditMode = (preferredAttorneyProviderBO != null && preferredAttorneyProviderBO.ID > 0) ? true : false; using (var dbContextTransaction = _context.Database.BeginTransaction()) { if (companyBO == null || (companyBO != null && companyBO.ID <= 0)) { dbContextTransaction.Rollback(); return(new BO.ErrorObject { ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } if (prefAttProviderBO == null) { dbContextTransaction.Rollback(); return(new BO.ErrorObject { ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } if (prefAttProviderBO.company == null) { dbContextTransaction.Rollback(); return(new BO.ErrorObject { ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } if (prefAttProviderBO.user == null) { dbContextTransaction.Rollback(); return(new BO.ErrorObject { ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } if (prefAttProviderBO.contactInfo == null) { dbContextTransaction.Rollback(); return(new BO.ErrorObject { ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } //if (string.IsNullOrEmpty(prefAttProviderBO.company.TaxID) == false && _context.Companies.Any(o => o.TaxID == prefAttProviderBO.company.TaxID && (o.IsDeleted.HasValue == false || (o.IsDeleted.HasValue == true && o.IsDeleted.Value == false)))) //{ // dbContextTransaction.Rollback(); // return new BO.ErrorObject { ErrorMessage = "TaxID already exists.", errorObject = "", ErrorLevel = ErrorLevel.Error }; //} if (_context.Companies.Any(o => o.Name == prefAttProviderBO.company.Name && (o.IsDeleted.HasValue == false || (o.IsDeleted.HasValue == true && o.IsDeleted.Value == false)))) { dbContextTransaction.Rollback(); return(new BO.ErrorObject { ErrorMessage = "Company already exists.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } else if (_context.Users.Any(o => o.UserName == prefAttProviderBO.user.UserName && (o.IsDeleted.HasValue == false || (o.IsDeleted.HasValue == true && o.IsDeleted.Value == false)))) { dbContextTransaction.Rollback(); return(new BO.ErrorObject { ErrorMessage = "User Name already exists.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } BO.Company prefAttProviderCompanyBO = prefAttProviderBO.company; BO.ContactInfo ContactInfoBO = prefAttProviderBO.contactInfo; BO.User userBO = prefAttProviderBO.user; BO.Role roleBO = prefAttProviderBO.role; Company prefAttProvider_CompanyDB = new Company(); AddressInfo AddressInfo = new AddressInfo(); ContactInfo ContactInfo = new ContactInfo() { CellPhone = ContactInfoBO.CellPhone, EmailAddress = ContactInfoBO.EmailAddress }; _context.AddressInfoes.Add(AddressInfo); _context.SaveChanges(); _context.ContactInfoes.Add(ContactInfo); _context.SaveChanges(); prefAttProvider_CompanyDB.Name = prefAttProviderCompanyBO.Name; prefAttProvider_CompanyDB.Status = System.Convert.ToByte(prefAttProviderCompanyBO.Status); prefAttProvider_CompanyDB.CompanyType = System.Convert.ToByte(prefAttProviderCompanyBO.CompanyType); if (prefAttProviderCompanyBO.SubsCriptionType != null) { prefAttProvider_CompanyDB.SubscriptionPlanType = System.Convert.ToByte(prefAttProviderCompanyBO.SubsCriptionType); } else { prefAttProvider_CompanyDB.SubscriptionPlanType = null; } prefAttProvider_CompanyDB.TaxID = prefAttProviderCompanyBO.TaxID; prefAttProvider_CompanyDB.AddressId = AddressInfo.id; prefAttProvider_CompanyDB.ContactInfoID = ContactInfo.id; prefAttProvider_CompanyDB.BlobStorageTypeId = 1; prefAttProvider_CompanyDB.CompanyStatusTypeID = 1; // CompanyStatusTypeID = 1 -- RegistrationImcomplete prefAttProvider_CompanyDB.IsDeleted = prefAttProviderCompanyBO.IsDeleted; prefAttProvider_CompanyDB.CreateByUserID = prefAttProviderCompanyBO.CreateByUserID; prefAttProvider_CompanyDB.UpdateByUserID = prefAttProviderCompanyBO.UpdateByUserID; prefAttProvider_CompanyDB.CreateDate = DateTime.UtcNow; _context.Companies.Add(prefAttProvider_CompanyDB); _context.SaveChanges(); userDB.FirstName = userBO.FirstName; userDB.LastName = userBO.LastName; userDB.UserName = userBO.UserName; userDB.UserType = 3; userDB.C2FactAuthEmailEnabled = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactEmail")); userDB.C2FactAuthSMSEnabled = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactSMS")); userDB.AddressId = prefAttProvider_CompanyDB.AddressId; userDB.ContactInfoId = prefAttProvider_CompanyDB.ContactInfoID; userDB.IsDeleted = false; userDB.CreateByUserID = userBO.CreateByUserID; userDB.CreateDate = DateTime.UtcNow; _context.Users.Add(userDB); _context.SaveChanges(); UserCompanyDB.UserID = userDB.id; UserCompanyDB.CompanyID = prefAttProvider_CompanyDB.id; UserCompanyDB.UserStatusID = 1; UserCompanyDB.IsDeleted = false; UserCompanyDB.CreateByUserID = 0; UserCompanyDB.CreateDate = DateTime.UtcNow; UserCompanyDB.IsAccepted = true; _context.UserCompanies.Add(UserCompanyDB); _context.SaveChanges(); UserCompanyRole UserCompanyRoleDB = new UserCompanyRole(); UserCompanyRoleDB.UserID = userDB.id; UserCompanyRoleDB.RoleID = (int)roleBO.RoleType; UserCompanyRoleDB.IsDeleted = false; UserCompanyRoleDB.CreateDate = DateTime.UtcNow; UserCompanyRoleDB.CreateByUserID = 0; _context.UserCompanyRoles.Add(UserCompanyRoleDB); _context.SaveChanges(); prefAttProvider.PrefAttorneyProviderId = prefAttProvider_CompanyDB.id; prefAttProvider.CompanyId = companyBO.ID; prefAttProvider.IsCreated = true; prefAttProvider.IsDeleted = false; prefAttProvider.CreateByUserID = prefAttProvider_CompanyDB.CreateByUserID; prefAttProvider.UpdateByUserID = prefAttProvider_CompanyDB.UpdateByUserID; prefAttProvider.CreateDate = DateTime.UtcNow; _context.PreferredAttorneyProviders.Add(prefAttProvider); _context.SaveChanges(); dbContextTransaction.Commit(); } #region Insert Invitation Invitation invitationDB = new Invitation(); invitationDB.User = userDB; invitationDB_UniqueID = Guid.NewGuid(); invitationDB.UniqueID = invitationDB_UniqueID; invitationDB.CompanyID = UserCompanyDB.CompanyID != 0 ? UserCompanyDB.CompanyID : 0; invitationDB.CreateDate = DateTime.UtcNow; invitationDB.CreateByUserID = userDB.id; _context.Invitations.Add(invitationDB); _context.SaveChanges(); #endregion if (IsEditMode == false) { try { #region Send Email var CurrentUser = _context.Users.Where(p => p.id == prefAttProvider.CreateByUserID && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault <User>(); var CurrentCompanyId = _context.UserCompanies.Where(p => p.UserID == CurrentUser.id && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).Select(p2 => p2.CompanyID).FirstOrDefault(); var CurrentCompany = _context.Companies.Where(p => p.id == CurrentCompanyId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault(); if (CurrentUser != null) { if (CurrentUser.UserType == 3) { var attorneyprovider_UserId = _context.UserCompanies.Where(p => p.CompanyID == prefAttProvider.PrefAttorneyProviderId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).Select(p2 => p2.UserID).FirstOrDefault(); var attorneyprovider_user = _context.Users.Where(p => p.id == attorneyprovider_UserId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault(); if (attorneyprovider_user != null) { var PreferredAttorneyAddByAttorney = _context.MailTemplates.Where(x => x.TemplateName.ToUpper() == "PreferredAttorneyAddByAttorney".ToUpper()).FirstOrDefault(); if (PreferredAttorneyAddByAttorney == null) { return(new BO.ErrorObject { ErrorMessage = "No record found Mail Template.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } else { #region Send mail to attorney string VarificationLink1 = "<a href='" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "' target='_blank'>" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "</a>"; string msg1 = PreferredAttorneyAddByAttorney.EmailBody; string subject1 = PreferredAttorneyAddByAttorney.EmailSubject; string message1 = string.Format(msg1, attorneyprovider_user.FirstName, CurrentUser.FirstName, CurrentCompany.Name, VarificationLink1); BO.Email objEmail1 = new BO.Email { ToEmail = attorneyprovider_user.UserName, Subject = subject1, Body = message1 }; objEmail1.SendMail(); #endregion } } } else if (CurrentUser.UserType == 2 || CurrentUser.UserType == 4) { var attorneyprovider_UserId = _context.UserCompanies.Where(p => p.CompanyID == prefAttProvider.PrefAttorneyProviderId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).Select(p2 => p2.UserID).FirstOrDefault(); var attorneyprovider_user = _context.Users.Where(p => p.id == attorneyprovider_UserId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault(); if (attorneyprovider_user != null) { var PreferredAttorneyAddByProvider = _context.MailTemplates.Where(x => x.TemplateName.ToUpper() == "PreferredAttorneyAddByProvider".ToUpper()).FirstOrDefault(); if (PreferredAttorneyAddByProvider == null) { return(new BO.ErrorObject { ErrorMessage = "No record found Mail Template.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } else { #region Send mail to attorney string VarificationLink1 = "<a href='" + Utility.GetConfigValue("AttorneyVerificationLink") + "/" + invitationDB_UniqueID + "' target='_blank'>" + Utility.GetConfigValue("AttorneyVerificationLink") + "/" + invitationDB_UniqueID + "</a>"; string msg1 = PreferredAttorneyAddByProvider.EmailBody; string subject1 = PreferredAttorneyAddByProvider.EmailSubject; string message1 = string.Format(msg1, attorneyprovider_user.FirstName, CurrentUser.FirstName, CurrentCompany.Name, VarificationLink1); BO.Email objEmail1 = new BO.Email { ToEmail = attorneyprovider_user.UserName, Subject = subject1, Body = message1 }; objEmail1.SendMail(); #endregion } } } } #endregion } catch (Exception ex) { } } else { #region Send Email var userId = _context.UserCompanies.Where(p => p.CompanyID == prefAttProvider.PrefAttorneyProviderId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).Select(p2 => p2.UserID).ToList(); var userBO = _context.Users.Where(p => userId.Contains(p.id) && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault(); if (userBO != null) { var mailTemplateDB = _context.MailTemplates.Where(x => x.TemplateName.ToUpper() == "PrefAttorneyProviderUpdated".ToUpper()).FirstOrDefault(); if (mailTemplateDB == null) { return(new BO.ErrorObject { ErrorMessage = "No record found Mail Template.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } else { //string VerificationLink = "<a href='" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "' target='_blank'>" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "</a>"; string LoginLink2 = "<a href='http://www.patient.codearray.tk/#/account/login'>http://www.patient.codearray.tk/#/account/login </a>"; string msg = mailTemplateDB.EmailBody; string subject = mailTemplateDB.EmailSubject; string message = string.Format(msg, userBO.FirstName, userBO.UserName, LoginLink2); BO.Email objEmail = new BO.Email { ToEmail = userBO.UserName, Subject = subject, Body = message }; objEmail.SendMail(); } } #endregion } var result = _context.PreferredAttorneyProviders.Include("Company").Include("Company1") .Where(p => p.Id == prefAttProvider.Id && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))) .FirstOrDefault(); BO.PreferredAttorneyProvider acc_ = Convert <BO.PreferredAttorneyProvider, PreferredAttorneyProvider>(result); var res = (BO.GbObject)(object) acc_; return((object)res); }