예제 #1
0
        public override Object RegenerateOTP <T>(T entity)
        {
            BO.OTP otpUser = (BO.OTP)(object) entity;


            var otpOld = _context.OTPs.Where(p => p.UserID == otpUser.User.ID).ToList <OTP>();

            otpOld.ForEach(a => { a.IsDeleted = true; a.UpdateDate = DateTime.UtcNow; a.UpdateByUserID = System.Convert.ToInt32(Utility.GetConfigValue("DefaultAdminUserID")); });
            if (otpOld != null)
            {
                _context.SaveChanges();
            }

            OTP otpDB = new OTP();

            otpDB.OTP1           = Utility.GenerateRandomNumber(6);
            otpDB.Pin            = Utility.GenerateRandomNo();
            otpDB.UserID         = otpUser.User.ID;
            otpDB.CreateDate     = DateTime.UtcNow;
            otpDB.CreateByUserID = System.Convert.ToInt32(Utility.GetConfigValue("DefaultAdminUserID"));

            _dbSet.Add(otpDB);
            _context.SaveChanges();

            BO.OTP acc = Convert <BO.OTP, OTP>(otpDB);

            dynamic data_ = _context.Users.Where(x => x.id == otpUser.User.ID && (x.IsDeleted == null || x.IsDeleted == false)).FirstOrDefault();

            BO.User acc_    = Convert <BO.User, User>(data_);
            string  Message = "Dear " + acc_.UserName + ",<br><br>As per your request, a One Time Password (OTP) has been generated and the same is <i><b>" + otpDB.OTP1.ToString() + "</b></i><br><br>Please use this OTP to complete the Login. Reference number is " + otpDB.Pin.ToString() + " <br><br>*** This is an auto-generated email. Please do not reply to this email.*** <br><br>Thanks";

            try
            {
                BO.Email objEmail = new BO.Email {
                    ToEmail = acc_.UserName, Subject = "Alert Message From GBX MIDAS", Body = Message
                };
                objEmail.SendMail();
            }
            catch (Exception ex)
            {
                return(acc);
            }

            return(Convert <BO.OTP, OTP>(otpDB));
        }
예제 #2
0
        public override Object GeneratePasswordLink <T>(T entity)
        {
            BO.PasswordToken passwordBO = (BO.PasswordToken)(object) entity;

            dynamic data_ = _context.Users.Where(x => x.UserName == passwordBO.UserName).FirstOrDefault();

            if (data_ == null)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "No record found for this user.", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }

            PasswordToken passwordDB = new PasswordToken();

            passwordDB.TokenHash      = Guid.NewGuid();
            passwordDB.UserName       = passwordBO.UserName;
            passwordDB.CreateDate     = DateTime.UtcNow;
            passwordDB.CreateByUserID = System.Convert.ToInt32(Utility.GetConfigValue("DefaultAdminUserID"));

            _dbSet.Add(passwordDB);
            _context.SaveChanges();

            BO.PasswordToken acc = Convert <BO.PasswordToken, PasswordToken>(passwordDB);

            string Message = "Dear " + passwordBO.UserName + ",<br><br>You are receiving this email because you (or someone pretending to be you) requested that your password be reset on the " + Utility.GetConfigValue("Website") + " site.  If you do not wish to reset your password, please ignore this message.<br><br>To reset your password, please click the following link, or copy and paste it into your web browser:<br><br>" + Utility.GetConfigValue("ForgotPasswordLink") + "/" + passwordDB.TokenHash + " <br><br>Your username, in case you've forgotten: " + passwordDB.UserName + "<br><br>Thanks";

            try
            {
                BO.Email objEmail = new BO.Email {
                    ToEmail = passwordBO.UserName, Subject = "Password Reset on MIDAS GBX", Body = Message
                };
                objEmail.SendMail();
            }
            catch (Exception ex)
            {
                return(acc);
            }

            return(acc);
        }
