예제 #1
0
        public override T Convert <T, U>(U entity)
        {
            if (entity.GetType().Name == "User")
            {
                User user_ = entity as User;
                if (user_ == null)
                {
                    return(default(T));
                }

                BO.User boUser = new BO.User();

                boUser.UserName       = user_.UserName;
                boUser.ID             = user_.id;
                boUser.FirstName      = user_.FirstName;
                boUser.LastName       = user_.LastName;
                boUser.ImageLink      = user_.ImageLink;
                boUser.UserType       = (BO.GBEnums.UserType)user_.UserType;
                boUser.Gender         = (BO.GBEnums.Gender)user_.UserType;
                boUser.CreateByUserID = user_.CreateByUserID;
                return((T)(object)boUser);
            }
            OTP user = entity as OTP;

            if (user == null)
            {
                return(default(T));
            }

            BO.OTP boOTP = new BO.OTP();
            boOTP.Pin = user.Pin;

            return((T)(object)boOTP);
        }
예제 #2
0
        public override T Convert <T, U>(U entity)
        {
            if (entity.GetType().Name == "Invitation")
            {
                BO.User    boUser     = new BO.User();
                Invitation invitation = entity as Invitation;
                if (invitation == null)
                {
                    return(default(T));
                }

                BO.Invitation boInvitation = new BO.Invitation();
                boUser.ID = invitation.UserID;
                boInvitation.InvitationID = invitation.InvitationID;
                boInvitation.User         = boUser;
                return((T)(object)boInvitation);
            }
            else
            {
                Company company = entity as Company;
                if (company == null)
                {
                    return(default(T));
                }

                BO.Company boCompany = new BO.Company();

                boCompany.ID          = company.id;
                boCompany.Name        = company.Name;
                boCompany.TaxID       = company.TaxID == null ? null : company.TaxID;
                boCompany.Status      = (BO.GBEnums.AccountStatus)company.Status;
                boCompany.CompanyType = (BO.GBEnums.CompanyType)company.CompanyType;
                if (company.SubscriptionPlanType != null)
                {
                    boCompany.SubsCriptionType = (BO.GBEnums.SubsCriptionType)company.SubscriptionPlanType;
                }
                else
                {
                    boCompany.SubsCriptionType = null;
                }
                boCompany.CompanyStatusTypeID = (BO.GBEnums.CompanyStatusType)company.CompanyStatusTypeID;

                if (company.Locations != null)
                {
                    List <BO.Location> lstLocation = new List <BO.Location>();
                    foreach (var item in company.Locations)
                    {
                        using (LocationRepository sr = new LocationRepository(_context))
                        {
                            BO.Location location = sr.Convert <BO.Location, Location>(item);
                            location.Company = null;
                            lstLocation.Add(location);
                        }
                    }

                    boCompany.Locations = lstLocation;
                }
                return((T)(object)boCompany);
            }
        }
예제 #3
0
        public override T Convert <T, U>(U entity)
        {
            BO.User    boUser     = new BO.User();
            BO.Company boCompany  = new BO.Company();
            Invitation invitation = entity as Invitation;

            if (invitation == null)
            {
                return(default(T));
            }

            BO.Invitation boInvitation = new BO.Invitation();
            boUser.ID = invitation.UserID;
            boInvitation.InvitationID = invitation.InvitationID;
            boInvitation.User         = boUser;

            if (invitation.User.UserCompanies != null && invitation.User.UserCompanies.Count > 0)
            {
                List <BO.UserCompany> boUserCompany = new List <BO.UserCompany>();
                invitation.User.UserCompanies.Where(p => p.IsAccepted == true && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                .ToList().ForEach(x => boUserCompany.Add(new BO.UserCompany()
                {
                    CompanyId = x.CompanyID, UserId = x.UserID, UserStatusID = (BO.GBEnums.UserStatu)x.UserStatusID, CreateByUserID = x.CreateByUserID, ID = x.id, IsDeleted = x.IsDeleted, UpdateByUserID = x.UpdateByUserID
                }));
                boInvitation.User.UserCompanies = boUserCompany;
            }



            boCompany.ID         = invitation.CompanyID;
            boInvitation.Company = boCompany;

            return((T)(object)boInvitation);
        }
예제 #4
0
        public override List <MIDAS.GBX.BusinessObjects.BusinessValidation> Validate <T>(T entity)
        {
            BO.Signup  signUPBO  = (BO.Signup)(object) entity;
            BO.Company companyBO = signUPBO.company;
            BO.User    userBO    = signUPBO.user;


            var result = companyBO.Validate(companyBO);

            return(result);
        }
예제 #5
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));
        }