예제 #3
0
        public override Object UpdateCompany <T>(T data)
        {
            BO.Signup signUPBO = (BO.Signup)(object) data;

            BO.User        userBO                = signUPBO.user;
            BO.Company     companyBO             = signUPBO.company;
            BO.AddressInfo addressBO             = signUPBO.addressInfo;
            BO.ContactInfo contactinfoBO         = signUPBO.contactInfo;
            BO.Role        roleBO                = signUPBO.role;
            Guid           invitationDB_UniqueID = Guid.NewGuid();

            Company         companyDB         = new Company();
            User            userDB            = new User();
            AddressInfo     addressDB         = new AddressInfo();
            ContactInfo     contactinfoDB     = new ContactInfo();
            UserCompany     userCompanyDB     = new UserCompany();
            UserCompanyRole userCompanyRoleDB = new UserCompanyRole();
            Invitation      invitationDB      = new Invitation();

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                if (signUPBO == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                if (signUPBO.company == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                if (signUPBO.user == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                if (signUPBO.contactInfo == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                #region Company

                companyDB = _context.Companies.Where(p => p.id == companyBO.ID &&
                                                     (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                            .FirstOrDefault();

                if (companyDB == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "Company Record Not Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                companyDB.TaxID = companyBO.TaxID;

                if (companyBO.SubsCriptionType != null)
                {
                    companyDB.SubscriptionPlanType = (int)companyBO.SubsCriptionType;
                }
                else
                {
                    companyDB.SubscriptionPlanType = null;
                }

                companyDB.CompanyStatusTypeID = 2; // CompanyStatusTypeID = 2 --- RegistrationComplete

                _context.SaveChanges();


                #endregion

                #region contactInfo
                contactinfoDB = _context.ContactInfoes.Where(p => p.id == contactinfoBO.ID &&
                                                             (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                .FirstOrDefault();

                if (contactinfoDB == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "Contact Record Not Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                contactinfoDB.CellPhone = contactinfoBO.CellPhone;

                _context.SaveChanges();

                #endregion

                #region User
                userDB = _context.Users.Where(p => p.id == userBO.ID &&
                                              (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                         .FirstOrDefault();

                if (userDB == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "User Record Not Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                userDB.FirstName = userBO.FirstName;
                userDB.LastName  = userBO.LastName;
                userDB.C2FactAuthEmailEnabled = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactEmail"));
                userDB.C2FactAuthSMSEnabled   = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactSMS"));

                #region password

                BO.ResetPassword resetPassword = new BO.ResetPassword();
                resetPassword.OldPassword = userDB.Password;
                //if (userDB != null)
                //{
                //        resetPassword.NewPassword = PasswordHash.HashPassword(userBO.Password);
                //        userDB.Password = resetPassword.NewPassword;
                // }
                if (userDB != null)
                {
                    if (companyDB.CompanyStatusTypeID == 2) //CompanyStatusTypeID == 2 --- Registration Complete
                    {
                        resetPassword.NewPassword     = PasswordHash.HashPassword(userBO.Password);
                        userDB.Password               = resetPassword.NewPassword;
                        companyDB.CompanyStatusTypeID = 3; //CompanyStatusTypeID = 3 --- Active
                    }
                }
                #endregion

                _context.SaveChanges();

                userDB = _context.Users.Where(p => p.id == userBO.ID &&
                                              (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                         .FirstOrDefault();

                #endregion

                dbContextTransaction.Commit();
            }

            BO.Company acc_ = Convert <BO.Company, Company>(companyDB);

            try
            {
                if (userDB != null)
                {
                    var updateCompany = _context.MailTemplates.Where(x => x.TemplateName.ToUpper() == "CompanyUpdated".ToUpper()).FirstOrDefault();

                    if (updateCompany == null)
                    {
                        return(new BO.ErrorObject {
                            ErrorMessage = "No record found Mail Template.", errorObject = "", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    else
                    {
                        #region Send mail to attorney
                        string msg1     = updateCompany.EmailBody;
                        string subject1 = updateCompany.EmailSubject;

                        string message1 = string.Format(msg1, userDB.FirstName);

                        BO.Email objEmail1 = new BO.Email {
                            ToEmail = userDB.UserName, Subject = subject1, Body = message1
                        };
                        objEmail1.SendMail();
                        #endregion
                    }
                }
            }
            catch (Exception ex) { }

            var res = (BO.GbObject)(object) acc_;
            return((object)res);
        }
예제 #4
0
        public override Object Signup <T>(T data)
        {
            BO.Signup signUPBO = (BO.Signup)(object) data;

            bool flagUser = false;

            BO.User        userBO        = signUPBO.user;
            BO.Company     companyBO     = signUPBO.company;
            BO.AddressInfo addressBO     = signUPBO.addressInfo;
            BO.ContactInfo contactinfoBO = signUPBO.contactInfo;
            BO.Role        roleBO        = signUPBO.role;

            Company         companyDB         = new Company();
            User            userDB            = new User();
            AddressInfo     addressDB         = new AddressInfo();
            ContactInfo     contactinfoDB     = new ContactInfo();
            UserCompany     userCompanyDB     = new UserCompany();
            UserCompanyRole userCompanyRoleDB = new UserCompanyRole();
            Invitation      invitationDB      = new Invitation();

            if (string.IsNullOrEmpty(companyBO.TaxID) == false && _context.Companies.Any(o => o.TaxID == companyBO.TaxID))
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "TaxID already exists.", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }

            if (_context.Companies.Any(o => o.Name == companyBO.Name))
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "Company already exists.", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }
            else if (_context.Users.Any(o => o.UserName == userBO.UserName))
            {
                flagUser = true;
            }

            #region Company

            companyDB.Name        = companyBO.Name;
            companyDB.id          = companyBO.ID;
            companyDB.TaxID       = companyBO.TaxID;
            companyDB.Status      = System.Convert.ToByte(companyBO.Status);
            companyDB.CompanyType = System.Convert.ToByte(companyBO.CompanyType);
            if (companyBO.SubsCriptionType.HasValue == true)
            {
                companyDB.SubscriptionPlanType = System.Convert.ToInt16(companyBO.SubsCriptionType);
            }
            else
            {
                companyDB.SubscriptionPlanType = null;
            }
            companyDB.CompanyStatusTypeID = 2; // CompanyStatusTypeID = 2 --- RegistrationComplete
            companyDB.BlobStorageTypeId   = 1;

            if (companyDB.IsDeleted.HasValue)
            {
                companyDB.IsDeleted = companyBO.IsDeleted.Value;
            }

            #endregion

            #region Address
            if (addressBO != null)
            {
                addressDB.id       = addressBO.ID;
                addressDB.Name     = addressBO.Name;
                addressDB.Address1 = addressBO.Address1;
                addressDB.Address2 = addressBO.Address2;
                addressDB.City     = addressBO.City;
                addressDB.State    = addressBO.State;
                addressDB.ZipCode  = addressBO.ZipCode;
                addressDB.Country  = addressBO.Country;
            }
            #endregion

            #region Contact Info

            if (contactinfoBO != null)
            {
                contactinfoDB.id           = contactinfoBO.ID;
                contactinfoDB.Name         = contactinfoBO.Name;
                contactinfoDB.CellPhone    = contactinfoBO.CellPhone;
                contactinfoDB.EmailAddress = contactinfoBO.EmailAddress;
                contactinfoDB.HomePhone    = contactinfoBO.HomePhone;
                contactinfoDB.WorkPhone    = contactinfoBO.WorkPhone;
                contactinfoDB.FaxNo        = contactinfoBO.FaxNo;
                if (contactinfoBO.IsDeleted.HasValue)
                {
                    contactinfoDB.IsDeleted = contactinfoBO.IsDeleted;
                }
            }
            #endregion

            #region User
            if (!flagUser)
            {
                userDB.UserName               = userBO.UserName;
                userDB.MiddleName             = userBO.MiddleName;
                userDB.FirstName              = userBO.FirstName;
                userDB.LastName               = userBO.LastName;
                userDB.Gender                 = System.Convert.ToByte(userBO.Gender);
                userDB.UserType               = System.Convert.ToByte(userBO.UserType);
                userDB.C2FactAuthEmailEnabled = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactEmail"));
                userDB.C2FactAuthSMSEnabled   = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactSMS"));
                userDB.ImageLink              = userBO.ImageLink;
                if (userBO.DateOfBirth.HasValue)
                {
                    userDB.DateOfBirth = userBO.DateOfBirth.Value;
                }

                if (userBO.IsDeleted.HasValue)
                {
                    userDB.IsDeleted = userBO.IsDeleted.Value;
                }

                userDB.AddressInfo       = addressDB;
                userDB.ContactInfo       = contactinfoDB;
                userCompanyDB.User       = userDB;
                userCompanyDB.IsAccepted = true;
            }
            else
            {
                //Find Record By Name
                User user_ = _context.Users.Where(p => p.UserName == userBO.UserName).FirstOrDefault <User>();
                userCompanyDB.User          = user_;
                userCompanyDB.IsAccepted    = true;
                _context.Entry(user_).State = System.Data.Entity.EntityState.Modified;
            }

            #endregion

            UserCompany cmp = new UserCompany();
            cmp.Company = companyDB;

            companyDB.AddressInfo = addressDB;
            companyDB.ContactInfo = contactinfoDB;

            if (companyDB.id > 0)
            {
                //For Update Record
            }
            else
            {
                companyDB.CreateDate     = companyBO.CreateDate;
                companyDB.CreateByUserID = companyBO.CreateByUserID;

                userDB.CreateDate     = companyBO.CreateDate;
                userDB.CreateByUserID = companyBO.CreateByUserID;

                addressDB.CreateDate     = companyBO.CreateDate;
                addressDB.CreateByUserID = companyBO.CreateByUserID;

                contactinfoDB.CreateDate     = companyBO.CreateDate;
                contactinfoDB.CreateByUserID = companyBO.CreateByUserID;

                _dbSet.Add(companyDB);
            }
            _context.SaveChanges();

            #region Insert User Block
            userCompanyDB.IsAccepted     = true;
            userCompanyDB.Company        = companyDB;
            userCompanyDB.UserStatusID   = 1; //UserStatusID = 1 --- UserStatus Pending
            userCompanyDB.CreateDate     = companyBO.CreateDate;
            userCompanyDB.CreateByUserID = companyBO.CreateByUserID;
            _dbUserCompany.Add(userCompanyDB);
            _context.SaveChanges();
            #endregion

            #region Insert User Company Role
            userCompanyRoleDB.User           = userCompanyDB.User;
            userCompanyRoleDB.RoleID         = (int)roleBO.RoleType;
            userCompanyRoleDB.CreateDate     = companyBO.CreateDate;
            userCompanyRoleDB.CreateByUserID = companyBO.CreateByUserID;
            _dbUserCompanyRole.Add(userCompanyRoleDB);
            _context.SaveChanges();
            #endregion

            #region Insert Invitation
            invitationDB.User           = userCompanyDB.User;
            invitationDB.Company        = companyDB;
            invitationDB.UniqueID       = Guid.NewGuid();
            invitationDB.CreateDate     = companyBO.CreateDate;
            invitationDB.CreateByUserID = companyBO.CreateByUserID;
            _dbInvitation.Add(invitationDB);
            _context.SaveChanges();
            #endregion

            #region Update referral
            //var referral = _context.Referrals.Where(p => p.ReferredToEmail == userDB.UserName && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).ToList<Referral>();

            //foreach (var eachReferral in referral)
            //{
            //    eachReferral.ReferredToCompanyId = companyDB.id;
            //    eachReferral.ReferralAccepted = true;
            //}

            _context.SaveChanges();
            #endregion

            BO.Company acc_ = Convert <BO.Company, Company>(companyDB);
            try
            {
                #region Send Email

                string   VerificationLink = "<a href='" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB.UniqueID + "' target='_blank'>" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB.UniqueID + "</a>";
                string   Message          = "Dear " + userBO.FirstName + ",<br><br>Thanks for registering with us.<br><br> Your user name is:- " + userBO.UserName + "<br><br> Please confirm your account by clicking below link in order to use.<br><br><b>" + VerificationLink + "</b><br><br>Thanks";
                BO.Email objEmail         = new BO.Email {
                    ToEmail = userBO.UserName, Subject = "Company registered", Body = Message
                };
                objEmail.SendMail();
                #endregion
            }
            catch (Exception ex)
            {
                //Message sending failed
            }

            var res = (BO.GbObject)(object) acc_;
            return((object)res);
        }
예제 #5
0
        public override object UpdateAttorneyProvider <T>(T entity)
        {
            BO.PreferredAttorneyProviderSignUp preferredÀttorneyProviderBO = (BO.PreferredAttorneyProviderSignUp)(object) entity;
            PreferredAttorneyProvider          preferredAttorneyProviderDB = new PreferredAttorneyProvider();

            BO.Signup prefAttProviderBO = preferredÀttorneyProviderBO.Signup;
            //BO.Company company = preferredÀttorneyProviderBO.Company;
            PreferredAttorneyProvider prefAttProvider = new PreferredAttorneyProvider();

            Guid    invitationDB_UniqueID = Guid.NewGuid();
            User    userDB = new User();
            Company prefAttProvider_CompanyDB = new Company();

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                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.id != prefAttProviderBO.company.ID
                //    && (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.id != prefAttProviderBO.company.ID &&
                                           (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.id != prefAttProviderBO.user.ID &&
                                            (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;

                prefAttProvider_CompanyDB = _context.Companies.Where(p => p.id == prefAttProviderCompanyBO.ID &&
                                                                     (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                            .FirstOrDefault();

                if (prefAttProvider_CompanyDB == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "Company Record Not Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                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 = prefAttProviderCompanyBO.AddressInfo.ID;
                prefAttProvider_CompanyDB.ContactInfoID       = ContactInfoBO.ID;
                prefAttProvider_CompanyDB.CompanyStatusTypeID = System.Convert.ToByte(prefAttProviderCompanyBO.CompanyStatusTypeID);
                prefAttProvider_CompanyDB.IsDeleted           = false;
                prefAttProvider_CompanyDB.UpdateByUserID      = 0;
                prefAttProvider_CompanyDB.UpdateDate          = DateTime.UtcNow;

                _context.SaveChanges();


                ContactInfo ContactInfo = _context.ContactInfoes.Where(p => p.id == ContactInfoBO.ID &&
                                                                       (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                          .FirstOrDefault();

                if (ContactInfo == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "Contact Record Not Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                ContactInfo.CellPhone    = ContactInfoBO.CellPhone;
                ContactInfo.EmailAddress = ContactInfoBO.EmailAddress;

                _context.SaveChanges();


                userDB = _context.Users.Where(p => p.id == userBO.ID &&
                                              (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                         .FirstOrDefault();

                if (userDB == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "User Record Not Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                userDB.FirstName = userBO.FirstName;
                userDB.LastName  = userBO.LastName;
                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 = 0;
                userDB.CreateDate     = DateTime.UtcNow;

                _context.SaveChanges();

                prefAttProvider.PrefAttorneyProviderId = prefAttProviderBO.company.ID;
                prefAttProvider.CompanyId      = preferredÀttorneyProviderBO.CompanyId;
                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();
            }

            try
            {
                #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();

                //var userBO = _context.Users.Where(p => p.id == caseDB.AttorneyId && (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
                    {
                        #region Insert Invitation
                        Invitation invitationDB = new Invitation();
                        invitationDB.User = userDB;

                        invitationDB_UniqueID       = Guid.NewGuid();
                        invitationDB.UniqueID       = invitationDB_UniqueID;
                        invitationDB.CompanyID      = prefAttProvider_CompanyDB.id != 0 ? prefAttProvider_CompanyDB.id : 0;
                        invitationDB.CreateDate     = DateTime.UtcNow;
                        invitationDB.CreateByUserID = userDB.id;
                        _context.Invitations.Add(invitationDB);
                        _context.SaveChanges();
                        #endregion

                        //string VerificationLink = "<a href='http://medicalprovider.codearray.tk/#/account/login'> http://medicalprovider.codearray.tk/#/account/login </a>";
                        string VerificationLink = "<a href='http://attorney.codearray.tk/#/account/login'> http://attorney.codearray.tk/#/account/login </a>";
                        string msg     = mailTemplateDB.EmailBody;
                        string subject = mailTemplateDB.EmailSubject;

                        string message = string.Format(msg, userBO.FirstName, userBO.UserName, VerificationLink);

                        BO.Email objEmail = new BO.Email {
                            ToEmail = userBO.UserName, Subject = subject, Body = message
                        };
                        objEmail.SendMail();
                    }
                }

                #endregion
            }
            catch (Exception ex) { }

            var result = _context.PreferredAttorneyProviders.Include("Company").Include("Company1")
                         .Where(p => p.PrefAttorneyProviderId == prefAttProviderBO.company.ID &&
                                (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                         .FirstOrDefault();

            BO.PreferredAttorneyProviderSignUp acc_ = ConvertPreferredAttorneyProviderSignUp <BO.PreferredAttorneyProviderSignUp, PreferredAttorneyProvider>(result);

            var res = (BO.GbObject)(object) acc_;
            return((object)res);
        }
예제 #6
0
        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);
        }
예제 #7
0
        public override object AssociateUserToCompany(string UserName, int CompanyId, bool sendEmail)
        {
            User UserDB = _context.Users.Where(p => p.UserName == UserName &&
                                               (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                          .FirstOrDefault();

            if (UserDB == null)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "User dosent exists.", errorObject = "", ErrorLevel = ErrorLevel.Information
                });
            }

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

            UserCompany UserCompanyDB1 = _context.UserCompanies.Where(p => (p.UserID == UserDB.id && p.CompanyID == CompanyId && p.IsAccepted == true) &&
                                                                      (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                         .FirstOrDefault();

            if (UserCompanyDB1 == null)
            {
                UserCompany UserCompanyDB = new UserCompany();

                Guid invitationDB_UniqueID = Guid.NewGuid();

                using (var dbContextTransaction = _context.Database.BeginTransaction())
                {
                    if (UserDB != null && CompanyDB != null)
                    {
                        UserCompanyDB.UserID         = UserDB.id;
                        UserCompanyDB.CompanyID      = CompanyDB.id;
                        UserCompanyDB.IsAccepted     = true;
                        UserCompanyDB.IsDeleted      = false;
                        UserCompanyDB.CreateByUserID = 0;
                        UserCompanyDB.CreateDate     = DateTime.UtcNow;

                        UserCompanyDB = _context.UserCompanies.Add(UserCompanyDB);

                        _context.SaveChanges();

                        if (sendEmail == true)
                        {
                            #region Insert Invitation
                            Invitation invitationDB = new Invitation();
                            invitationDB.User     = UserCompanyDB.User;
                            invitationDB_UniqueID = Guid.NewGuid();

                            invitationDB.UniqueID       = invitationDB_UniqueID;
                            invitationDB.CompanyID      = UserCompanyDB.CompanyID;
                            invitationDB.CreateDate     = DateTime.UtcNow;
                            invitationDB.CreateByUserID = UserCompanyDB.CreateByUserID;

                            _context.Invitations.Add(invitationDB);

                            _context.SaveChanges();
                            #endregion
                        }
                    }
                    else
                    {
                        return(new BO.ErrorObject {
                            ErrorMessage = "Please pass valid user and company details.", errorObject = "", ErrorLevel = ErrorLevel.Information
                        });
                    }

                    dbContextTransaction.Commit();

                    UserDB = _context.Users.Include("AddressInfo")
                             .Include("ContactInfo")
                             .Include("UserCompanyRoles")
                             .Include("UserCompanies")
                             .Where(p => p.id == UserDB.id &&
                                    (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                             .FirstOrDefault <User>();
                }

                if (sendEmail == true)
                {
                    try
                    {
                        #region Send Email
                        string   VerificationLink = "<a href='" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "' target='_blank'>" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "</a>";
                        string   Message          = "Dear " + UserDB.FirstName + ",<br><br>Thanks for registering with us.<br><br> Your user name is:- " + UserDB.UserName + "<br><br> Please confirm your account by clicking below link in order to use.<br><br><b>" + VerificationLink + "</b><br><br>Thanks";
                        BO.Email objEmail         = new BO.Email {
                            ToEmail = UserDB.UserName, Subject = "User registered", Body = Message
                        };
                        objEmail.SendMail();
                        #endregion
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            else
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "User is already  associated with this Company.", errorObject = "", ErrorLevel = ErrorLevel.Information
                });
            }

            var res = Convert <BO.User, User>(UserDB);
            return((object)res);
        }
예제 #8
0
        public override object AssociateDoctorWithCompany(int DoctorId, int CompanyId)
        {
            bool add_UserCompany       = false;
            bool sendEmail             = false;
            Guid invitationDB_UniqueID = Guid.NewGuid();

            var company = _context.Companies.Where(p => p.id == CompanyId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault();

            if (company == null)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "No record found for this Company.", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }

            var Doctor = _context.Doctors.Where(p => p.Id == DoctorId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault();

            if (Doctor == null)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "No record found for this Doctor.", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }

            var userCompany = _context.UserCompanies.Where(p => p.UserID == DoctorId && p.CompanyID == CompanyId && p.IsAccepted == true && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault();

            if (userCompany == null)
            {
                userCompany     = new UserCompany();
                add_UserCompany = true;
                sendEmail       = true;
            }

            userCompany.CompanyID    = CompanyId;
            userCompany.UserID       = DoctorId;
            userCompany.UserStatusID = 1;
            userCompany.IsAccepted   = true;

            if (add_UserCompany)
            {
                _context.UserCompanies.Add(userCompany);
            }

            _context.SaveChanges();

            var doctorDB = _context.Doctors.Include("User")
                           .Include("User.AddressInfo")
                           .Include("User.ContactInfo")
                           .Include("DoctorSpecialities")
                           .Include("DoctorSpecialities.Specialty")
                           .Include("User.UserCompanyRoles")
                           .Include("User.UserCompanies")
                           .Where(p => p.Id == DoctorId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault <Doctor>();

            #region Send Email
            if (sendEmail == true)
            {
                try
                {
                    string   VerificationLink = "<a href='" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "' target='_blank'>" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "</a>";
                    string   Message          = "Dear " + doctorDB.User.FirstName + ",<br><br>Thanks for registering with us.<br><br> Your user name is:- " + doctorDB.User.UserName + "<br><br> Please confirm your account by clicking below link in order to use.<br><br><b>" + VerificationLink + "</b><br><br>Thanks";
                    BO.Email objEmail         = new BO.Email {
                        ToEmail = doctorDB.User.UserName, Subject = "User registered", Body = Message
                    };
                    objEmail.SendMail();
                }
                catch (Exception ex) { }
            }
            #endregion

            var res = Convert <BO.Doctor, Doctor>(doctorDB);
            return((object)res);
        }