예제 #6
0
        public override Object ValidateOTP <T>(T entity)
        {
            BO.ValidateOTP validateOTP = (BO.ValidateOTP)(object) entity;


            BO.OTP  otpBO  = validateOTP.otp;
            BO.User userBO = validateOTP.user;

            OTP data_ = _context.OTPs.Where(x => x.OTP1 == otpBO.OTP1 && x.Pin == otpBO.Pin && (x.IsDeleted != true) && x.UserID == userBO.ID).FirstOrDefault();

            if (data_ == null)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "Invalid OTP", errorObject = "", ErrorLevel = ErrorLevel.Information
                });
            }
            else
            {
                BO.OTP acc_  = Convert <BO.OTP, OTP>(data_);
                User   _user = _context.Users.Where(p => p.id == data_.UserID).FirstOrDefault();
                if ((BO.GBEnums.UserType)_user.UserType == BO.GBEnums.UserType.Staff)
                {
                    using (UserCompanyRepository sr = new UserCompanyRepository(_context))
                    {
                        //acc_.company = ((BO.UserCompany)sr.Get(userBO.ID)).Company;
                        //acc_.User = ((BO.UserCompany)sr.Get(userBO.ID)).User;
                        var userCompany = ((BO.UserCompany)sr.GetByUserId(userBO.ID));
                        if (userCompany != null)
                        {
                            acc_.company = userCompany.Company;
                            acc_.User    = userCompany.User;
                        }
                    }
                }
                else
                {
                    using (UserRepository userRep = new UserRepository(_context))
                    {
                        acc_.User = ((BO.User)userRep.Get(userBO.ID));
                    }
                }
                return(acc_);
            }
        }
예제 #7
0
        public Object Login2(BO.User user)
        {
            try
            {
                EntityRepository.UserRepository userRepo = new EntityRepository.UserRepository(dbContextProvider.GetGbDBContext());

                var gbdata = userRepo.Login2(user);
                return(gbdata);
            }

            catch (GbException gbe)
            {
                //LogManager.LogErrorMessage(gbe.Message, 0, (GbObject)(object)(entity));
                throw;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public override T Convert <T, U>(U entity)
        {
            UserPersonalSetting userPersonalSetting = entity as UserPersonalSetting;

            if (userPersonalSetting == null)
            {
                return(default(T));
            }

            BO.UserPersonalSetting userPersonalSettingBO = new BO.UserPersonalSetting();

            userPersonalSettingBO.ID                           = userPersonalSetting.Id;
            userPersonalSettingBO.UserId                       = userPersonalSetting.UserId;
            userPersonalSettingBO.CompanyId                    = userPersonalSetting.CompanyId;
            userPersonalSettingBO.IsPublic                     = userPersonalSetting.IsPublic;
            userPersonalSettingBO.IsSearchable                 = userPersonalSetting.IsSearchable;
            userPersonalSettingBO.IsCalendarPublic             = userPersonalSetting.IsCalendarPublic;
            userPersonalSettingBO.SlotDuration                 = userPersonalSetting.SlotDuration;
            userPersonalSettingBO.PreferredModeOfCommunication = userPersonalSetting.PreferredModeOfCommunication;
            userPersonalSettingBO.IsPushNotificationEnabled    = userPersonalSetting.IsPushNotificationEnabled;
            userPersonalSettingBO.IsDeleted                    = userPersonalSetting.IsDeleted;
            userPersonalSettingBO.CreateByUserID               = userPersonalSetting.CreateByUserID;
            userPersonalSettingBO.UpdateByUserID               = userPersonalSetting.UpdateByUserID;

            if (userPersonalSetting.User != null)
            {
                if (userPersonalSetting.User.IsDeleted.HasValue == false || (userPersonalSetting.User.IsDeleted.HasValue == true && userPersonalSetting.User.IsDeleted.Value == false))
                {
                    BO.User boUser = new BO.User();
                    using (UserRepository cmp = new UserRepository(_context))
                    {
                        boUser = cmp.Convert <BO.User, User>(userPersonalSetting.User);
                        userPersonalSettingBO.User = boUser;
                    }
                }
            }


            return((T)(object)userPersonalSettingBO);
        }
예제 #9
0
        public override Object ValidatePassword <T>(T entity)
        {
            BO.PasswordToken passwordBO = (BO.PasswordToken)(object) entity;

            PasswordToken data_ = _context.PasswordTokens.Where(x => x.IsTokenUsed != true && x.TokenHash == passwordBO.UniqueID).FirstOrDefault();

            if (data_ != null)
            {
                User usr = _context.Users.Where(x => x.UserName == data_.UserName).FirstOrDefault();

                BO.User userBO = new BO.User {
                    ID = usr.id
                };
                return(userBO);
            }
            else
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "Invalid password link.", errorObject = "", ErrorLevel = ErrorLevel.Information
                });
            }
        }
예제 #10
0
        public override T Convert <T, U>(U entity)
        {
            Doctor doctor = entity as Doctor;

            if (doctor == null)
            {
                return(default(T));
            }

            BO.Doctor doctorBO = new BO.Doctor();

            doctorBO.ID               = doctor.Id;
            doctorBO.LicenseNumber    = doctor.LicenseNumber;
            doctorBO.WCBAuthorization = doctor.WCBAuthorization;
            doctorBO.WcbRatingCode    = doctor.WcbRatingCode;
            doctorBO.NPI              = doctor.NPI;
            doctorBO.Title            = doctor.Title;
            doctorBO.TaxType          = (BO.GBEnums.TaxType)doctor.TaxTypeId;

            if (doctor.IsDeleted.HasValue)
            {
                doctorBO.IsDeleted = doctor.IsDeleted.Value;
            }
            if (doctor.UpdateByUserID.HasValue)
            {
                doctorBO.UpdateByUserID = doctor.UpdateByUserID.Value;
            }

            doctorBO.IsCalendarPublic = doctor.IsCalendarPublic;

            if (doctor.User != null)
            {
                if (doctor.User.IsDeleted.HasValue == false || (doctor.User.IsDeleted.HasValue == true && doctor.User.IsDeleted.Value == false))
                {
                    BO.User boUser = new BO.User();
                    using (UserRepository sr = new UserRepository(_context))
                    {
                        boUser        = sr.Convert <BO.User, User>(doctor.User);
                        doctorBO.user = boUser;
                    }

                    if (doctor.DoctorSpecialities != null)
                    {
                        List <BO.DoctorSpeciality> lstDoctorSpecility = new List <BO.DoctorSpeciality>();
                        foreach (var item in doctor.DoctorSpecialities)
                        {
                            if (item.IsDeleted == false)
                            {
                                using (DoctorSpecialityRepository sr = new DoctorSpecialityRepository(_context))
                                {
                                    lstDoctorSpecility.Add(sr.ObjectConvert <BO.DoctorSpeciality, DoctorSpeciality>(item));
                                }
                            }
                        }
                        doctorBO.DoctorSpecialities = lstDoctorSpecility;
                    }

                    if (doctor.DoctorRoomTestMappings != null)
                    {
                        List <BO.DoctorRoomTestMapping> lstDoctorRoomTestMapping = new List <BO.DoctorRoomTestMapping>();
                        foreach (var item in doctor.DoctorRoomTestMappings)
                        {
                            if (item.IsDeleted == false)
                            {
                                BO.DoctorRoomTestMapping doctorRoomTestMappingBO = new BO.DoctorRoomTestMapping();
                                doctorRoomTestMappingBO.ID        = item.Id;
                                doctorRoomTestMappingBO.IsDeleted = item.IsDeleted;
                                if (doctorRoomTestMappingBO.UpdateByUserID.HasValue)
                                {
                                    doctorRoomTestMappingBO.UpdateByUserID = item.UpdateByUserID.Value;
                                }

                                if (item.RoomTest != null && (item.RoomTest.IsDeleted.HasValue == false || (item.RoomTest.IsDeleted.HasValue == true && item.RoomTest.IsDeleted.Value == false)))
                                {
                                    BO.RoomTest boRoomTest = new BO.RoomTest();
                                    using (RoomTestRepository sr = new RoomTestRepository(_context))
                                    {
                                        boRoomTest = sr.Convert <BO.RoomTest, RoomTest>(item.RoomTest);
                                        doctorRoomTestMappingBO.RoomTest = boRoomTest;
                                    }
                                }
                                lstDoctorRoomTestMapping.Add(doctorRoomTestMappingBO);
                            }
                        }
                        doctorBO.DoctorRoomTestMappings = lstDoctorRoomTestMapping;
                    }

                    //if (doctor.User.UserCompanies != null && doctorBO.user.UserCompanies != null && doctorBO.user.UserCompanies.Count <= 0)
                    if (doctor.User.UserCompanies != null)
                    {
                        List <BO.UserCompany> lstUserCompany = new List <BO.UserCompany>();
                        foreach (var item in doctor.User.UserCompanies)
                        {
                            if (item.IsDeleted.HasValue == false || (item.IsDeleted.HasValue == true && item.IsDeleted.Value == false))
                            {
                                using (UserCompanyRepository sr = new UserCompanyRepository(_context))
                                {
                                    BO.UserCompany BOUserCompany = new BO.UserCompany();
                                    BOUserCompany      = sr.Convert <BO.UserCompany, UserCompany>(item);
                                    BOUserCompany.User = null;
                                    lstUserCompany.Add(BOUserCompany);
                                }
                            }
                        }
                        doctorBO.user.UserCompanies = lstUserCompany;
                    }

                    if (doctor.DoctorLocationSchedules != null)
                    {
                        List <BO.DoctorLocationSchedule> lstDoctorLocationSchedule = new List <BO.DoctorLocationSchedule>();
                        foreach (var item in doctor.DoctorLocationSchedules)
                        {
                            if (item.IsDeleted.HasValue == false || (item.IsDeleted.HasValue == true && item.IsDeleted.Value == false))
                            {
                                using (DoctorLocationScheduleRepository sr = new DoctorLocationScheduleRepository(_context))
                                {
                                    BO.DoctorLocationSchedule BODoctorLocationSchedule = new BO.DoctorLocationSchedule();
                                    BODoctorLocationSchedule          = sr.Convert <BO.DoctorLocationSchedule, DoctorLocationSchedule>(item);
                                    BODoctorLocationSchedule.doctor   = null;
                                    BODoctorLocationSchedule.schedule = null;
                                    lstDoctorLocationSchedule.Add(BODoctorLocationSchedule);
                                }
                            }
                        }
                        doctorBO.DoctorLocationSchedules = lstDoctorLocationSchedule;
                    }
                }
            }

            return((T)(object)doctorBO);
        }
예제 #11
0
        public T ConvertUpdateCompanySignUp <T, U>(U entity)
        {
            Company company = entity as Company;

            if (company == null)
            {
                return(default(T));
            }

            BO.UpdateCompany updateCompanyBO = new BO.UpdateCompany();

            updateCompanyBO.Signup = new BO.Signup();
            if (company != null)
            {
                if (company.IsDeleted.HasValue == false || (company.IsDeleted.HasValue == true && company.IsDeleted.Value == false))
                {
                    BO.Company boCompany = new BO.Company();
                    using (CompanyRepository sr = new CompanyRepository(_context))
                    {
                        boCompany = sr.Convert <BO.Company, Company>(company);

                        updateCompanyBO.Signup.company = boCompany;
                    }
                }
            }

            if (company.ContactInfo != null)
            {
                BO.ContactInfo boContactInfo = new BO.ContactInfo();
                boContactInfo.ID           = company.ContactInfo.id;
                boContactInfo.CellPhone    = company.ContactInfo.CellPhone;
                boContactInfo.EmailAddress = company.ContactInfo.EmailAddress;

                updateCompanyBO.Signup.contactInfo = boContactInfo;
            }

            if (company.UserCompanies != null)
            {
                BO.User lstUser = new BO.User();
                if (company.UserCompanies.Count >= 1)
                {
                    var item = company.UserCompanies.FirstOrDefault();

                    if (item.IsDeleted.HasValue == false || (item.IsDeleted.HasValue == true && item.IsDeleted.Value == false))
                    {
                        var userDB = _context.Users.Where(p => p.id == item.UserID && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                     .FirstOrDefault();

                        using (UserRepository sr = new UserRepository(_context))
                        {
                            BO.User BOUser = new BO.User();
                            BOUser = sr.Convert <BO.User, User>(userDB);
                            BOUser.UserCompanies = null;
                            BOUser.ContactInfo   = null;
                            BOUser.AddressInfo   = null;
                            BOUser.Roles         = null;

                            lstUser = BOUser;
                        }
                    }
                }

                updateCompanyBO.Signup.user = lstUser;
            }

            return((T)(object)updateCompanyBO);
        }
예제 #12
0
        public T ConvertPreferredAttorneyProviderSignUp <T, U>(U entity)
        {
            PreferredAttorneyProvider preferredAttorneyProviderr = entity as PreferredAttorneyProvider;

            if (preferredAttorneyProviderr == null)
            {
                return(default(T));
            }

            BO.PreferredAttorneyProviderSignUp PreferredAttorneyProviderSignUpBO = new BO.PreferredAttorneyProviderSignUp();

            PreferredAttorneyProviderSignUpBO.ID = preferredAttorneyProviderr.Id;
            PreferredAttorneyProviderSignUpBO.PrefAttorneyProviderId = preferredAttorneyProviderr.PrefAttorneyProviderId;
            PreferredAttorneyProviderSignUpBO.CompanyId = preferredAttorneyProviderr.CompanyId;
            PreferredAttorneyProviderSignUpBO.IsCreated = preferredAttorneyProviderr.IsCreated;

            PreferredAttorneyProviderSignUpBO.Signup = new BO.Signup();
            if (preferredAttorneyProviderr.Company1 != null)
            {
                if (preferredAttorneyProviderr.Company1.IsDeleted.HasValue == false || (preferredAttorneyProviderr.Company1.IsDeleted.HasValue == true && preferredAttorneyProviderr.Company1.IsDeleted.Value == false))
                {
                    BO.Company boCompany = new BO.Company();
                    using (CompanyRepository sr = new CompanyRepository(_context))
                    {
                        boCompany = sr.Convert <BO.Company, Company>(preferredAttorneyProviderr.Company1);

                        PreferredAttorneyProviderSignUpBO.Signup.company = boCompany;
                    }
                }
            }

            if (preferredAttorneyProviderr.Company1.ContactInfo != null)
            {
                BO.ContactInfo boContactInfo = new BO.ContactInfo();
                boContactInfo.Name                   = preferredAttorneyProviderr.Company1.ContactInfo.Name;
                boContactInfo.CellPhone              = preferredAttorneyProviderr.Company1.ContactInfo.CellPhone;
                boContactInfo.EmailAddress           = preferredAttorneyProviderr.Company1.ContactInfo.EmailAddress;
                boContactInfo.HomePhone              = preferredAttorneyProviderr.Company1.ContactInfo.HomePhone;
                boContactInfo.WorkPhone              = preferredAttorneyProviderr.Company1.ContactInfo.WorkPhone;
                boContactInfo.FaxNo                  = preferredAttorneyProviderr.Company1.ContactInfo.FaxNo;
                boContactInfo.CreateByUserID         = preferredAttorneyProviderr.Company1.ContactInfo.CreateByUserID;
                boContactInfo.ID                     = preferredAttorneyProviderr.Company1.ContactInfo.id;
                boContactInfo.OfficeExtension        = preferredAttorneyProviderr.Company1.ContactInfo.OfficeExtension;
                boContactInfo.AlternateEmail         = preferredAttorneyProviderr.Company1.ContactInfo.AlternateEmail;
                boContactInfo.PreferredCommunication = preferredAttorneyProviderr.Company1.ContactInfo.PreferredCommunication;

                PreferredAttorneyProviderSignUpBO.Signup.contactInfo = boContactInfo;
            }

            if (preferredAttorneyProviderr.Company1.UserCompanies != null)
            {
                BO.User lstUser = new BO.User();
                if (preferredAttorneyProviderr.Company1.UserCompanies.Count >= 1)
                {
                    var item = preferredAttorneyProviderr.Company1.UserCompanies.FirstOrDefault();

                    if (item.IsDeleted.HasValue == false || (item.IsDeleted.HasValue == true && item.IsDeleted.Value == false))
                    {
                        var userDB = _context.Users.Where(p => p.id == item.UserID && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                     .FirstOrDefault();

                        using (UserRepository sr = new UserRepository(_context))
                        {
                            BO.User BOUser = new BO.User();
                            BOUser = sr.Convert <BO.User, User>(userDB);
                            BOUser.UserCompanies = null;
                            BOUser.ContactInfo   = null;
                            BOUser.AddressInfo   = null;
                            BOUser.Roles         = null;

                            lstUser = BOUser;
                        }
                    }
                }

                PreferredAttorneyProviderSignUpBO.Signup.user = lstUser;
            }

            return((T)(object)PreferredAttorneyProviderSignUpBO);
        }
예제 #13
0
        public override T Convert <T, U>(U entity)
        {
            if (entity.GetType().Name != "User")
            {
                UserCompany usercompany = entity as UserCompany;

                if (usercompany == null)
                {
                    return(default(T));
                }

                BO.UserCompany usercompanyBO = new BO.UserCompany();

                usercompanyBO.ID           = usercompany.id;
                usercompanyBO.UserId       = usercompany.UserID;
                usercompanyBO.CompanyId    = usercompany.CompanyID;
                usercompanyBO.UserStatusID = (BO.GBEnums.UserStatu)usercompany.UserStatusID;
                usercompanyBO.IsAccepted   = usercompany.IsAccepted;

                if (usercompany.IsDeleted.HasValue)
                {
                    usercompanyBO.IsDeleted = usercompany.IsDeleted.Value;
                }
                if (usercompany.UpdateByUserID.HasValue)
                {
                    usercompanyBO.UpdateByUserID = usercompany.UpdateByUserID.Value;
                }

                if (usercompany.User != null && (usercompany.User.IsDeleted.HasValue == false || (usercompany.User.IsDeleted.HasValue == true && usercompany.User.IsDeleted.Value == false)))
                {
                    using (UserRepository sr = new UserRepository(_context))
                    {
                        BO.User boUser = sr.Convert <BO.User, User>(usercompany.User);
                        usercompanyBO.User = boUser;
                    }
                }

                if (usercompany.Company != null && (usercompany.Company.IsDeleted.HasValue == false || (usercompany.Company.IsDeleted.HasValue == true && usercompany.Company.IsDeleted.Value == false)))
                {
                    using (CompanyRepository sr = new CompanyRepository(_context))
                    {
                        BO.Company boCompany = sr.Convert <BO.Company, Company>(usercompany.Company);
                        usercompanyBO.Company = boCompany;
                    }
                }

                return((T)(object)usercompanyBO);
            }
            else
            {
                User    userDB = entity as User;
                BO.User boUser = new BO.User();

                if (userDB.IsDeleted.HasValue == false || (userDB.IsDeleted.HasValue == true && userDB.IsDeleted.Value == false))
                {
                    using (UserRepository sr = new UserRepository(_context))
                    {
                        boUser = sr.Convert <BO.User, User>(userDB);
                    }
                }

                if (boUser.UserCompanies == null && userDB.UserCompanies != null)
                {
                    boUser.UserCompanies = new List <BO.UserCompany>();

                    foreach (var eachUserCompany in userDB.UserCompanies)
                    {
                        if (eachUserCompany.IsDeleted.HasValue == false || (eachUserCompany.IsDeleted.HasValue == true && eachUserCompany.IsDeleted.Value == false))
                        {
                            BO.UserCompany usercompanyBO = new BO.UserCompany();

                            usercompanyBO.ID        = eachUserCompany.id;
                            usercompanyBO.UserId    = eachUserCompany.UserID;
                            usercompanyBO.CompanyId = eachUserCompany.CompanyID;

                            usercompanyBO.IsDeleted      = eachUserCompany.IsDeleted;
                            usercompanyBO.CreateByUserID = eachUserCompany.CreateByUserID;
                            usercompanyBO.UpdateByUserID = eachUserCompany.UpdateByUserID;
                            usercompanyBO.IsAccepted     = true;

                            boUser.UserCompanies.Add(usercompanyBO);
                        }
                    }
                }

                return((T)(object)boUser);
            }
        }
예제 #14
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);
        }
예제 #15
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);
        }
예제 #16
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);
        }
예제 #17
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);
        }
예제 #18
0
        public override object Save <T>(T entity)
        {
            BO.Doctor                    doctorBO                 = (BO.Doctor)(object) entity;
            BO.ErrorObject               errObj                   = new BO.ErrorObject();
            BO.User                      userBO                   = new BO.User();
            Doctor                       doctorDB                 = new Doctor();
            User                         userDB                   = new User();
            List <DoctorSpeciality>      lstDoctorSpecility       = new List <DoctorSpeciality>();
            List <DoctorRoomTestMapping> lstDoctorRoomTestMapping = new List <DoctorRoomTestMapping>();

            doctorDB.Id = doctorBO.ID;

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                ////Find Record By ID
                User user_ = _context.Users.Include("UserCompanyRoles").Include("AddressInfo").Include("ContactInfo").Where(p => p.id == doctorBO.user.ID).FirstOrDefault <User>();
                if (user_ != null)
                {
                    BO.AddUser updUserBO = new BO.AddUser();
                    updUserBO.user                        = doctorBO.user;
                    updUserBO.user.UserName               = string.IsNullOrEmpty(user_.UserName) ? user_.UserName : doctorBO.user.UserName;
                    updUserBO.user.FirstName              = string.IsNullOrEmpty(user_.FirstName) ? user_.FirstName : doctorBO.user.FirstName;
                    updUserBO.user.LastName               = string.IsNullOrEmpty(user_.LastName) ? user_.LastName : doctorBO.user.LastName;
                    updUserBO.user.MiddleName             = string.IsNullOrEmpty(user_.MiddleName) ? user_.MiddleName: doctorBO.user.MiddleName;
                    updUserBO.user.Gender                 = doctorBO.user.Gender;
                    updUserBO.user.UserType               = !Enum.IsDefined(typeof(BO.GBEnums.UserType), doctorBO.user.UserType) ? (BO.GBEnums.UserType)user_.UserType : doctorBO.user.UserType;
                    updUserBO.user.ImageLink              = string.IsNullOrEmpty(doctorBO.user.ImageLink) ? user_.ImageLink : doctorBO.user.ImageLink;
                    updUserBO.user.C2FactAuthEmailEnabled = doctorBO.user.C2FactAuthEmailEnabled == true || doctorBO.user.C2FactAuthEmailEnabled == false ? doctorBO.user.C2FactAuthEmailEnabled : (bool)user_.C2FactAuthEmailEnabled;
                    updUserBO.user.C2FactAuthEmailEnabled = doctorBO.user.C2FactAuthSMSEnabled == true || doctorBO.user.C2FactAuthSMSEnabled == false ? doctorBO.user.C2FactAuthSMSEnabled : (bool)user_.C2FactAuthSMSEnabled;
                    updUserBO.user.ID                     = doctorBO.user.ID;
                    updUserBO.user.Roles                  = doctorBO.user.Roles;
                    updUserBO.company                     = doctorBO.user.UserCompanies.ToList().Select(p => p.Company).FirstOrDefault();
                    updUserBO.role                        = doctorBO.user.Roles.ToArray();
                    // if (doctorBO.DoctorSpecialities.Count > 0) updUserBO.DoctorSpecialities = doctorBO.user.DoctorSpecialities;
                    if (doctorBO.user.AddressInfo != null && doctorBO.user.AddressInfo.ID > 0)
                    {
                        updUserBO.address = doctorBO.user.AddressInfo;
                    }
                    if (doctorBO.user.ContactInfo != null && doctorBO.user.ContactInfo.ID > 0)
                    {
                        updUserBO.contactInfo = doctorBO.user.ContactInfo;
                    }
                    using (UserRepository userRepo = new UserRepository(_context))
                    {
                        object obj = userRepo.Save <BO.AddUser>(updUserBO);
                        if (obj.GetType() == errObj.GetType())
                        {
                            errObj = (BO.ErrorObject)obj;
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                ErrorMessage = errObj.ErrorMessage, errorObject = "", ErrorLevel = ErrorLevel.Error
                            });
                        }
                        else
                        {
                            userBO = (BO.User)obj;
                        }
                        doctorDB.User = _context.Users.Include("UserCompanyRoles").Include("UserCompanies").Where(p => p.id == doctorBO.user.ID).FirstOrDefault <User>();
                    }
                    //_context.Entry(user_).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    BO.AddUser addUserBO = new BO.AddUser();
                    addUserBO.user = doctorBO.user;
                    // addUserBO.user.DoctorSpecialities = doctorBO.DoctorSpecialities;
                    addUserBO.user.Roles  = doctorBO.user.Roles;
                    addUserBO.company     = doctorBO.user.UserCompanies.ToList().Select(p => p.Company).FirstOrDefault();
                    addUserBO.role        = doctorBO.user.Roles.ToArray();
                    addUserBO.address     = doctorBO.user.AddressInfo;
                    addUserBO.contactInfo = doctorBO.user.ContactInfo;
                    using (UserRepository userRepo = new UserRepository(_context))
                    {
                        object obj = userRepo.Save <BO.AddUser>(addUserBO);
                        if (obj.GetType() == errObj.GetType())
                        {
                            errObj = (BO.ErrorObject)obj;
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                ErrorMessage = errObj.ErrorMessage, errorObject = "", ErrorLevel = ErrorLevel.Error
                            });
                        }
                        else
                        {
                            userBO = (BO.User)obj;
                        }
                        doctorBO.user.ID = userBO.ID;
                        doctorDB.User    = _context.Users.Include("UserCompanyRoles").Include("UserCompanies").Where(p => p.id == doctorBO.user.ID && p.UserCompanyRoles.Any(x => x.RoleID == (int)BO.GBEnums.RoleType.Doctor)).FirstOrDefault <User>();
                    }
                }

                if (doctorBO.DoctorSpecialities.Count > 0)
                {
                    _dbSetDocSpecility.RemoveRange(_context.DoctorSpecialities.Where(c => c.DoctorID == doctorBO.user.ID));
                    _context.SaveChanges();
                    Specialty        specilityDB       = null;
                    DoctorSpeciality doctorSpecilityDB = null;
                    foreach (var item in doctorBO.DoctorSpecialities)
                    {
                        BO.DoctorSpeciality doctorSpecialityBO = (BO.DoctorSpeciality)(object) item;
                        specilityDB                 = new Specialty();
                        doctorSpecilityDB           = new DoctorSpeciality();
                        doctorSpecilityDB.IsDeleted = doctorSpecialityBO.IsDeleted.HasValue ? doctorSpecialityBO.IsDeleted.Value : false;
                        doctorSpecilityDB.Doctor    = doctorDB;
                        //Find Record By ID
                        Specialty speclity = _context.Specialties.Where(p => p.id == doctorSpecialityBO.ID).FirstOrDefault <Specialty>();
                        if (speclity == null)
                        {
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                ErrorMessage = "Invalid specility " + item.ToString() + " details.", errorObject = "", ErrorLevel = ErrorLevel.Error
                            });
                        }
                        if (!lstDoctorSpecility.Select(p => p.Specialty).Contains(speclity))
                        {
                            doctorSpecilityDB.Specialty    = speclity;
                            _context.Entry(speclity).State = System.Data.Entity.EntityState.Modified;
                            lstDoctorSpecility.Add(doctorSpecilityDB);
                        }
                        ;
                    }
                }
                doctorDB.DoctorSpecialities = lstDoctorSpecility;

                if (doctorBO.DoctorRoomTestMappings != null)
                {
                    if (doctorBO.DoctorRoomTestMappings.Count > 0)
                    {
                        _dbSetDocRoomTestMapping.RemoveRange(_context.DoctorRoomTestMappings.Where(c => c.DoctorId == doctorBO.user.ID));
                        _context.SaveChanges();
                        RoomTest roomTestDB = null;
                        DoctorRoomTestMapping doctorRoomTestMappingDB = null;
                        foreach (var item in doctorBO.DoctorRoomTestMappings)
                        {
                            BO.DoctorRoomTestMapping doctorRoomTestMappingBO = (BO.DoctorRoomTestMapping)(object) item;
                            roomTestDB = new RoomTest();
                            doctorRoomTestMappingDB           = new DoctorRoomTestMapping();
                            doctorRoomTestMappingDB.IsDeleted = doctorRoomTestMappingBO.IsDeleted.HasValue ? doctorRoomTestMappingBO.IsDeleted.Value : false;
                            doctorRoomTestMappingDB.Doctor    = doctorDB;
                            //Find Record By ID
                            RoomTest roomTest = _context.RoomTests.Where(p => p.id == doctorRoomTestMappingBO.ID).FirstOrDefault <RoomTest>();
                            if (roomTest == null)
                            {
                                dbContextTransaction.Rollback();
                                return(new BO.ErrorObject {
                                    ErrorMessage = "Invalid specility " + item.ToString() + " details.", errorObject = "", ErrorLevel = ErrorLevel.Error
                                });
                            }
                            if (!lstDoctorRoomTestMapping.Select(p => p.RoomTest).Contains(roomTest))
                            {
                                doctorRoomTestMappingDB.RoomTest = roomTest;
                                _context.Entry(roomTest).State   = System.Data.Entity.EntityState.Modified;
                                lstDoctorRoomTestMapping.Add(doctorRoomTestMappingDB);
                            }
                            ;
                        }
                    }
                    doctorDB.DoctorRoomTestMappings = lstDoctorRoomTestMapping;
                }

                if (doctorDB.Id > 0)
                {
                    //Find Doctor By ID
                    Doctor doctor = _context.Doctors.Where(p => p.Id == doctorBO.user.ID && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault <Doctor>();

                    if (doctor == null)
                    {
                        doctorDB = new Doctor();
                    }
                    #region Doctor
                    doctorDB.Id               = doctorBO.ID;
                    doctorDB.LicenseNumber    = string.IsNullOrEmpty(doctorBO.LicenseNumber) ? doctor.LicenseNumber : doctorBO.LicenseNumber;
                    doctorDB.WCBAuthorization = string.IsNullOrEmpty(doctorBO.WCBAuthorization) ? doctor.WCBAuthorization : doctorBO.WCBAuthorization;
                    doctorDB.WcbRatingCode    = string.IsNullOrEmpty(doctorBO.WcbRatingCode) ? doctor.WcbRatingCode : doctorBO.WcbRatingCode;
                    doctorDB.NPI              = string.IsNullOrEmpty(doctorBO.NPI) ? doctor.NPI : doctorBO.NPI;
                    doctorDB.Title            = string.IsNullOrEmpty(doctorBO.Title) ? doctor.Title : doctorBO.Title;
                    doctorDB.TaxTypeId        = !Enum.IsDefined(typeof(BO.GBEnums.TaxType), doctorBO.TaxType) ? System.Convert.ToByte((BO.GBEnums.TaxType)doctor.TaxTypeId) : System.Convert.ToByte(doctorBO.TaxType);
                    doctorDB.IsDeleted        = doctorBO.IsDeleted.HasValue ? doctorBO.IsDeleted : (doctorBO.IsDeleted.HasValue ? doctor.IsDeleted : false);
                    doctorDB.UpdateDate       = doctorBO.UpdateDate;
                    doctorDB.UpdateByUserID   = doctorBO.UpdateByUserID;
                    doctorDB.IsCalendarPublic = doctorBO.IsCalendarPublic;
                    #endregion
                    // doctorDB = doctor;
                    // _context.Entry(doctorDB).State = System.Data.Entity.EntityState.Modified;
                    doctorDB = _context.Doctors.Add(doctorDB);

                    //else
                    //{
                    //    dbContextTransaction.Rollback();
                    //    return new BO.ErrorObject { ErrorMessage = "Please pass valid doctor details.", errorObject = "", ErrorLevel = ErrorLevel.Error };
                    //}
                }
                else
                {
                    doctorDB.LicenseNumber    = doctorBO.LicenseNumber;
                    doctorDB.WCBAuthorization = doctorBO.WCBAuthorization;
                    doctorDB.WcbRatingCode    = doctorBO.WcbRatingCode;
                    doctorDB.NPI              = doctorBO.NPI;
                    doctorDB.Title            = doctorBO.Title;
                    doctorDB.TaxTypeId        = System.Convert.ToByte(doctorBO.TaxType);
                    doctorDB.IsDeleted        = doctorBO.IsDeleted.HasValue ? doctorBO.IsDeleted : false;
                    doctorDB.UpdateDate       = doctorBO.UpdateDate;
                    doctorDB.UpdateByUserID   = doctorBO.UpdateByUserID;
                    doctorDB.CreateDate       = doctorBO.CreateDate;
                    doctorDB.CreateByUserID   = doctorBO.CreateByUserID;
                    doctorDB.IsCalendarPublic = doctorBO.IsCalendarPublic;

                    _dbSet.Add(doctorDB);
                }
                _context.SaveChanges();
                dbContextTransaction.Commit();
            }
            var res = Convert <BO.Doctor, Doctor>(doctorDB);
            return((object)res);
        }