Exemplo n.º 1
0
        //public override object GetCurrentROByPatientId(int id)
        //{
        //    //var acc = _context.Patient2.Include("User").Include("Location").Where(p => p.Id == id && p.IsDeleted == false).FirstOrDefault<Patient2>();
        //    var acc = _context.RefferingOffices.Include("AddressInfo").Where(p => p.PatientId == id && p.IsCurrentReffOffice == true && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault<RefferingOffice>();

        //    if (acc == null)
        //    {
        //        return new BO.ErrorObject { ErrorMessage = "No record found for this Patient.", errorObject = "", ErrorLevel = ErrorLevel.Error };
        //    }
        //    else
        //    {
        //        BO.RefferingOffice acc_ = Convert<BO.RefferingOffice, RefferingOffice>(acc);
        //        return (object)acc_;

        //    }
        //}
        #endregion

        #region save
        //public override object Save<T>(T entity)
        //{
        //    BO.RefferingOffice refferingOfficeBO = (BO.RefferingOffice)(object)entity;
        //    BO.AddressInfo addressBO = refferingOfficeBO.AddressInfo;


        //    RefferingOffice refferingOfficeDB = new RefferingOffice();

        //    using (var dbContextTransaction = _context.Database.BeginTransaction())
        //    {

        //        AddressInfo addressDB = new AddressInfo();


        //        #region Address
        //        if (addressBO != null)
        //        {
        //            bool Add_addressDB = false;
        //            addressDB = _context.AddressInfoes.Where(p => p.id == addressBO.ID).FirstOrDefault();

        //            if (addressDB == null && addressBO.ID <= 0)
        //            {
        //                addressDB = new AddressInfo();
        //                Add_addressDB = true;
        //            }
        //            else if (addressDB == null && addressBO.ID > 0)
        //            {
        //                dbContextTransaction.Rollback();
        //                return new BO.ErrorObject { errorObject = "", ErrorMessage = "Address details dosent exists.", ErrorLevel = ErrorLevel.Error };
        //            }

        //            //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;

        //            if (Add_addressDB == true)
        //            {
        //                addressDB = _context.AddressInfoes.Add(addressDB);
        //            }
        //            _context.SaveChanges();
        //        }
        //        else
        //        {
        //            dbContextTransaction.Rollback();
        //            return new BO.ErrorObject { errorObject = "", ErrorMessage = "Please pass valid Address details.", ErrorLevel = ErrorLevel.Error };
        //        }
        //        #endregion

        //        #region refference office
        //        if (refferingOfficeBO != null)
        //        {
        //            if (refferingOfficeBO.IsCurrentReffOffice == true)
        //            {
        //                var existingrefferingOfficeDB = _context.RefferingOffices.Where(p => p.PatientId == refferingOfficeBO.PatientId).ToList();
        //                existingrefferingOfficeDB.ForEach(p => p.IsCurrentReffOffice = false);
        //            }

        //            bool Add_refferingOfficeDB = false;
        //            refferingOfficeDB = _context.RefferingOffices.Include("AddressInfo").Where(p => p.Id == refferingOfficeBO.ID && (p.IsDeleted == false || p.IsDeleted == null)).FirstOrDefault();

        //            if (refferingOfficeDB == null && refferingOfficeBO.ID <= 0)
        //            {
        //                refferingOfficeDB = new RefferingOffice();
        //                Add_refferingOfficeDB = true;
        //            }
        //            else if (refferingOfficeDB == null && refferingOfficeBO.ID > 0)
        //            {
        //                dbContextTransaction.Rollback();
        //                return new BO.ErrorObject { errorObject = "", ErrorMessage = "Address details dosent exists.", ErrorLevel = ErrorLevel.Error };
        //            }

        //            refferingOfficeDB.PatientId = refferingOfficeBO.PatientId;
        //            refferingOfficeDB.RefferingOfficeId = refferingOfficeBO.RefferingOfficeId;
        //            refferingOfficeDB.AddressInfoId = addressDB.id;
        //            refferingOfficeDB.ReffferingDoctorId = refferingOfficeBO.ReffferingDoctorId;
        //            refferingOfficeDB.NPI = refferingOfficeBO.NPI;
        //            refferingOfficeDB.IsCurrentReffOffice = refferingOfficeBO.IsCurrentReffOffice;
        //            refferingOfficeDB.IsDeleted = refferingOfficeBO.IsDeleted;
        //            refferingOfficeDB.CreateByUserID = refferingOfficeBO.CreateByUserID;
        //            refferingOfficeDB.CreateDate = refferingOfficeBO.CreateDate;
        //            refferingOfficeDB.UpdateByUserID = refferingOfficeBO.UpdateByUserID;
        //            refferingOfficeDB.UpdateDate = refferingOfficeBO.UpdateDate;


        //            if (Add_refferingOfficeDB == true)
        //            {
        //                refferingOfficeDB = _context.RefferingOffices.Add(refferingOfficeDB);
        //            }
        //            _context.SaveChanges();
        //        }
        //        else
        //        {
        //            dbContextTransaction.Rollback();
        //            return new BO.ErrorObject { errorObject = "", ErrorMessage = "Please pass valid Reffering Office details.", ErrorLevel = ErrorLevel.Error };
        //        }
        //      #endregion



        //        dbContextTransaction.Commit();

        //        refferingOfficeDB = _context.RefferingOffices.Include("AddressInfo").Where(p => p.Id == refferingOfficeDB.Id && (p.IsDeleted == false || p.IsDeleted == null)).FirstOrDefault<RefferingOffice>();
        //    }

        //    var res = Convert<BO.RefferingOffice, RefferingOffice>(refferingOfficeDB);
        //    return (object)res;
        //}
        #endregion

        #region save
        public override object Save <T>(T entity)
        {
            BO.RefferingOffice refferingOfficeBO = (BO.RefferingOffice)(object) entity;
            BO.AddressInfo     addressBO         = refferingOfficeBO.AddressInfo;
            //BO.Case caseBO = refferingOfficeBO.Case;

            RefferingOffice refferingOfficeDB = new RefferingOffice();

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                AddressInfo addressDB = new AddressInfo();
                //Case caseDB = new Case();

                bool IsEditMode = false;
                IsEditMode = (refferingOfficeBO != null && refferingOfficeBO.ID > 0) ? true : false;

                if (IsEditMode == false)
                {
                    if (refferingOfficeBO.CaseId == 0)
                    {
                        return new BO.ErrorObject {
                                   errorObject = "", ErrorMessage = "Please pass valid Case Id.", ErrorLevel = ErrorLevel.Error
                        }
                    }
                }
                ;
Exemplo n.º 2
0
        public override T Convert <T, U>(U entity)
        {
            RefferingOffice refferingOffice = entity as RefferingOffice;

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

            BO.RefferingOffice refferenceOfficeBO2 = new BO.RefferingOffice();

            refferenceOfficeBO2.ID                 = refferingOffice.Id;
            refferenceOfficeBO2.CaseId             = refferingOffice.CaseId;
            refferenceOfficeBO2.RefferingOfficeId  = refferingOffice.RefferingOfficeId;
            refferenceOfficeBO2.AddressInfoId      = refferingOffice.AddressInfoId;
            refferenceOfficeBO2.ReffferingDoctorId = refferingOffice.ReffferingDoctorId;
            refferenceOfficeBO2.NPI                = refferingOffice.NPI;

            if (refferingOffice.IsDeleted.HasValue)
            {
                refferenceOfficeBO2.IsDeleted = refferingOffice.IsDeleted.Value;
            }
            if (refferingOffice.UpdateByUserID.HasValue)
            {
                refferenceOfficeBO2.UpdateByUserID = refferingOffice.UpdateByUserID.Value;
            }



            if (refferingOffice.AddressInfo != null)
            {
                if (refferingOffice.AddressInfo.IsDeleted.HasValue == false || (refferingOffice.AddressInfo.IsDeleted.HasValue == true && refferingOffice.AddressInfo.IsDeleted.Value == false))
                {
                    BO.AddressInfo boAddress = new BO.AddressInfo();
                    boAddress.Name     = refferingOffice.AddressInfo.Name;
                    boAddress.Address1 = refferingOffice.AddressInfo.Address1;
                    boAddress.Address2 = refferingOffice.AddressInfo.Address2;
                    boAddress.City     = refferingOffice.AddressInfo.City;
                    boAddress.State    = refferingOffice.AddressInfo.State;
                    boAddress.ZipCode  = refferingOffice.AddressInfo.ZipCode;
                    boAddress.Country  = refferingOffice.AddressInfo.Country;
                    //[STATECODE-CHANGE]
                    //boAddress.StateCode = refferingOffice.AddressInfo.StateCode;
                    //[STATECODE-CHANGE]
                    boAddress.CreateByUserID        = refferingOffice.AddressInfo.CreateByUserID;
                    boAddress.ID                    = refferingOffice.AddressInfo.id;
                    refferenceOfficeBO2.AddressInfo = boAddress;
                }
            }

            refferenceOfficeBO2.IsDeleted      = refferingOffice.IsDeleted;
            refferenceOfficeBO2.CreateByUserID = refferingOffice.CreateByUserID;
            refferenceOfficeBO2.UpdateByUserID = refferingOffice.UpdateByUserID;

            return((T)(object)refferenceOfficeBO2);
        }
        public override T ObjectConvert <T, U>(U entity)
        {
            InsuranceMaster insuranceMaster = entity as InsuranceMaster;

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

            BO.InsuranceMaster boInsuranceMaster = new BO.InsuranceMaster();

            boInsuranceMaster.ID                 = insuranceMaster.Id;
            boInsuranceMaster.CompanyCode        = insuranceMaster.CompanyCode;
            boInsuranceMaster.CompanyName        = insuranceMaster.CompanyName;
            boInsuranceMaster.AddressInfoId      = insuranceMaster.AddressInfoId;
            boInsuranceMaster.ContactInfoId      = insuranceMaster.ContactInfoId;
            boInsuranceMaster.ZeusID             = insuranceMaster.ZeusID;
            boInsuranceMaster.PriorityBilling    = insuranceMaster.PriorityBilling;
            boInsuranceMaster.Only1500Form       = insuranceMaster.Only1500Form;
            boInsuranceMaster.PaperAuthorization = insuranceMaster.PaperAuthorization;
            boInsuranceMaster.CreatedByCompanyId = insuranceMaster.CreatedByCompanyId;

            //if (insuranceMaster.IsDeleted.HasValue)
            //    boInsuranceMaster.IsDeleted = insuranceMaster.IsDeleted.Value;

            if (insuranceMaster.AddressInfo != null)
            {
                BO.AddressInfo boAddress = new BO.AddressInfo();
                boAddress.Name                = insuranceMaster.AddressInfo.Name;
                boAddress.Address1            = insuranceMaster.AddressInfo.Address1;
                boAddress.Address2            = insuranceMaster.AddressInfo.Address2;
                boAddress.City                = insuranceMaster.AddressInfo.City;
                boAddress.State               = insuranceMaster.AddressInfo.State;
                boAddress.ZipCode             = insuranceMaster.AddressInfo.ZipCode;
                boAddress.Country             = insuranceMaster.AddressInfo.Country;
                boAddress.CreateByUserID      = insuranceMaster.AddressInfo.CreateByUserID;
                boAddress.ID                  = insuranceMaster.AddressInfo.id;
                boAddress.IsDeleted           = insuranceMaster.AddressInfo.IsDeleted;
                boInsuranceMaster.AddressInfo = boAddress;
            }

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

            boInsuranceMaster.IsDeleted      = insuranceMaster.IsDeleted;
            boInsuranceMaster.CreateByUserID = insuranceMaster.CreateByUserID;
            boInsuranceMaster.UpdateByUserID = insuranceMaster.UpdateByUserID;

            return((T)(object)boInsuranceMaster);
        }
Exemplo n.º 4
0
        public override T Convert <T, U>(U entity)
        {
            Location location = entity as Location;

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

            BO.Location locationBO = new BO.Location();

            locationBO.ID           = location.id;
            locationBO.Name         = location.Name;
            locationBO.IsDefault    = location.IsDefault;
            locationBO.LocationType = (BO.GBEnums.LocationType)location.LocationType;
            if (location.IsDeleted.HasValue)
            {
                locationBO.IsDeleted = location.IsDeleted.Value;
            }
            if (location.UpdateByUserID.HasValue)
            {
                locationBO.UpdateByUserID = location.UpdateByUserID.Value;
            }



            if (location.Company != null)
            {
                BO.Company boCompany = new BO.Company();
                boCompany.ID          = location.Company.id;
                boCompany.Name        = location.Company.Name;
                boCompany.TaxID       = location.Company.TaxID;
                boCompany.Status      = (BO.GBEnums.AccountStatus)location.Company.Status;
                boCompany.CompanyType = (BO.GBEnums.CompanyType)location.Company.CompanyType;
                if (location.Company.SubscriptionPlanType != null)
                {
                    boCompany.SubsCriptionType = (BO.GBEnums.SubsCriptionType)location.Company.SubscriptionPlanType;
                }
                else
                {
                    boCompany.SubsCriptionType = null;
                }

                locationBO.Company = boCompany;
            }

            if (location.AddressInfo != null)
            {
                BO.AddressInfo boAddress = new BO.AddressInfo();
                boAddress.Name     = location.AddressInfo.Name;
                boAddress.Address1 = location.AddressInfo.Address1;
                boAddress.Address2 = location.AddressInfo.Address2;
                boAddress.City     = location.AddressInfo.City;
                boAddress.State    = location.AddressInfo.State;
                boAddress.ZipCode  = location.AddressInfo.ZipCode;
                boAddress.Country  = location.AddressInfo.Country;
                //[STATECODE-CHANGE]
                //boAddress.StateCode = location.AddressInfo.StateCode;
                //[STATECODE-CHANGE]
                boAddress.CreateByUserID = location.AddressInfo.CreateByUserID;
                boAddress.ID             = location.AddressInfo.id;
                if (location.AddressInfo.IsDeleted.HasValue)
                {
                    boAddress.IsDeleted = location.AddressInfo.IsDeleted.Value;
                }
                if (location.AddressInfo.UpdateByUserID.HasValue)
                {
                    boAddress.UpdateByUserID = location.AddressInfo.UpdateByUserID.Value;
                }
                locationBO.AddressInfo = boAddress;
            }

            if (location.ContactInfo != null)
            {
                BO.ContactInfo boContactInfo = new BO.ContactInfo();
                boContactInfo.Name           = location.ContactInfo.Name;
                boContactInfo.CellPhone      = location.ContactInfo.CellPhone;
                boContactInfo.EmailAddress   = location.ContactInfo.EmailAddress;
                boContactInfo.HomePhone      = location.ContactInfo.HomePhone;
                boContactInfo.WorkPhone      = location.ContactInfo.WorkPhone;
                boContactInfo.FaxNo          = location.ContactInfo.FaxNo;
                boContactInfo.CreateByUserID = location.ContactInfo.CreateByUserID;
                boContactInfo.ID             = location.ContactInfo.id;
                if (location.ContactInfo.IsDeleted.HasValue)
                {
                    boContactInfo.IsDeleted = location.ContactInfo.IsDeleted.Value;
                }
                if (location.ContactInfo.UpdateByUserID.HasValue)
                {
                    boContactInfo.UpdateByUserID = location.ContactInfo.UpdateByUserID.Value;
                }
                locationBO.ContactInfo = boContactInfo;
            }
            BO.Schedule boSchedule = new BO.Schedule();
            using (ScheduleRepository cmp = new ScheduleRepository(_context))
            {
                boSchedule = cmp.Convert <BO.Schedule, Schedule>(location.Schedule);
                // cmp.Save(boSchedule);
                locationBO.Schedule = boSchedule;
            }
            return((T)(object)locationBO);
        }
Exemplo n.º 5
0
        public override object Save <T>(T entity)
        {
            BO.SaveLocation saveLocationBO = (BO.SaveLocation)(object) entity;

            if (saveLocationBO.location == null)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "Location object can't be null", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }
            if (saveLocationBO.location.ID == 0)
            {
                if (saveLocationBO.addressInfo == null)
                {
                    return(new BO.ErrorObject {
                        ErrorMessage = "Addressinfo object can't be null", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }
            }
            if (saveLocationBO.location.ID == 0)
            {
                if (saveLocationBO.contactInfo == null)
                {
                    return(new BO.ErrorObject {
                        ErrorMessage = "Contactinfo object can't be null", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }
            }
            if (saveLocationBO.location.ID == 0)
            {
                if (saveLocationBO.company == null)
                {
                    return(new BO.ErrorObject {
                        ErrorMessage = "Company object can't be null", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }
            }


            BO.Location    locationBO    = saveLocationBO.location;
            BO.Company     companyBO     = saveLocationBO.company;
            BO.AddressInfo addressBO     = saveLocationBO.addressInfo;
            BO.ContactInfo contactinfoBO = saveLocationBO.contactInfo;

            Location    locationDB    = new Location();
            Company     companyDB     = new Company();
            User        userDB        = new User();
            AddressInfo addressDB     = new AddressInfo();
            ContactInfo contactinfoDB = new ContactInfo();

            #region Location
            locationDB.id           = locationBO.ID;
            locationDB.Name         = locationBO.Name;
            locationDB.LocationType = System.Convert.ToByte(locationBO.LocationType);
            locationDB.IsDefault    = locationBO.IsDefault;
            locationDB.IsDeleted    = locationBO.IsDeleted.HasValue ? locationBO.IsDeleted : false;
            #endregion

            #region Company
            if (companyBO.ID > 0)
            {
                Company company = _context.Companies.Where(p => p.id == companyBO.ID).FirstOrDefault <Company>();
                if (company != null)
                {
                    locationDB.Company            = company;
                    _context.Entry(company).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    return new BO.ErrorObject {
                               errorObject = "", ErrorMessage = "Please pass valid Company details.", ErrorLevel = ErrorLevel.Error
                    }
                };
            }
            #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;
                //[STATECODE-CHANGE]
                //addressDB.StateCode = addressBO.StateCode;
                //[STATECODE-CHANGE]
            }
            #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

            //Added code to get data in AddressInfo and ContactInfo
            locationDB.AddressInfo = addressDB;
            locationDB.ContactInfo = contactinfoDB;

            if (saveLocationBO.schedule != null)
            {
                #region Schedule
                if (saveLocationBO.schedule != null)
                {
                    if (saveLocationBO.schedule.ID > 0)
                    {
                        Schedule schedule = _context.Schedules.Where(p => p.id == saveLocationBO.schedule.ID).FirstOrDefault <Schedule>();
                        if (schedule != null)
                        {
                            locationDB.Schedule = schedule;
                        }
                        else
                        {
                            return new BO.ErrorObject {
                                       errorObject = "", ErrorMessage = "Please pass valid Schedule.", ErrorLevel = ErrorLevel.Error
                            }
                        };
                    }
                }
                #endregion
            }
            else
            {
                //Default schedule

                Schedule defaultschedule = _context.Schedules.Where(p => p.IsDefault == true).FirstOrDefault <Schedule>();
                if (defaultschedule != null)
                {
                    locationDB.Schedule = defaultschedule;
                }
                else
                {
                    return new BO.ErrorObject {
                               errorObject = "", ErrorMessage = "Please set default schedule in database.", ErrorLevel = ErrorLevel.Error
                    }
                };
            }

            if (locationDB.id > 0)
            {
                //For Update Record

                //Find Location By ID
                Location location = _context.Locations.Include("Company").Include("ContactInfo").Include("AddressInfo").Where(p => p.id == locationDB.id).FirstOrDefault <Location>();

                if (location != null)
                {
                    #region Location
                    locationDB.id = locationBO.ID;

                    location.Name           = locationBO.Name == null ? location.Name : locationBO.Name;
                    location.LocationType   = locationBO.LocationType == null ? location.LocationType : System.Convert.ToByte(locationBO.LocationType);
                    location.IsDefault      = locationBO.IsDefault;
                    location.IsDeleted      = locationBO.IsDeleted == null ? locationBO.IsDeleted : locationDB.IsDeleted;
                    location.UpdateDate     = locationBO.UpdateDate;
                    location.UpdateByUserID = locationBO.UpdateByUserID;
                    #endregion

                    #region AddressInfo
                    location.AddressInfo.CreateByUserID = location.CreateByUserID;
                    location.AddressInfo.CreateDate     = location.CreateDate;
                    if (locationBO.UpdateByUserID.HasValue)
                    {
                        location.AddressInfo.UpdateByUserID = locationBO.UpdateByUserID.Value;
                    }
                    location.AddressInfo.UpdateDate = DateTime.UtcNow;
                    location.AddressInfo.Name       = addressBO.Name;
                    location.AddressInfo.Address1   = addressBO.Address1;
                    location.AddressInfo.Address2   = addressBO.Address2;
                    location.AddressInfo.City       = addressBO.City;
                    location.AddressInfo.State      = addressBO.State;
                    location.AddressInfo.ZipCode    = addressBO.ZipCode;
                    location.AddressInfo.Country    = addressBO.Country;
                    //[STATECODE-CHANGE]
                    //location.AddressInfo.StateCode = addressBO.StateCode;
                    //[STATECODE-CHANGE]
                    location.AddressInfo.UpdateDate     = addressBO.UpdateDate;
                    location.AddressInfo.UpdateByUserID = addressBO.UpdateByUserID;
                    #endregion

                    #region Contact Info
                    location.ContactInfo.CreateByUserID = location.CreateByUserID;
                    location.ContactInfo.CreateDate     = location.CreateDate;
                    if (locationBO.UpdateByUserID.HasValue)
                    {
                        location.ContactInfo.UpdateByUserID = locationBO.UpdateByUserID.Value;
                    }
                    location.ContactInfo.UpdateDate     = DateTime.UtcNow;
                    location.ContactInfo.Name           = contactinfoBO.Name;
                    location.ContactInfo.CellPhone      = contactinfoBO.CellPhone;
                    location.ContactInfo.EmailAddress   = contactinfoBO.EmailAddress;
                    location.ContactInfo.HomePhone      = contactinfoBO.HomePhone;
                    location.ContactInfo.WorkPhone      = contactinfoBO.WorkPhone;
                    location.ContactInfo.FaxNo          = contactinfoBO.FaxNo;
                    location.ContactInfo.UpdateDate     = contactinfoBO.UpdateDate;
                    location.ContactInfo.UpdateByUserID = contactinfoBO.UpdateByUserID;
                    #endregion

                    #region Schedule
                    if (saveLocationBO.schedule != null)
                    {
                        if (saveLocationBO.schedule.ID > 0)
                        {
                            Schedule schedule = _context.Schedules.Where(p => p.id == saveLocationBO.schedule.ID).FirstOrDefault <Schedule>();

                            if (schedule != null)
                            {
                                location.Schedule = schedule;
                            }
                            else
                            {
                                return new BO.ErrorObject {
                                           errorObject = "", ErrorMessage = "Please pass valid Schedule.", ErrorLevel = ErrorLevel.Error
                                }
                            };
                        }
                    }
                    #endregion

                    _context.Entry(location).State = System.Data.Entity.EntityState.Modified;
                }
            }
            else
            {
                locationDB.CreateDate     = companyBO.CreateDate;
                locationDB.CreateByUserID = companyBO.CreateByUserID;

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

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

                locationDB.AddressInfo = addressDB;
                locationDB.ContactInfo = contactinfoDB;
                _dbSet.Add(locationDB);
            }
            _context.SaveChanges();

            var res = Convert <BO.Location, Location>(locationDB);
            return((object)res);
        }
        public override T Convert <T, U>(U entity)
        {
            AdjusterMaster adjusterMasterDB = entity as AdjusterMaster;

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

            BO.AdjusterMaster adjusterMasterBO = new BO.AdjusterMaster();

            adjusterMasterBO.ID                = adjusterMasterDB.Id;
            adjusterMasterBO.CompanyId         = adjusterMasterDB.CompanyId;
            adjusterMasterBO.FirstName         = adjusterMasterDB.FirstName;
            adjusterMasterBO.MiddleName        = adjusterMasterDB.MiddleName;
            adjusterMasterBO.LastName          = adjusterMasterDB.LastName;
            adjusterMasterBO.InsuranceMasterId = adjusterMasterDB.InsuranceMasterId;
            adjusterMasterBO.AddressInfoId     = adjusterMasterDB.AddressInfoId;
            adjusterMasterBO.ContactInfoId     = adjusterMasterDB.ContactInfoId;

            if (adjusterMasterDB.AddressInfo != null)
            {
                BO.AddressInfo boAddress = new BO.AddressInfo();
                boAddress.Name     = adjusterMasterDB.AddressInfo.Name;
                boAddress.Address1 = adjusterMasterDB.AddressInfo.Address1;
                boAddress.Address2 = adjusterMasterDB.AddressInfo.Address2;
                boAddress.City     = adjusterMasterDB.AddressInfo.City;
                boAddress.State    = adjusterMasterDB.AddressInfo.State;
                boAddress.ZipCode  = adjusterMasterDB.AddressInfo.ZipCode;
                boAddress.Country  = adjusterMasterDB.AddressInfo.Country;
                //[STATECODE-CHANGE]
                //boAddress.StateCode = adjusterMasterDB.AddressInfo.StateCode;
                //[STATECODE-CHANGE]
                boAddress.CreateByUserID     = adjusterMasterDB.AddressInfo.CreateByUserID;
                boAddress.ID                 = adjusterMasterDB.AddressInfo.id;
                adjusterMasterBO.AddressInfo = boAddress;
            }
            if (adjusterMasterDB.ContactInfo != null)
            {
                BO.ContactInfo boContactInfo = new BO.ContactInfo();
                boContactInfo.Name                   = adjusterMasterDB.ContactInfo.Name;
                boContactInfo.CellPhone              = adjusterMasterDB.ContactInfo.CellPhone;
                boContactInfo.EmailAddress           = adjusterMasterDB.ContactInfo.EmailAddress;
                boContactInfo.HomePhone              = adjusterMasterDB.ContactInfo.HomePhone;
                boContactInfo.WorkPhone              = adjusterMasterDB.ContactInfo.WorkPhone;
                boContactInfo.FaxNo                  = adjusterMasterDB.ContactInfo.FaxNo;
                boContactInfo.CreateByUserID         = adjusterMasterDB.ContactInfo.CreateByUserID;
                boContactInfo.ID                     = adjusterMasterDB.ContactInfo.id;
                boContactInfo.OfficeExtension        = adjusterMasterDB.ContactInfo.OfficeExtension;
                boContactInfo.AlternateEmail         = adjusterMasterDB.ContactInfo.AlternateEmail;
                boContactInfo.PreferredCommunication = adjusterMasterDB.ContactInfo.PreferredCommunication;

                adjusterMasterBO.ContactInfo = boContactInfo;
            }



            //Common
            adjusterMasterBO.IsDeleted      = adjusterMasterDB.IsDeleted;
            adjusterMasterBO.CreateByUserID = adjusterMasterDB.CreateByUserID;
            adjusterMasterBO.UpdateByUserID = adjusterMasterDB.UpdateByUserID;

            return((T)(object)adjusterMasterBO);
        }
        public override object Save <T>(T entity)
        {
            BO.AdjusterMaster adjusterMasterBO = (BO.AdjusterMaster)(object) entity;
            BO.AddressInfo    addressBO        = adjusterMasterBO.AddressInfo;
            BO.ContactInfo    contactinfoBO    = adjusterMasterBO.ContactInfo;

            AdjusterMaster adjusterMasterDB = new AdjusterMaster();

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                bool IsEditMode = false;
                IsEditMode = (adjusterMasterBO != null && adjusterMasterBO.ID > 0) ? true : false;

                AddressInfo addressDB     = new AddressInfo();
                ContactInfo contactinfoDB = new ContactInfo();

                #region Address
                if (addressBO != null)
                {
                    bool Add_addressDB = false;
                    addressDB = _context.AddressInfoes.Where(p => p.id == addressBO.ID).FirstOrDefault();

                    if (addressDB == null && addressBO.ID <= 0)
                    {
                        addressDB     = new AddressInfo();
                        Add_addressDB = true;
                    }
                    else if (addressDB == null && addressBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Address details dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    addressDB.Name     = IsEditMode == true && addressBO.Name == null ? addressDB.Name : addressBO.Name;
                    addressDB.Address1 = IsEditMode == true && addressBO.Address1 == null ? addressDB.Address1 : addressBO.Address1;
                    addressDB.Address2 = IsEditMode == true && addressBO.Address2 == null ? addressDB.Address2 : addressBO.Address2;
                    addressDB.City     = IsEditMode == true && addressBO.City == null ? addressDB.City : addressBO.City;
                    addressDB.State    = IsEditMode == true && addressBO.State == null ? addressDB.State : addressBO.State;
                    addressDB.ZipCode  = IsEditMode == true && addressBO.ZipCode == null ? addressDB.ZipCode : addressBO.ZipCode;
                    addressDB.Country  = IsEditMode == true && addressBO.Country == null ? addressDB.Country : addressBO.Country;
                    //[STATECODE-CHANGE]
                    // addressDB.StateCode = IsEditMode == true && addressBO.StateCode == null ? addressDB.StateCode : addressBO.StateCode;
                    //[STATECODE-CHANGE]

                    if (Add_addressDB == true)
                    {
                        addressDB = _context.AddressInfoes.Add(addressDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    if (IsEditMode == false)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Please pass valid address details.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    addressDB = null;
                }
                #endregion

                #region Contact Info
                if (contactinfoBO != null)
                {
                    bool Add_contactinfoDB = false;
                    contactinfoDB = _context.ContactInfoes.Where(p => p.id == contactinfoBO.ID).FirstOrDefault();

                    if (contactinfoDB == null && contactinfoBO.ID <= 0)
                    {
                        contactinfoDB     = new ContactInfo();
                        Add_contactinfoDB = true;
                    }
                    else if (contactinfoDB == null && contactinfoBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Contact details dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    contactinfoDB.Name                   = IsEditMode == true && contactinfoBO.Name == null ? contactinfoDB.Name : contactinfoBO.Name;
                    contactinfoDB.CellPhone              = IsEditMode == true && contactinfoBO.CellPhone == null ? contactinfoDB.CellPhone : contactinfoBO.CellPhone;
                    contactinfoDB.EmailAddress           = IsEditMode == true && contactinfoBO.EmailAddress == null ? contactinfoDB.EmailAddress : contactinfoBO.EmailAddress;
                    contactinfoDB.HomePhone              = IsEditMode == true && contactinfoBO.HomePhone == null ? contactinfoDB.HomePhone : contactinfoBO.HomePhone;
                    contactinfoDB.WorkPhone              = IsEditMode == true && contactinfoBO.WorkPhone == null ? contactinfoDB.WorkPhone : contactinfoBO.WorkPhone;
                    contactinfoDB.FaxNo                  = IsEditMode == true && contactinfoBO.FaxNo == null ? contactinfoDB.FaxNo : contactinfoBO.FaxNo;
                    contactinfoDB.IsDeleted              = contactinfoBO.IsDeleted;
                    contactinfoDB.OfficeExtension        = IsEditMode == true && contactinfoBO.OfficeExtension == null ? contactinfoDB.OfficeExtension : contactinfoBO.OfficeExtension;
                    contactinfoDB.AlternateEmail         = IsEditMode == true && contactinfoBO.AlternateEmail == null ? contactinfoDB.AlternateEmail : contactinfoBO.AlternateEmail;
                    contactinfoDB.PreferredCommunication = IsEditMode == true && contactinfoBO.PreferredCommunication == null ? contactinfoDB.PreferredCommunication : contactinfoBO.PreferredCommunication;

                    if (Add_contactinfoDB == true)
                    {
                        contactinfoDB = _context.ContactInfoes.Add(contactinfoDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    if (IsEditMode == false)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Please pass valid contact details.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    contactinfoDB = null;
                }
                #endregion

                #region AdjusterMaster

                if (adjusterMasterBO != null)
                {
                    bool Add_adjusterMasterDB = false;
                    adjusterMasterDB = _context.AdjusterMasters.Where(p => p.Id == adjusterMasterBO.ID).FirstOrDefault();

                    if (adjusterMasterDB == null && adjusterMasterBO.ID <= 0)
                    {
                        adjusterMasterDB     = new AdjusterMaster();
                        Add_adjusterMasterDB = true;
                    }
                    else if (adjusterMasterDB == null && adjusterMasterBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Adjuster information dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    adjusterMasterDB.CompanyId         = adjusterMasterBO.CompanyId;
                    adjusterMasterDB.InsuranceMasterId = adjusterMasterBO.InsuranceMasterId;
                    adjusterMasterDB.FirstName         = IsEditMode == true && adjusterMasterBO.FirstName == null ? adjusterMasterDB.FirstName : adjusterMasterBO.FirstName;
                    adjusterMasterDB.MiddleName        = IsEditMode == true && adjusterMasterBO.MiddleName == null ? adjusterMasterDB.MiddleName : adjusterMasterBO.MiddleName;
                    adjusterMasterDB.LastName          = IsEditMode == true && adjusterMasterBO.LastName == null ? adjusterMasterDB.LastName : adjusterMasterBO.LastName;
                    adjusterMasterDB.AddressInfoId     = (addressDB != null && addressDB.id > 0) ? addressDB.id : adjusterMasterDB.AddressInfoId;
                    adjusterMasterDB.ContactInfoId     = (contactinfoDB != null && contactinfoDB.id > 0) ? contactinfoDB.id : adjusterMasterDB.ContactInfoId;

                    if (Add_adjusterMasterDB == true)
                    {
                        adjusterMasterDB = _context.AdjusterMasters.Add(adjusterMasterDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    if (IsEditMode == false)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Please pass valid adjuster information details.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    adjusterMasterDB = null;
                }

                _context.SaveChanges();
                #endregion

                dbContextTransaction.Commit();

                adjusterMasterDB = _context.AdjusterMasters.Include("AddressInfo")
                                   .Include("ContactInfo").Include("InsuranceMaster").Where(p => p.Id == adjusterMasterDB.Id).FirstOrDefault <AdjusterMaster>();
            }

            var res = Convert <BO.AdjusterMaster, AdjusterMaster>(adjusterMasterDB);
            return((object)res);
        }
        public override T Convert <T, U>(U entity)
        {
            PatientAccidentInfo PatientAccidentInfoDB = entity as PatientAccidentInfo;

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

            BO.PatientAccidentInfo PatientAccidentInfoBO = new BO.PatientAccidentInfo();
            PatientAccidentInfoBO.ID                    = PatientAccidentInfoDB.Id;
            PatientAccidentInfoBO.CaseId                = PatientAccidentInfoDB.CaseId;
            PatientAccidentInfoBO.AccidentDate          = PatientAccidentInfoDB.AccidentDate;
            PatientAccidentInfoBO.Weather               = PatientAccidentInfoDB.Weather;
            PatientAccidentInfoBO.PlateNumber           = PatientAccidentInfoDB.PlateNumber;
            PatientAccidentInfoBO.AccidentAddressInfoId = PatientAccidentInfoDB.AccidentAddressInfoId;
            PatientAccidentInfoBO.PoliceAtScene         = PatientAccidentInfoDB.PoliceAtScene;
            PatientAccidentInfoBO.Precinct              = PatientAccidentInfoDB.Precinct;
            PatientAccidentInfoBO.ReportNumber          = PatientAccidentInfoDB.ReportNumber;
            PatientAccidentInfoBO.PatientTypeId         = PatientAccidentInfoDB.PatientTypeId;
            PatientAccidentInfoBO.WearingSeatBelts      = PatientAccidentInfoDB.WearingSeatBelts;
            PatientAccidentInfoBO.AirBagsDeploy         = PatientAccidentInfoDB.AirBagsDeploy;
            PatientAccidentInfoBO.PhotosTaken           = PatientAccidentInfoDB.PhotosTaken;
            PatientAccidentInfoBO.AccidentDescription   = PatientAccidentInfoDB.AccidentDescription;
            PatientAccidentInfoBO.Witness               = PatientAccidentInfoDB.Witness;
            PatientAccidentInfoBO.DescribeInjury        = PatientAccidentInfoDB.DescribeInjury;
            PatientAccidentInfoBO.HospitalName          = PatientAccidentInfoDB.HospitalName;
            PatientAccidentInfoBO.Ambulance             = PatientAccidentInfoDB.Ambulance;
            PatientAccidentInfoBO.HospitalAddressInfoId = PatientAccidentInfoDB.HospitalAddressInfoId;
            PatientAccidentInfoBO.TreatedAndReleased    = PatientAccidentInfoDB.TreatedAndReleased;
            PatientAccidentInfoBO.Admitted              = PatientAccidentInfoDB.Admitted;
            PatientAccidentInfoBO.DateOfAdmission       = PatientAccidentInfoDB.DateOfAdmission;
            PatientAccidentInfoBO.XRaysTaken            = PatientAccidentInfoDB.XRaysTaken;
            PatientAccidentInfoBO.DurationAtHospital    = PatientAccidentInfoDB.DurationAtHospital;
            PatientAccidentInfoBO.MedicalReportNumber   = PatientAccidentInfoDB.MedicalReportNumber;
            PatientAccidentInfoBO.AdditionalPatients    = PatientAccidentInfoDB.AdditionalPatients;

            if (PatientAccidentInfoDB.AddressInfo != null)
            {
                if (PatientAccidentInfoDB.AddressInfo.IsDeleted.HasValue == false || (PatientAccidentInfoDB.AddressInfo.IsDeleted.HasValue == true && PatientAccidentInfoDB.AddressInfo.IsDeleted.Value == false))
                {
                    BO.AddressInfo boAddress = new BO.AddressInfo();
                    boAddress.Name           = PatientAccidentInfoDB.AddressInfo.Name;
                    boAddress.Address1       = PatientAccidentInfoDB.AddressInfo.Address1;
                    boAddress.Address2       = PatientAccidentInfoDB.AddressInfo.Address2;
                    boAddress.City           = PatientAccidentInfoDB.AddressInfo.City;
                    boAddress.State          = PatientAccidentInfoDB.AddressInfo.State;
                    boAddress.ZipCode        = PatientAccidentInfoDB.AddressInfo.ZipCode;
                    boAddress.Country        = PatientAccidentInfoDB.AddressInfo.Country;
                    boAddress.CreateByUserID = PatientAccidentInfoDB.AddressInfo.CreateByUserID;
                    boAddress.ID             = PatientAccidentInfoDB.AddressInfo.id;
                    PatientAccidentInfoBO.AccidentAddressInfo = boAddress;
                }
            }
            if (PatientAccidentInfoDB.AddressInfo1 != null)
            {
                if (PatientAccidentInfoDB.AddressInfo1.IsDeleted.HasValue == false || (PatientAccidentInfoDB.AddressInfo1.IsDeleted.HasValue == true && PatientAccidentInfoDB.AddressInfo1.IsDeleted.Value == false))
                {
                    BO.AddressInfo boAddress1 = new BO.AddressInfo();
                    boAddress1.Name           = PatientAccidentInfoDB.AddressInfo1.Name;
                    boAddress1.Address1       = PatientAccidentInfoDB.AddressInfo1.Address1;
                    boAddress1.Address2       = PatientAccidentInfoDB.AddressInfo1.Address2;
                    boAddress1.City           = PatientAccidentInfoDB.AddressInfo1.City;
                    boAddress1.State          = PatientAccidentInfoDB.AddressInfo1.State;
                    boAddress1.ZipCode        = PatientAccidentInfoDB.AddressInfo1.ZipCode;
                    boAddress1.Country        = PatientAccidentInfoDB.AddressInfo1.Country;
                    boAddress1.CreateByUserID = PatientAccidentInfoDB.AddressInfo1.CreateByUserID;
                    boAddress1.ID             = PatientAccidentInfoDB.AddressInfo1.id;
                    PatientAccidentInfoBO.HospitalAddressInfo = boAddress1;
                }
            }

            PatientAccidentInfoBO.AccidentWitnesses = new List <BO.AccidentWitness>();
            if (PatientAccidentInfoDB.AccidentWitnesses != null)
            {
                foreach (var eachAccidentWitness in PatientAccidentInfoDB.AccidentWitnesses)
                {
                    BO.AccidentWitness AccidentWitnessBO = new BO.AccidentWitness();
                    AccidentWitnessBO.ID = eachAccidentWitness.Id;
                    AccidentWitnessBO.PatientAccidentInfoId = eachAccidentWitness.PatientAccidentInfoId;
                    AccidentWitnessBO.WitnessName           = eachAccidentWitness.WitnessName;
                    AccidentWitnessBO.WitnessContactNumber  = eachAccidentWitness.WitnessContactNumber;
                    AccidentWitnessBO.IsDeleted             = eachAccidentWitness.IsDeleted;

                    PatientAccidentInfoBO.AccidentWitnesses.Add(AccidentWitnessBO);
                }
            }

            PatientAccidentInfoBO.AccidentTreatments = new List <BO.AccidentTreatment>();
            if (PatientAccidentInfoDB.AccidentTreatments != null)
            {
                foreach (var eachAccidentTreatment in PatientAccidentInfoDB.AccidentTreatments)
                {
                    BO.AccidentTreatment AccidentTreatmentBO = new BO.AccidentTreatment();
                    AccidentTreatmentBO.ID = eachAccidentTreatment.Id;
                    AccidentTreatmentBO.PatientAccidentInfoId = eachAccidentTreatment.PatientAccidentInfoId;
                    AccidentTreatmentBO.MedicalFacilityName   = eachAccidentTreatment.MedicalFacilityName;
                    AccidentTreatmentBO.DoctorName            = eachAccidentTreatment.DoctorName;
                    AccidentTreatmentBO.ContactNumber         = eachAccidentTreatment.ContactNumber;
                    AccidentTreatmentBO.Address   = eachAccidentTreatment.Address;
                    AccidentTreatmentBO.IsDeleted = eachAccidentTreatment.IsDeleted;

                    PatientAccidentInfoBO.AccidentTreatments.Add(AccidentTreatmentBO);
                }
            }

            PatientAccidentInfoBO.IsDeleted      = PatientAccidentInfoDB.IsDeleted;
            PatientAccidentInfoBO.CreateByUserID = PatientAccidentInfoDB.CreateByUserID;
            PatientAccidentInfoBO.UpdateByUserID = PatientAccidentInfoDB.UpdateByUserID;

            return((T)(object)PatientAccidentInfoBO);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
        public override T Convert <T, U>(U entity)
        {
            PatientEmpInfo PatientEmpInfo = entity as PatientEmpInfo;

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

            BO.PatientEmpInfo PatientEmpInfoBO = new BO.PatientEmpInfo();
            PatientEmpInfoBO.ID                   = PatientEmpInfo.Id;
            PatientEmpInfoBO.CaseId               = PatientEmpInfo.CaseId;
            PatientEmpInfoBO.JobTitle             = PatientEmpInfo.JobTitle;
            PatientEmpInfoBO.EmpName              = PatientEmpInfo.EmpName;
            PatientEmpInfoBO.AddressInfoId        = PatientEmpInfo.AddressInfoId;
            PatientEmpInfoBO.ContactInfoId        = PatientEmpInfo.ContactInfoId;
            PatientEmpInfoBO.Salary               = PatientEmpInfo.Salary;
            PatientEmpInfoBO.HourOrYearly         = PatientEmpInfo.HourOrYearly;
            PatientEmpInfoBO.LossOfEarnings       = PatientEmpInfo.LossOfEarnings;
            PatientEmpInfoBO.DatesOutOfWork       = PatientEmpInfo.DatesOutOfWork;
            PatientEmpInfoBO.HoursPerWeek         = PatientEmpInfo.HoursPerWeek;
            PatientEmpInfoBO.AccidentAtEmployment = PatientEmpInfo.AccidentAtEmployment;

            if (PatientEmpInfo.AddressInfo != null)
            {
                if (PatientEmpInfo.AddressInfo.IsDeleted.HasValue == false || (PatientEmpInfo.AddressInfo.IsDeleted.HasValue == true && PatientEmpInfo.AddressInfo.IsDeleted.Value == false))
                {
                    BO.AddressInfo boAddress = new BO.AddressInfo();
                    boAddress.Name               = PatientEmpInfo.AddressInfo.Name;
                    boAddress.Address1           = PatientEmpInfo.AddressInfo.Address1;
                    boAddress.Address2           = PatientEmpInfo.AddressInfo.Address2;
                    boAddress.City               = PatientEmpInfo.AddressInfo.City;
                    boAddress.State              = PatientEmpInfo.AddressInfo.State;
                    boAddress.ZipCode            = PatientEmpInfo.AddressInfo.ZipCode;
                    boAddress.Country            = PatientEmpInfo.AddressInfo.Country;
                    boAddress.CreateByUserID     = PatientEmpInfo.AddressInfo.CreateByUserID;
                    boAddress.ID                 = PatientEmpInfo.AddressInfo.id;
                    PatientEmpInfoBO.AddressInfo = boAddress;
                }
            }

            if (PatientEmpInfo.ContactInfo != null)
            {
                if (PatientEmpInfo.ContactInfo.IsDeleted.HasValue == false || (PatientEmpInfo.ContactInfo.IsDeleted.HasValue == true && PatientEmpInfo.ContactInfo.IsDeleted.Value == false))
                {
                    BO.ContactInfo boContactInfo = new BO.ContactInfo();
                    boContactInfo.Name                   = PatientEmpInfo.ContactInfo.Name;
                    boContactInfo.CellPhone              = PatientEmpInfo.ContactInfo.CellPhone;
                    boContactInfo.EmailAddress           = PatientEmpInfo.ContactInfo.EmailAddress;
                    boContactInfo.HomePhone              = PatientEmpInfo.ContactInfo.HomePhone;
                    boContactInfo.WorkPhone              = PatientEmpInfo.ContactInfo.WorkPhone;
                    boContactInfo.FaxNo                  = PatientEmpInfo.ContactInfo.FaxNo;
                    boContactInfo.OfficeExtension        = PatientEmpInfo.ContactInfo.OfficeExtension;
                    boContactInfo.AlternateEmail         = PatientEmpInfo.ContactInfo.AlternateEmail;
                    boContactInfo.PreferredCommunication = PatientEmpInfo.ContactInfo.PreferredCommunication;
                    boContactInfo.CreateByUserID         = PatientEmpInfo.ContactInfo.CreateByUserID;
                    boContactInfo.ID             = PatientEmpInfo.ContactInfo.id;
                    PatientEmpInfoBO.ContactInfo = boContactInfo;
                }
            }

            //Common
            PatientEmpInfoBO.IsDeleted      = PatientEmpInfo.IsDeleted;
            PatientEmpInfoBO.CreateByUserID = PatientEmpInfo.CreateByUserID;
            PatientEmpInfoBO.UpdateByUserID = PatientEmpInfo.UpdateByUserID;

            return((T)(object)PatientEmpInfoBO);
        }
        public override object Save <T>(T entity)
        {
            BO.PatientEmpInfo patientEmpInfoBO = (BO.PatientEmpInfo)(object) entity;
            BO.AddressInfo    addressBO        = patientEmpInfoBO.AddressInfo;
            BO.ContactInfo    contactinfoBO    = patientEmpInfoBO.ContactInfo;

            PatientEmpInfo patientEmpInfoDB = new PatientEmpInfo();

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                bool IsEditMode = false;
                IsEditMode = (patientEmpInfoBO != null && patientEmpInfoBO.ID > 0) ? true : false;

                AddressInfo addressDB     = new AddressInfo();
                ContactInfo contactinfoDB = new ContactInfo();
                //User userDB = new User();

                #region Address
                if (addressBO != null)
                {
                    bool Add_addressDB = false;
                    addressDB = _context.AddressInfoes.Where(p => p.id == addressBO.ID).FirstOrDefault();

                    if (addressDB == null && addressBO.ID <= 0)
                    {
                        addressDB     = new AddressInfo();
                        Add_addressDB = true;
                    }
                    else if (addressDB == null && addressBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Address details dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    addressDB.Name     = IsEditMode == true && addressBO.Name == null ? addressDB.Name : addressBO.Name;
                    addressDB.Address1 = IsEditMode == true && addressBO.Address1 == null ? addressDB.Address1 : addressBO.Address1;
                    addressDB.Address2 = IsEditMode == true && addressBO.Address2 == null ? addressDB.Address2 : addressBO.Address2;
                    addressDB.City     = IsEditMode == true && addressBO.City == null ? addressDB.City : addressBO.City;
                    addressDB.State    = IsEditMode == true && addressBO.State == null ? addressDB.State : addressBO.State;
                    addressDB.ZipCode  = IsEditMode == true && addressBO.ZipCode == null ? addressDB.ZipCode : addressBO.ZipCode;
                    addressDB.Country  = IsEditMode == true && addressBO.Country == null ? addressDB.Country : addressBO.Country;
                    //[STATECODE-CHANGE]
                    //addressDB.StateCode = IsEditMode == true && addressBO.StateCode == null ? addressDB.StateCode : addressBO.StateCode;
                    //[STATECODE-CHANGE]

                    if (Add_addressDB == true)
                    {
                        addressDB = _context.AddressInfoes.Add(addressDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    if (IsEditMode == false)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Please pass valid address details.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    addressDB = null;
                }
                #endregion

                #region Contact Info
                if (contactinfoBO != null)
                {
                    bool Add_contactinfoDB = false;
                    contactinfoDB = _context.ContactInfoes.Where(p => p.id == contactinfoBO.ID).FirstOrDefault();

                    if (contactinfoDB == null && contactinfoBO.ID <= 0)
                    {
                        contactinfoDB     = new ContactInfo();
                        Add_contactinfoDB = true;
                    }
                    else if (contactinfoDB == null && contactinfoBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Contact details dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    contactinfoDB.Name                   = IsEditMode == true && contactinfoBO.Name == null ? contactinfoDB.Name : contactinfoBO.Name;
                    contactinfoDB.CellPhone              = IsEditMode == true && contactinfoBO.CellPhone == null ? contactinfoDB.CellPhone : contactinfoBO.CellPhone;
                    contactinfoDB.EmailAddress           = IsEditMode == true && contactinfoBO.EmailAddress == null ? contactinfoDB.EmailAddress : contactinfoBO.EmailAddress;
                    contactinfoDB.HomePhone              = IsEditMode == true && contactinfoBO.HomePhone == null ? contactinfoDB.HomePhone : contactinfoBO.HomePhone;
                    contactinfoDB.WorkPhone              = IsEditMode == true && contactinfoBO.WorkPhone == null ? contactinfoDB.WorkPhone : contactinfoBO.WorkPhone;
                    contactinfoDB.FaxNo                  = IsEditMode == true && contactinfoBO.FaxNo == null ? contactinfoDB.FaxNo : contactinfoBO.FaxNo;
                    contactinfoDB.OfficeExtension        = IsEditMode == true && contactinfoBO.OfficeExtension == null ? contactinfoDB.OfficeExtension : contactinfoBO.OfficeExtension;
                    contactinfoDB.AlternateEmail         = IsEditMode == true && contactinfoBO.AlternateEmail == null ? contactinfoDB.AlternateEmail : contactinfoBO.AlternateEmail;
                    contactinfoDB.PreferredCommunication = IsEditMode == true && contactinfoBO.PreferredCommunication == null ? contactinfoDB.PreferredCommunication : contactinfoBO.PreferredCommunication;
                    contactinfoDB.IsDeleted              = contactinfoBO.IsDeleted;

                    if (Add_contactinfoDB == true)
                    {
                        contactinfoDB = _context.ContactInfoes.Add(contactinfoDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    if (IsEditMode == false)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Please pass valid contact details.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    contactinfoDB = null;
                }
                #endregion

                #region patient Emp Info
                if (patientEmpInfoBO != null)
                {
                    bool Add_patientEmpInfoDB = false;
                    patientEmpInfoDB = _context.PatientEmpInfoes.Where(p => p.Id == patientEmpInfoBO.ID).FirstOrDefault();

                    if (patientEmpInfoDB == null && patientEmpInfoBO.ID <= 0)
                    {
                        patientEmpInfoDB     = new PatientEmpInfo();
                        Add_patientEmpInfoDB = true;
                    }
                    else if (patientEmpInfoDB == null && patientEmpInfoBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Patient employee information dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    patientEmpInfoDB.CaseId               = patientEmpInfoBO.CaseId;
                    patientEmpInfoDB.JobTitle             = IsEditMode == true && patientEmpInfoBO.JobTitle == null ? patientEmpInfoDB.JobTitle : patientEmpInfoBO.JobTitle;
                    patientEmpInfoDB.EmpName              = IsEditMode == true && patientEmpInfoBO.EmpName == null ? patientEmpInfoDB.EmpName : patientEmpInfoBO.EmpName;
                    patientEmpInfoDB.AddressInfoId        = (addressDB != null && addressDB.id > 0) ? addressDB.id : patientEmpInfoDB.AddressInfoId;
                    patientEmpInfoDB.ContactInfoId        = (contactinfoDB != null && contactinfoDB.id > 0) ? contactinfoDB.id : patientEmpInfoDB.ContactInfoId;
                    patientEmpInfoDB.Salary               = IsEditMode == true && patientEmpInfoBO.Salary == null ? patientEmpInfoDB.Salary : patientEmpInfoBO.Salary;
                    patientEmpInfoDB.HourOrYearly         = IsEditMode == true && patientEmpInfoBO.HourOrYearly == null ? patientEmpInfoDB.HourOrYearly : patientEmpInfoBO.HourOrYearly;
                    patientEmpInfoDB.LossOfEarnings       = IsEditMode == true && patientEmpInfoBO.LossOfEarnings == null ? patientEmpInfoDB.LossOfEarnings : patientEmpInfoBO.LossOfEarnings;
                    patientEmpInfoDB.DatesOutOfWork       = IsEditMode == true && patientEmpInfoBO.DatesOutOfWork == null ? patientEmpInfoDB.DatesOutOfWork : patientEmpInfoBO.DatesOutOfWork;
                    patientEmpInfoDB.HoursPerWeek         = IsEditMode == true && patientEmpInfoBO.HoursPerWeek == null ? patientEmpInfoDB.HoursPerWeek : patientEmpInfoBO.HoursPerWeek;
                    patientEmpInfoDB.AccidentAtEmployment = IsEditMode == true && patientEmpInfoBO.AccidentAtEmployment == null ? patientEmpInfoDB.AccidentAtEmployment : patientEmpInfoBO.AccidentAtEmployment;

                    if (Add_patientEmpInfoDB == true)
                    {
                        patientEmpInfoDB = _context.PatientEmpInfoes.Add(patientEmpInfoDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    if (IsEditMode == false)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Please pass valid patient employee information details.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    patientEmpInfoDB = null;
                }

                _context.SaveChanges();
                #endregion

                dbContextTransaction.Commit();

                patientEmpInfoDB = _context.PatientEmpInfoes.Include("addressInfo").Include("contactInfo").Where(p => p.Id == patientEmpInfoDB.Id).FirstOrDefault <PatientEmpInfo>();
            }

            var res = Convert <BO.PatientEmpInfo, PatientEmpInfo>(patientEmpInfoDB);
            return((object)res);
        }
        //public override object IsInsuranceInfoAdded(int id)
        //{
        //    var acc = _context.PatientInsuranceInfoes.Where(p => p.PatientId == id && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
        //                                             .FirstOrDefault<PatientInsuranceInfo>();

        //    if (acc == null)
        //    {
        //        return false;
        //    }
        //    else
        //    {
        //        return true;
        //    }
        //}
        #endregion


        #region save
        public override object Save <T>(T entity)
        {
            BO.PatientInsuranceInfo insuranceBO = (BO.PatientInsuranceInfo)(object) entity;
            BO.AddressInfo          addressinfoPolicyHolderBO     = insuranceBO.AddressInfo1;
            BO.ContactInfo          contactinfoPolicyHolderBO     = insuranceBO.ContactInfo1;
            BO.AddressInfo          addressinfoInsuranceCompanyBO = insuranceBO.AddressInfo;
            BO.ContactInfo          contactinfoInsuranceCompanyBO = insuranceBO.ContactInfo;

            PatientInsuranceInfo insuranceDB = new PatientInsuranceInfo();

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                bool IsEditMode = false;
                IsEditMode = (insuranceBO != null && insuranceBO.ID > 0) ? true : false;

                AddressInfo addressinfoPolicyHolderDB     = new AddressInfo();
                ContactInfo contactinfoPolicyHolderDB     = new ContactInfo();
                AddressInfo addressinfoInsuranceCompanyDB = new AddressInfo();
                ContactInfo contactinfoInsuranceCompanyDB = new ContactInfo();

                User userDB = new User();

                #region Address Poliy Holder
                if (addressinfoPolicyHolderBO != null)
                {
                    bool Add_addressDB = false;
                    addressinfoPolicyHolderDB = _context.AddressInfoes.Where(p => p.id == addressinfoPolicyHolderBO.ID).FirstOrDefault();

                    if (addressinfoPolicyHolderDB == null && addressinfoPolicyHolderBO.ID <= 0)
                    {
                        addressinfoPolicyHolderDB = new AddressInfo();
                        Add_addressDB             = true;
                    }
                    else if (addressinfoPolicyHolderDB == null && addressinfoPolicyHolderBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Policy address details dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    addressinfoPolicyHolderDB.Name     = IsEditMode == true && addressinfoPolicyHolderBO.Name == null ? addressinfoPolicyHolderDB.Name : addressinfoPolicyHolderBO.Name;
                    addressinfoPolicyHolderDB.Address1 = IsEditMode == true && addressinfoPolicyHolderBO.Address1 == null ? addressinfoPolicyHolderDB.Address1 : addressinfoPolicyHolderBO.Address1;
                    addressinfoPolicyHolderDB.Address2 = IsEditMode == true && addressinfoPolicyHolderBO.Address2 == null ? addressinfoPolicyHolderDB.Address2 : addressinfoPolicyHolderBO.Address2;
                    addressinfoPolicyHolderDB.City     = IsEditMode == true && addressinfoPolicyHolderBO.City == null ? addressinfoPolicyHolderDB.City : addressinfoPolicyHolderBO.City;
                    addressinfoPolicyHolderDB.State    = IsEditMode == true && addressinfoPolicyHolderBO.State == null ? addressinfoPolicyHolderDB.State : addressinfoPolicyHolderBO.State;
                    addressinfoPolicyHolderDB.ZipCode  = IsEditMode == true && addressinfoPolicyHolderBO.ZipCode == null ? addressinfoPolicyHolderDB.ZipCode : addressinfoPolicyHolderBO.ZipCode;
                    addressinfoPolicyHolderDB.Country  = IsEditMode == true && addressinfoPolicyHolderBO.Country == null ? addressinfoPolicyHolderDB.Country : addressinfoPolicyHolderBO.Country;
                    //[STATECODE-CHANGE]
                    //addressinfoPolicyHolderDB.StateCode = IsEditMode == true && addressinfoPolicyHolderBO.StateCode == null ? addressinfoPolicyHolderDB.StateCode : addressinfoPolicyHolderBO.StateCode;
                    //[STATECODE-CHANGE]

                    if (Add_addressDB == true)
                    {
                        addressinfoPolicyHolderDB = _context.AddressInfoes.Add(addressinfoPolicyHolderDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    if (IsEditMode == false)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Please pass valid policy address details.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    addressinfoPolicyHolderDB = null;
                }
                #endregion

                #region Contact Info Policy Holder
                if (contactinfoPolicyHolderBO != null)
                {
                    bool Add_contactinfoDB = false;
                    contactinfoPolicyHolderDB = _context.ContactInfoes.Where(p => p.id == contactinfoPolicyHolderBO.ID).FirstOrDefault();

                    if (contactinfoPolicyHolderDB == null && contactinfoPolicyHolderBO.ID <= 0)
                    {
                        contactinfoPolicyHolderDB = new ContactInfo();
                        Add_contactinfoDB         = true;
                    }
                    else if (contactinfoPolicyHolderDB == null && contactinfoPolicyHolderBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Policy contact details dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    contactinfoPolicyHolderDB.Name                   = IsEditMode == true && contactinfoPolicyHolderBO.Name == null ? contactinfoPolicyHolderDB.Name : contactinfoPolicyHolderBO.Name;
                    contactinfoPolicyHolderDB.CellPhone              = IsEditMode == true && contactinfoPolicyHolderBO.CellPhone == null ? contactinfoPolicyHolderDB.CellPhone : contactinfoPolicyHolderBO.CellPhone;
                    contactinfoPolicyHolderDB.EmailAddress           = IsEditMode == true && contactinfoPolicyHolderBO.EmailAddress == null ? contactinfoPolicyHolderDB.EmailAddress : contactinfoPolicyHolderBO.EmailAddress;
                    contactinfoPolicyHolderDB.HomePhone              = IsEditMode == true && contactinfoPolicyHolderBO.HomePhone == null ? contactinfoPolicyHolderDB.HomePhone : contactinfoPolicyHolderBO.HomePhone;
                    contactinfoPolicyHolderDB.WorkPhone              = IsEditMode == true && contactinfoPolicyHolderBO.WorkPhone == null ? contactinfoPolicyHolderDB.WorkPhone : contactinfoPolicyHolderBO.WorkPhone;
                    contactinfoPolicyHolderDB.FaxNo                  = IsEditMode == true && contactinfoPolicyHolderBO.FaxNo == null ? contactinfoPolicyHolderDB.FaxNo : contactinfoPolicyHolderBO.FaxNo;
                    contactinfoPolicyHolderDB.OfficeExtension        = IsEditMode == true && contactinfoPolicyHolderBO.OfficeExtension == null ? contactinfoPolicyHolderDB.OfficeExtension : contactinfoPolicyHolderBO.OfficeExtension;
                    contactinfoPolicyHolderDB.AlternateEmail         = IsEditMode == true && contactinfoPolicyHolderBO.AlternateEmail == null ? contactinfoPolicyHolderDB.AlternateEmail : contactinfoPolicyHolderBO.AlternateEmail;
                    contactinfoPolicyHolderDB.PreferredCommunication = IsEditMode == true && contactinfoPolicyHolderBO.PreferredCommunication == null ? contactinfoPolicyHolderDB.PreferredCommunication : contactinfoPolicyHolderBO.PreferredCommunication;
                    contactinfoPolicyHolderDB.IsDeleted              = contactinfoPolicyHolderBO.IsDeleted;

                    if (Add_contactinfoDB == true)
                    {
                        contactinfoPolicyHolderDB = _context.ContactInfoes.Add(contactinfoPolicyHolderDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    if (IsEditMode == false)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Please pass valid policy contact details.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    contactinfoPolicyHolderDB = null;
                }
                #endregion

                #region Address Insurance Company
                if (addressinfoInsuranceCompanyBO != null)
                {
                    bool Add_addressDB = false;
                    addressinfoInsuranceCompanyDB = _context.AddressInfoes.Where(p => p.id == addressinfoInsuranceCompanyBO.ID).FirstOrDefault();

                    if (addressinfoInsuranceCompanyDB == null && addressinfoInsuranceCompanyBO.ID <= 0)
                    {
                        addressinfoInsuranceCompanyDB = new AddressInfo();
                        Add_addressDB = true;
                    }
                    else if (addressinfoInsuranceCompanyDB == null && addressinfoInsuranceCompanyBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Insurance address details dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    addressinfoInsuranceCompanyDB.id       = addressinfoInsuranceCompanyBO.ID;
                    addressinfoInsuranceCompanyDB.Name     = IsEditMode == true && addressinfoInsuranceCompanyBO.Name == null ? addressinfoInsuranceCompanyDB.Name : addressinfoInsuranceCompanyBO.Name;
                    addressinfoInsuranceCompanyDB.Address1 = IsEditMode == true && addressinfoInsuranceCompanyBO.Address1 == null ? addressinfoInsuranceCompanyDB.Address1 : addressinfoInsuranceCompanyBO.Address1;
                    addressinfoInsuranceCompanyDB.Address2 = IsEditMode == true && addressinfoInsuranceCompanyBO.Address2 == null ? addressinfoInsuranceCompanyDB.Address2 : addressinfoInsuranceCompanyBO.Address2;
                    addressinfoInsuranceCompanyDB.City     = IsEditMode == true && addressinfoInsuranceCompanyBO.City == null ? addressinfoInsuranceCompanyDB.City : addressinfoInsuranceCompanyBO.City;
                    addressinfoInsuranceCompanyDB.State    = IsEditMode == true && addressinfoInsuranceCompanyBO.State == null ? addressinfoInsuranceCompanyDB.State : addressinfoInsuranceCompanyBO.State;
                    addressinfoInsuranceCompanyDB.ZipCode  = IsEditMode == true && addressinfoInsuranceCompanyBO.ZipCode == null ? addressinfoInsuranceCompanyDB.ZipCode : addressinfoInsuranceCompanyBO.ZipCode;
                    addressinfoInsuranceCompanyDB.Country  = IsEditMode == true && addressinfoInsuranceCompanyBO.Country == null ? addressinfoInsuranceCompanyDB.Country : addressinfoInsuranceCompanyBO.Country;
                    //[STATECODE-CHANGE]
                    //addressinfoInsuranceCompanyDB.StateCode = IsEditMode == true && addressinfoInsuranceCompanyBO.StateCode == null ? addressinfoInsuranceCompanyDB.StateCode : addressinfoInsuranceCompanyBO.StateCode;
                    //[STATECODE-CHANGE]

                    if (Add_addressDB == true)
                    {
                        addressinfoInsuranceCompanyDB = _context.AddressInfoes.Add(addressinfoInsuranceCompanyDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    //if (IsEditMode == false)
                    //{
                    //    dbContextTransaction.Rollback();
                    //    return new BO.ErrorObject { errorObject = "", ErrorMessage = "Please pass valid insurance address details.", ErrorLevel = ErrorLevel.Error };
                    //}
                    addressinfoInsuranceCompanyDB = null;
                }
                #endregion

                #region Contact Info Insurance Company
                if (contactinfoInsuranceCompanyBO != null)
                {
                    bool Add_contactinfoDB = false;
                    contactinfoInsuranceCompanyDB = _context.ContactInfoes.Where(p => p.id == contactinfoInsuranceCompanyBO.ID).FirstOrDefault();

                    if (contactinfoInsuranceCompanyDB == null && contactinfoInsuranceCompanyBO.ID <= 0)
                    {
                        contactinfoInsuranceCompanyDB = new ContactInfo();
                        Add_contactinfoDB             = true;
                    }
                    else if (contactinfoInsuranceCompanyDB == null && contactinfoInsuranceCompanyBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Insurance contact details dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    contactinfoInsuranceCompanyDB.Name                   = IsEditMode == true && contactinfoInsuranceCompanyBO.Name == null ? contactinfoInsuranceCompanyDB.Name : contactinfoInsuranceCompanyBO.Name;
                    contactinfoInsuranceCompanyDB.CellPhone              = IsEditMode == true && contactinfoInsuranceCompanyBO.CellPhone == null ? contactinfoInsuranceCompanyDB.CellPhone : contactinfoInsuranceCompanyBO.CellPhone;
                    contactinfoInsuranceCompanyDB.EmailAddress           = IsEditMode == true && contactinfoInsuranceCompanyBO.EmailAddress == null ? contactinfoInsuranceCompanyDB.EmailAddress : contactinfoInsuranceCompanyBO.EmailAddress;
                    contactinfoInsuranceCompanyDB.HomePhone              = IsEditMode == true && contactinfoInsuranceCompanyBO.HomePhone == null ? contactinfoInsuranceCompanyDB.HomePhone : contactinfoInsuranceCompanyBO.HomePhone;
                    contactinfoInsuranceCompanyDB.WorkPhone              = IsEditMode == true && contactinfoInsuranceCompanyBO.WorkPhone == null ? contactinfoInsuranceCompanyDB.WorkPhone : contactinfoInsuranceCompanyBO.WorkPhone;
                    contactinfoInsuranceCompanyDB.FaxNo                  = IsEditMode == true && contactinfoInsuranceCompanyBO.FaxNo == null ? contactinfoInsuranceCompanyDB.FaxNo : contactinfoInsuranceCompanyBO.FaxNo;
                    contactinfoInsuranceCompanyDB.OfficeExtension        = IsEditMode == true && contactinfoInsuranceCompanyBO.OfficeExtension == null ? contactinfoInsuranceCompanyDB.OfficeExtension : contactinfoInsuranceCompanyBO.OfficeExtension;
                    contactinfoInsuranceCompanyDB.AlternateEmail         = IsEditMode == true && contactinfoInsuranceCompanyBO.AlternateEmail == null ? contactinfoInsuranceCompanyDB.AlternateEmail : contactinfoInsuranceCompanyBO.AlternateEmail;
                    contactinfoInsuranceCompanyDB.PreferredCommunication = IsEditMode == true && contactinfoInsuranceCompanyBO.PreferredCommunication == null ? contactinfoInsuranceCompanyDB.PreferredCommunication : contactinfoInsuranceCompanyBO.PreferredCommunication;
                    contactinfoInsuranceCompanyDB.IsDeleted              = contactinfoInsuranceCompanyBO.IsDeleted;

                    if (Add_contactinfoDB == true)
                    {
                        contactinfoInsuranceCompanyDB = _context.ContactInfoes.Add(contactinfoInsuranceCompanyDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    if (IsEditMode == false)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Please pass valid insurance contact details.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    contactinfoInsuranceCompanyDB = null;
                }
                #endregion

                #region insurance
                if (insuranceBO != null)
                {
                    bool Add_insuranceDB = false;
                    insuranceDB = _context.PatientInsuranceInfoes.Where(p => p.Id == insuranceBO.ID).FirstOrDefault <PatientInsuranceInfo>();

                    if (insuranceDB == null && insuranceBO.ID <= 0)
                    {
                        insuranceDB     = new PatientInsuranceInfo();
                        Add_insuranceDB = true;
                    }
                    else if (insuranceDB == null && insuranceBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Patient Insurance dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    insuranceDB.CaseId                        = insuranceBO.CaseId;
                    insuranceDB.PolicyHolderName              = IsEditMode == true && insuranceBO.PolicyHoldersName == null ? insuranceDB.PolicyHolderName : insuranceBO.PolicyHoldersName;
                    insuranceDB.PolicyHolderAddressInfoId     = (addressinfoPolicyHolderDB != null && addressinfoPolicyHolderDB.id > 0) ? addressinfoPolicyHolderDB.id : insuranceDB.PolicyHolderAddressInfoId;
                    insuranceDB.PolicyHolderContactInfoId     = (contactinfoPolicyHolderDB != null && contactinfoPolicyHolderDB.id > 0) ? contactinfoPolicyHolderDB.id : insuranceDB.PolicyHolderContactInfoId;
                    insuranceDB.PolicyOwnerId                 = IsEditMode == true && insuranceBO.PolicyOwnerId == null ? insuranceDB.PolicyOwnerId : insuranceBO.PolicyOwnerId;
                    insuranceDB.InsuranceCompanyCode          = IsEditMode == true && insuranceBO.InsuranceCompanyCode == null ? insuranceDB.InsuranceCompanyCode : insuranceBO.InsuranceCompanyCode;
                    insuranceDB.InsuranceCompanyAddressInfoId = (addressinfoInsuranceCompanyDB != null && addressinfoInsuranceCompanyDB.id > 0) ? addressinfoInsuranceCompanyDB.id : insuranceDB.InsuranceCompanyAddressInfoId;
                    insuranceDB.InsuranceCompanyContactInfoId = (contactinfoInsuranceCompanyDB != null && contactinfoInsuranceCompanyDB.id > 0) ? contactinfoInsuranceCompanyDB.id : insuranceDB.InsuranceCompanyContactInfoId;
                    insuranceDB.PolicyNo                      = IsEditMode == true && insuranceBO.PolicyNo == null ? insuranceDB.PolicyNo : insuranceBO.PolicyNo;
                    insuranceDB.ContactPerson                 = IsEditMode == true && insuranceBO.ContactPerson == null ? insuranceDB.ContactPerson : insuranceBO.ContactPerson;
                    insuranceDB.InsuranceTypeId               = IsEditMode == true && insuranceBO.InsuranceTypeId == null ? insuranceDB.InsuranceTypeId : insuranceBO.InsuranceTypeId;
                    insuranceDB.IsInActive                    = insuranceBO.IsInActive;

                    //insuranceDB.InsuranceMasterId = IsEditMode == true && insuranceBO.InsuranceMasterId == null ? insuranceDB.InsuranceMasterId : insuranceBO.InsuranceMasterId;
                    InsuranceMaster InsuranceMasterDB = _context.InsuranceMasters.Where(p => insuranceBO.InsuranceMasterId.HasValue == true && p.Id == insuranceBO.InsuranceMasterId).FirstOrDefault();
                    if (InsuranceMasterDB != null)
                    {
                        insuranceDB.InsuranceMasterId = insuranceBO.InsuranceMasterId;
                    }
                    else
                    {
                        if (IsEditMode == false)
                        {
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                errorObject = "", ErrorMessage = "Please pass valid Insurance Master Id.", ErrorLevel = ErrorLevel.Error
                            });
                        }
                    }

                    if (Add_insuranceDB == true)
                    {
                        insuranceDB = _context.PatientInsuranceInfoes.Add(insuranceDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    if (IsEditMode == false)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Please pass valid Patient Insurance details.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    insuranceDB = null;
                }

                _context.SaveChanges();
                #endregion

                dbContextTransaction.Commit();

                insuranceDB = _context.PatientInsuranceInfoes.Include("InsuranceMaster").Where(p => p.Id == insuranceDB.Id).FirstOrDefault <PatientInsuranceInfo>();
            }

            var res = Convert <BO.PatientInsuranceInfo, PatientInsuranceInfo>(insuranceDB);
            return((object)res);
        }
        public override T Convert <T, U>(U entity)
        {
            PatientInsuranceInfo InsuranceInfos = entity as PatientInsuranceInfo;

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

            BO.PatientInsuranceInfo insuranceBO = new BO.PatientInsuranceInfo();
            insuranceBO.ID                        = InsuranceInfos.Id;
            insuranceBO.CaseId                    = InsuranceInfos.CaseId;
            insuranceBO.PolicyHoldersName         = InsuranceInfos.PolicyHolderName;
            insuranceBO.PolicyHolderAddressInfoId = InsuranceInfos.PolicyHolderAddressInfoId;
            insuranceBO.PolicyHolderContactInfoId = InsuranceInfos.PolicyHolderContactInfoId;
            insuranceBO.PolicyOwnerId             = InsuranceInfos.PolicyOwnerId;

            insuranceBO.InsuranceMasterId = InsuranceInfos.InsuranceMasterId;

            insuranceBO.InsuranceCompanyCode          = InsuranceInfos.InsuranceCompanyCode;
            insuranceBO.InsuranceCompanyAddressInfoId = InsuranceInfos.InsuranceCompanyAddressInfoId;
            insuranceBO.InsuranceCompanyContactInfoId = InsuranceInfos.InsuranceCompanyContactInfoId;
            insuranceBO.PolicyNo        = InsuranceInfos.PolicyNo;
            insuranceBO.ContactPerson   = InsuranceInfos.ContactPerson;
            insuranceBO.InsuranceTypeId = InsuranceInfos.InsuranceTypeId;
            insuranceBO.IsInActive      = InsuranceInfos.IsInActive;

            if (InsuranceInfos.AddressInfo != null)
            {
                if (InsuranceInfos.AddressInfo.IsDeleted.HasValue == false || (InsuranceInfos.AddressInfo.IsDeleted.HasValue == true && InsuranceInfos.AddressInfo.IsDeleted.Value == false))
                {
                    BO.AddressInfo boAddress = new BO.AddressInfo();
                    boAddress.Name     = InsuranceInfos.AddressInfo.Name;
                    boAddress.Address1 = InsuranceInfos.AddressInfo.Address1;
                    boAddress.Address2 = InsuranceInfos.AddressInfo.Address2;
                    boAddress.City     = InsuranceInfos.AddressInfo.City;
                    boAddress.State    = InsuranceInfos.AddressInfo.State;
                    boAddress.ZipCode  = InsuranceInfos.AddressInfo.ZipCode;
                    boAddress.Country  = InsuranceInfos.AddressInfo.Country;
                    //[STATECODE-CHANGE]
                    //boAddress.StateCode = InsuranceInfos.AddressInfo.StateCode;
                    //[STATECODE-CHANGE]
                    boAddress.CreateByUserID = InsuranceInfos.AddressInfo.CreateByUserID;
                    boAddress.ID             = InsuranceInfos.AddressInfo.id;
                    insuranceBO.AddressInfo  = boAddress;
                }
            }

            if (InsuranceInfos.ContactInfo != null)
            {
                if (InsuranceInfos.ContactInfo.IsDeleted.HasValue == false || (InsuranceInfos.ContactInfo.IsDeleted.HasValue == true && InsuranceInfos.ContactInfo.IsDeleted.Value == false))
                {
                    BO.ContactInfo boContactInfo = new BO.ContactInfo();
                    boContactInfo.Name                   = InsuranceInfos.ContactInfo.Name;
                    boContactInfo.CellPhone              = InsuranceInfos.ContactInfo.CellPhone;
                    boContactInfo.EmailAddress           = InsuranceInfos.ContactInfo.EmailAddress;
                    boContactInfo.HomePhone              = InsuranceInfos.ContactInfo.HomePhone;
                    boContactInfo.WorkPhone              = InsuranceInfos.ContactInfo.WorkPhone;
                    boContactInfo.FaxNo                  = InsuranceInfos.ContactInfo.FaxNo;
                    boContactInfo.OfficeExtension        = InsuranceInfos.ContactInfo.OfficeExtension;
                    boContactInfo.AlternateEmail         = InsuranceInfos.ContactInfo.AlternateEmail;
                    boContactInfo.PreferredCommunication = InsuranceInfos.ContactInfo.PreferredCommunication;
                    boContactInfo.CreateByUserID         = InsuranceInfos.ContactInfo.CreateByUserID;
                    boContactInfo.ID        = InsuranceInfos.ContactInfo.id;
                    insuranceBO.ContactInfo = boContactInfo;
                }
            }

            if (InsuranceInfos.AddressInfo1 != null)
            {
                if (InsuranceInfos.AddressInfo1.IsDeleted.HasValue == false || (InsuranceInfos.AddressInfo1.IsDeleted.HasValue == true && InsuranceInfos.AddressInfo1.IsDeleted.Value == false))
                {
                    BO.AddressInfo boAddress1 = new BO.AddressInfo();
                    boAddress1.Name     = InsuranceInfos.AddressInfo1.Name;
                    boAddress1.Address1 = InsuranceInfos.AddressInfo1.Address1;
                    boAddress1.Address2 = InsuranceInfos.AddressInfo1.Address2;
                    boAddress1.City     = InsuranceInfos.AddressInfo1.City;
                    boAddress1.State    = InsuranceInfos.AddressInfo1.State;
                    boAddress1.ZipCode  = InsuranceInfos.AddressInfo1.ZipCode;
                    boAddress1.Country  = InsuranceInfos.AddressInfo1.Country;
                    //[STATECODE-CHANGE]
                    //boAddress1.StateCode = InsuranceInfos.AddressInfo1.StateCode;
                    //[STATECODE-CHANGE]
                    boAddress1.CreateByUserID = InsuranceInfos.AddressInfo1.CreateByUserID;
                    boAddress1.ID             = InsuranceInfos.AddressInfo1.id;
                    insuranceBO.AddressInfo1  = boAddress1;
                }
            }

            if (InsuranceInfos.ContactInfo1 != null)
            {
                if (InsuranceInfos.ContactInfo1.IsDeleted.HasValue == false || (InsuranceInfos.ContactInfo1.IsDeleted.HasValue == true && InsuranceInfos.ContactInfo1.IsDeleted.Value == false))
                {
                    BO.ContactInfo boContactInfo1 = new BO.ContactInfo();
                    boContactInfo1.Name                   = InsuranceInfos.ContactInfo1.Name;
                    boContactInfo1.CellPhone              = InsuranceInfos.ContactInfo1.CellPhone;
                    boContactInfo1.EmailAddress           = InsuranceInfos.ContactInfo1.EmailAddress;
                    boContactInfo1.HomePhone              = InsuranceInfos.ContactInfo1.HomePhone;
                    boContactInfo1.WorkPhone              = InsuranceInfos.ContactInfo1.WorkPhone;
                    boContactInfo1.FaxNo                  = InsuranceInfos.ContactInfo1.FaxNo;
                    boContactInfo1.OfficeExtension        = InsuranceInfos.ContactInfo1.OfficeExtension;
                    boContactInfo1.AlternateEmail         = InsuranceInfos.ContactInfo1.AlternateEmail;
                    boContactInfo1.PreferredCommunication = InsuranceInfos.ContactInfo1.PreferredCommunication;
                    boContactInfo1.CreateByUserID         = InsuranceInfos.ContactInfo1.CreateByUserID;
                    boContactInfo1.ID        = InsuranceInfos.ContactInfo1.id;
                    insuranceBO.ContactInfo1 = boContactInfo1;
                }
            }


            if (InsuranceInfos.InsuranceMaster != null)
            {
                if (InsuranceInfos.InsuranceMaster.IsDeleted.HasValue == false || (InsuranceInfos.InsuranceMaster.IsDeleted.HasValue == true && InsuranceInfos.InsuranceMaster.IsDeleted.Value == false))
                {
                    BO.InsuranceMaster boInsuranceMaster = new BO.InsuranceMaster();
                    using (InsuranceMasterRepository cmp = new InsuranceMasterRepository(_context))
                    {
                        boInsuranceMaster           = cmp.ObjectConvert <BO.InsuranceMaster, InsuranceMaster>(InsuranceInfos.InsuranceMaster);
                        insuranceBO.InsuranceMaster = boInsuranceMaster;
                    }
                }
            }

            if (InsuranceInfos.InsuranceType != null)
            {
                if (InsuranceInfos.InsuranceType.IsDeleted.HasValue == false || (InsuranceInfos.InsuranceType.IsDeleted.HasValue == true && InsuranceInfos.InsuranceType.IsDeleted.Value == false))
                {
                    BO.InsuranceType boInsuranceType = new BO.InsuranceType();

                    boInsuranceType.InsuranceTypeText = InsuranceInfos.InsuranceType.InsuranceTypeText;
                    insuranceBO.InsuranceType         = boInsuranceType;
                }
            }


            insuranceBO.IsDeleted      = InsuranceInfos.IsDeleted;
            insuranceBO.CreateByUserID = InsuranceInfos.CreateByUserID;
            insuranceBO.UpdateByUserID = InsuranceInfos.UpdateByUserID;

            return((T)(object)insuranceBO);
        }
        public override T Convert <T, U>(U entity)
        {
            List <InsuranceMaster> insuranceMaster = entity as List <InsuranceMaster>;

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

            List <BO.InsuranceMaster> boInsuranceMasters = new List <BO.InsuranceMaster>();

            foreach (var eachInsuranceMaster in insuranceMaster)
            {
                BO.InsuranceMaster boInsuranceMaster = new BO.InsuranceMaster();

                boInsuranceMaster.ID                 = eachInsuranceMaster.Id;
                boInsuranceMaster.CompanyCode        = eachInsuranceMaster.CompanyCode;
                boInsuranceMaster.CompanyName        = eachInsuranceMaster.CompanyName;
                boInsuranceMaster.AddressInfoId      = eachInsuranceMaster.AddressInfoId;
                boInsuranceMaster.ContactInfoId      = eachInsuranceMaster.ContactInfoId;
                boInsuranceMaster.ZeusID             = eachInsuranceMaster.ZeusID;
                boInsuranceMaster.PriorityBilling    = eachInsuranceMaster.PriorityBilling;
                boInsuranceMaster.Only1500Form       = eachInsuranceMaster.Only1500Form;
                boInsuranceMaster.PaperAuthorization = eachInsuranceMaster.PaperAuthorization;
                boInsuranceMaster.CreatedByCompanyId = eachInsuranceMaster.CreatedByCompanyId;

                //if (eachInsuranceMaster.IsDeleted.HasValue)
                //    boInsuranceMaster.IsDeleted = eachInsuranceMaster.IsDeleted.Value;

                if (eachInsuranceMaster.AddressInfo != null)
                {
                    BO.AddressInfo boAddress = new BO.AddressInfo();
                    boAddress.Name     = eachInsuranceMaster.AddressInfo.Name;
                    boAddress.Address1 = eachInsuranceMaster.AddressInfo.Address1;
                    boAddress.Address2 = eachInsuranceMaster.AddressInfo.Address2;
                    boAddress.City     = eachInsuranceMaster.AddressInfo.City;
                    boAddress.State    = eachInsuranceMaster.AddressInfo.State;
                    boAddress.ZipCode  = eachInsuranceMaster.AddressInfo.ZipCode;
                    boAddress.Country  = eachInsuranceMaster.AddressInfo.Country;
                    //[STATECODE-CHANGE]
                    //boAddress.StateCode = eachInsuranceMaster.AddressInfo.StateCode;
                    //[STATECODE-CHANGE]
                    boAddress.CreateByUserID      = eachInsuranceMaster.AddressInfo.CreateByUserID;
                    boAddress.ID                  = eachInsuranceMaster.AddressInfo.id;
                    boInsuranceMaster.AddressInfo = boAddress;
                }

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

                boInsuranceMaster.IsDeleted      = eachInsuranceMaster.IsDeleted;
                boInsuranceMaster.CreateByUserID = eachInsuranceMaster.CreateByUserID;
                boInsuranceMaster.UpdateByUserID = eachInsuranceMaster.UpdateByUserID;

                boInsuranceMasters.Add(boInsuranceMaster);
            }

            return((T)(object)boInsuranceMasters);
        }
        public override object Save <T>(T entity)
        {
            BO.InsuranceMaster insuranceMasterBO = (BO.InsuranceMaster)(object) entity;
            BO.AddressInfo     addressBO         = insuranceMasterBO.AddressInfo;
            BO.ContactInfo     contactinfoBO     = insuranceMasterBO.ContactInfo;

            if (insuranceMasterBO.CreatedByCompanyId.HasValue == true)
            {
                InsuranceMaster insuranceMasterDB = new InsuranceMaster();

                using (var dbContextTransaction = _context.Database.BeginTransaction())
                {
                    bool IsEditMode = false;
                    IsEditMode = (insuranceMasterBO != null && insuranceMasterBO.ID > 0) ? true : false;

                    AddressInfo addressDB     = new AddressInfo();
                    ContactInfo contactinfoDB = new ContactInfo();

                    #region Address
                    if (addressBO != null)
                    {
                        bool Add_addressDB = false;
                        addressDB = _context.AddressInfoes.Where(p => p.id == addressBO.ID && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault();

                        if (addressDB == null && addressBO.ID <= 0)
                        {
                            addressDB     = new AddressInfo();
                            Add_addressDB = true;
                        }
                        else if (addressDB == null && addressBO.ID > 0)
                        {
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                errorObject = "", ErrorMessage = "Address details dosent exists.", ErrorLevel = ErrorLevel.Error
                            });
                        }

                        addressDB.Name     = IsEditMode == true && addressBO.Name == null ? addressDB.Name : addressBO.Name;
                        addressDB.Address1 = IsEditMode == true && addressBO.Address1 == null ? addressDB.Address1 : addressBO.Address1;
                        addressDB.Address2 = IsEditMode == true && addressBO.Address2 == null ? addressDB.Address2 : addressBO.Address2;
                        addressDB.City     = IsEditMode == true && addressBO.City == null ? addressDB.City : addressBO.City;
                        addressDB.State    = IsEditMode == true && addressBO.State == null ? addressDB.State : addressBO.State;
                        addressDB.ZipCode  = IsEditMode == true && addressBO.ZipCode == null ? addressDB.ZipCode : addressBO.ZipCode;
                        addressDB.Country  = IsEditMode == true && addressBO.Country == null ? addressDB.Country : addressBO.Country;
                        //[STATECODE-CHANGE]
                        //addressDB.StateCode = IsEditMode == true && addressBO.StateCode == null ? addressDB.StateCode : addressBO.StateCode;
                        //[STATECODE-CHANGE]

                        if (Add_addressDB == true)
                        {
                            addressDB = _context.AddressInfoes.Add(addressDB);
                        }
                        _context.SaveChanges();
                    }
                    else
                    {
                        if (IsEditMode == false)
                        {
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                errorObject = "", ErrorMessage = "Please pass valid address details.", ErrorLevel = ErrorLevel.Error
                            });
                        }
                        addressDB = null;
                    }
                    #endregion

                    #region Contact Info
                    if (contactinfoBO != null)
                    {
                        bool Add_contactinfoDB = false;
                        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 && contactinfoBO.ID <= 0)
                        {
                            contactinfoDB     = new ContactInfo();
                            Add_contactinfoDB = true;
                        }
                        else if (contactinfoDB == null && contactinfoBO.ID > 0)
                        {
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                errorObject = "", ErrorMessage = "Contact details dosent exists.", ErrorLevel = ErrorLevel.Error
                            });
                        }

                        contactinfoDB.Name                   = IsEditMode == true && contactinfoBO.Name == null ? contactinfoDB.Name : contactinfoBO.Name;
                        contactinfoDB.CellPhone              = IsEditMode == true && contactinfoBO.CellPhone == null ? contactinfoDB.CellPhone : contactinfoBO.CellPhone;
                        contactinfoDB.EmailAddress           = IsEditMode == true && contactinfoBO.EmailAddress == null ? contactinfoDB.EmailAddress : contactinfoBO.EmailAddress;
                        contactinfoDB.HomePhone              = IsEditMode == true && contactinfoBO.HomePhone == null ? contactinfoDB.HomePhone : contactinfoBO.HomePhone;
                        contactinfoDB.WorkPhone              = IsEditMode == true && contactinfoBO.WorkPhone == null ? contactinfoDB.WorkPhone : contactinfoBO.WorkPhone;
                        contactinfoDB.FaxNo                  = IsEditMode == true && contactinfoBO.FaxNo == null ? contactinfoDB.FaxNo : contactinfoBO.FaxNo;
                        contactinfoDB.OfficeExtension        = IsEditMode == true && contactinfoBO.OfficeExtension == null ? contactinfoDB.OfficeExtension : contactinfoBO.OfficeExtension;
                        contactinfoDB.AlternateEmail         = IsEditMode == true && contactinfoBO.AlternateEmail == null ? contactinfoDB.AlternateEmail : contactinfoBO.AlternateEmail;
                        contactinfoDB.PreferredCommunication = IsEditMode == true && contactinfoBO.PreferredCommunication == null ? contactinfoDB.PreferredCommunication : contactinfoBO.PreferredCommunication;
                        contactinfoDB.IsDeleted              = contactinfoBO.IsDeleted;

                        if (Add_contactinfoDB == true)
                        {
                            contactinfoDB = _context.ContactInfoes.Add(contactinfoDB);
                        }
                        _context.SaveChanges();
                    }
                    else
                    {
                        if (IsEditMode == false)
                        {
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                errorObject = "", ErrorMessage = "Please pass valid contact details.", ErrorLevel = ErrorLevel.Error
                            });
                        }
                        contactinfoDB = null;
                    }
                    #endregion

                    #region Insurance Master
                    if (insuranceMasterBO != null)
                    {
                        bool Add_insuranceMasterDB = false;
                        insuranceMasterDB = _context.InsuranceMasters.Where(p => p.Id == insuranceMasterBO.ID && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault <InsuranceMaster>();

                        if (insuranceMasterDB == null && insuranceMasterBO.ID <= 0)
                        {
                            insuranceMasterDB     = new InsuranceMaster();
                            Add_insuranceMasterDB = true;
                        }
                        else if (insuranceMasterDB == null && insuranceMasterBO.ID > 0)
                        {
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                errorObject = "", ErrorMessage = "Insurance Master information dosent exists.", ErrorLevel = ErrorLevel.Error
                            });
                        }

                        insuranceMasterDB.CompanyCode        = insuranceMasterBO.CompanyCode;
                        insuranceMasterDB.CompanyName        = IsEditMode == true && insuranceMasterBO.CompanyName == null ? insuranceMasterDB.CompanyName : insuranceMasterBO.CompanyName;
                        insuranceMasterDB.ZeusID             = insuranceMasterBO.ZeusID;
                        insuranceMasterDB.PriorityBilling    = insuranceMasterBO.PriorityBilling;
                        insuranceMasterDB.Only1500Form       = insuranceMasterBO.Only1500Form;
                        insuranceMasterDB.PaperAuthorization = insuranceMasterBO.PaperAuthorization;
                        insuranceMasterDB.CreatedByCompanyId = insuranceMasterBO.CreatedByCompanyId;

                        insuranceMasterDB.AddressInfoId = (addressDB != null && addressDB.id > 0) ? addressDB.id : insuranceMasterDB.AddressInfoId;
                        insuranceMasterDB.ContactInfoId = (contactinfoDB != null && contactinfoDB.id > 0) ? contactinfoDB.id : insuranceMasterDB.ContactInfoId;

                        if (Add_insuranceMasterDB == true)
                        {
                            insuranceMasterDB = _context.InsuranceMasters.Add(insuranceMasterDB);
                        }
                        _context.SaveChanges();
                    }
                    else
                    {
                        if (IsEditMode == false)
                        {
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                errorObject = "", ErrorMessage = "Please pass valid insurance master information details.", ErrorLevel = ErrorLevel.Error
                            });
                        }
                        insuranceMasterDB = null;
                    }

                    _context.SaveChanges();
                    #endregion

                    dbContextTransaction.Commit();

                    insuranceMasterDB = _context.InsuranceMasters.Include("addressInfo").Include("contactInfo").Where(p => p.Id == insuranceMasterDB.Id && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault <InsuranceMaster>();
                }

                var res = ObjectConvert <BO.InsuranceMaster, InsuranceMaster>(insuranceMasterDB);
                return((object)res);
            }
            else
            {
                return(new BO.ErrorObject {
                    errorObject = "", ErrorMessage = "Cannot add or update Master Insurance data.", ErrorLevel = ErrorLevel.Error
                });
            }
        }
        public override object Save <T>(T entity)
        {
            BO.PatientAccidentInfo PatientAccidentInfoBO = (BO.PatientAccidentInfo)(object) entity;
            BO.AddressInfo         AccidentAddressInfoBO = PatientAccidentInfoBO.AccidentAddressInfo;
            BO.AddressInfo         HospitalAddressInfoBO = PatientAccidentInfoBO.HospitalAddressInfo;

            PatientAccidentInfo PatientAccidentInfoDB = new PatientAccidentInfo();

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                AddressInfo AccidentAddressInfoDB = new AddressInfo();
                AddressInfo HospitalAddressInfoDB = new AddressInfo();

                bool IsEditMode = false;
                IsEditMode = (PatientAccidentInfoBO != null && PatientAccidentInfoBO.ID > 0) ? true : false;

                bool IsAccAddressEditMode = false;
                IsAccAddressEditMode = (AccidentAddressInfoBO != null && AccidentAddressInfoBO.ID > 0) ? true : false;
                bool IsHosAddressEditMode = false;
                IsHosAddressEditMode = (HospitalAddressInfoBO != null && HospitalAddressInfoBO.ID > 0) ? true : false;

                #region accident Address
                if (AccidentAddressInfoBO != null)
                {
                    bool Add_addressDB = false;
                    AccidentAddressInfoDB = _context.AddressInfoes.Where(p => p.id == AccidentAddressInfoBO.ID).FirstOrDefault();

                    if (AccidentAddressInfoDB == null && AccidentAddressInfoBO.ID <= 0)
                    {
                        AccidentAddressInfoDB = new AddressInfo();
                        Add_addressDB         = true;
                    }
                    else if (AccidentAddressInfoDB == null && AccidentAddressInfoBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Accident address details dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    // AccidentAddressInfoDB.id = (IsAccAddressEditMode == true && AccidentAddressInfoBO.ID <= 0) ? AccidentAddressInfoDB.id : AccidentAddressInfoBO.ID;
                    AccidentAddressInfoDB.Name     = (IsAccAddressEditMode == true && AccidentAddressInfoBO.Name == null) ? AccidentAddressInfoDB.Name : AccidentAddressInfoBO.Name;
                    AccidentAddressInfoDB.Address1 = (IsAccAddressEditMode == true && AccidentAddressInfoBO.Address1 == null) ? AccidentAddressInfoDB.Address1 : AccidentAddressInfoBO.Address1;
                    AccidentAddressInfoDB.Address2 = (IsAccAddressEditMode == true && AccidentAddressInfoBO.Address2 == null) ? AccidentAddressInfoDB.Address2 : AccidentAddressInfoBO.Address2;
                    AccidentAddressInfoDB.City     = (IsAccAddressEditMode == true && AccidentAddressInfoBO.City == null) ? AccidentAddressInfoDB.City :  AccidentAddressInfoBO.City;
                    AccidentAddressInfoDB.State    = (IsAccAddressEditMode == true && AccidentAddressInfoBO.State == null) ? AccidentAddressInfoDB.State : AccidentAddressInfoBO.State;
                    AccidentAddressInfoDB.ZipCode  = (IsAccAddressEditMode == true && AccidentAddressInfoBO.ZipCode == null) ? AccidentAddressInfoDB.ZipCode : AccidentAddressInfoBO.ZipCode;
                    AccidentAddressInfoDB.Country  = (IsAccAddressEditMode == true && AccidentAddressInfoBO.Country == null) ? AccidentAddressInfoDB.Country : AccidentAddressInfoBO.Country;
                    //[STATECODE-CHANGE]
                    //AccidentAddressInfoDB.StateCode = (IsAccAddressEditMode == true && AccidentAddressInfoBO.StateCode == null) ? AccidentAddressInfoDB.StateCode : AccidentAddressInfoBO.StateCode;
                    //[STATECODE-CHANGE]

                    if (Add_addressDB == true)
                    {
                        AccidentAddressInfoDB = _context.AddressInfoes.Add(AccidentAddressInfoDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        errorObject = "", ErrorMessage = "Please pass valid Accident address details.", ErrorLevel = ErrorLevel.Error
                    });
                }
                #endregion

                #region Hospital Address
                if (HospitalAddressInfoBO != null)
                {
                    bool Add_addressDB = false;
                    HospitalAddressInfoDB = _context.AddressInfoes.Where(p => p.id == HospitalAddressInfoBO.ID).FirstOrDefault();

                    if (HospitalAddressInfoDB == null && HospitalAddressInfoBO.ID <= 0)
                    {
                        HospitalAddressInfoDB = new AddressInfo();
                        Add_addressDB         = true;
                    }
                    else if (HospitalAddressInfoDB == null && HospitalAddressInfoBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Hospital address details dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }

                    // HospitalAddressInfoDB.id = HospitalAddressInfoBO.ID;
                    HospitalAddressInfoDB.Name     = (IsHosAddressEditMode == true && HospitalAddressInfoBO.Name == null) ? HospitalAddressInfoDB.Name : HospitalAddressInfoBO.Name;
                    HospitalAddressInfoDB.Address1 = (IsHosAddressEditMode == true && HospitalAddressInfoBO.Address1 == null) ? HospitalAddressInfoDB.Address1 : HospitalAddressInfoBO.Address1;
                    HospitalAddressInfoDB.Address2 = (IsHosAddressEditMode == true && HospitalAddressInfoBO.Address2 == null) ? HospitalAddressInfoDB.Address2 : HospitalAddressInfoBO.Address2;
                    HospitalAddressInfoDB.City     = (IsHosAddressEditMode == true && HospitalAddressInfoBO.City == null) ? HospitalAddressInfoDB.City : HospitalAddressInfoBO.City;
                    HospitalAddressInfoDB.State    = (IsHosAddressEditMode == true && HospitalAddressInfoBO.State == null) ? HospitalAddressInfoDB.State : HospitalAddressInfoBO.State;
                    HospitalAddressInfoDB.ZipCode  = (IsHosAddressEditMode == true && HospitalAddressInfoBO.ZipCode == null) ? HospitalAddressInfoDB.ZipCode : HospitalAddressInfoBO.ZipCode;
                    HospitalAddressInfoDB.Country  = (IsHosAddressEditMode == true && HospitalAddressInfoBO.Country == null) ? HospitalAddressInfoDB.Country : HospitalAddressInfoBO.Country;
                    //[STATECODE-CHANGE]
                    //HospitalAddressInfoDB.StateCode = (IsHosAddressEditMode == true && HospitalAddressInfoBO.StateCode == null) ? HospitalAddressInfoDB.StateCode : HospitalAddressInfoBO.StateCode;
                    //[STATECODE-CHANGE]

                    if (Add_addressDB == true)
                    {
                        HospitalAddressInfoDB = _context.AddressInfoes.Add(HospitalAddressInfoDB);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        errorObject = "", ErrorMessage = "Please pass valid hospital address details.", ErrorLevel = ErrorLevel.Error
                    });
                }
                #endregion

                #region patient Accident Info
                if (PatientAccidentInfoBO != null)
                {
                    bool Add_PatientAccidentInfoDB = false;
                    PatientAccidentInfoDB = _context.PatientAccidentInfoes.Where(p => p.Id == PatientAccidentInfoBO.ID).FirstOrDefault();

                    if (PatientAccidentInfoDB == null && PatientAccidentInfoBO.ID <= 0)
                    {
                        PatientAccidentInfoDB     = new PatientAccidentInfo();
                        Add_PatientAccidentInfoDB = true;
                    }
                    else if (PatientAccidentInfoDB == null && PatientAccidentInfoBO.ID > 0)
                    {
                        dbContextTransaction.Rollback();
                        return(new BO.ErrorObject {
                            errorObject = "", ErrorMessage = "Patient dosent exists.", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    if (IsEditMode == false)
                    {
                        PatientAccidentInfoDB.CaseId = PatientAccidentInfoBO.CaseId;
                    }

                    PatientAccidentInfoDB.AccidentDate          = (IsEditMode == true && PatientAccidentInfoBO.AccidentDate == null) ? PatientAccidentInfoDB.AccidentDate : PatientAccidentInfoBO.AccidentDate;
                    PatientAccidentInfoDB.Weather               = (IsEditMode == true && PatientAccidentInfoBO.Weather == null) ? PatientAccidentInfoDB.Weather : PatientAccidentInfoBO.Weather;
                    PatientAccidentInfoDB.PlateNumber           = (IsEditMode == true && PatientAccidentInfoBO.PlateNumber == null) ? PatientAccidentInfoDB.PlateNumber : PatientAccidentInfoBO.PlateNumber;
                    PatientAccidentInfoDB.AccidentAddressInfoId = (IsEditMode == true && PatientAccidentInfoBO.AccidentAddressInfoId == null) ? PatientAccidentInfoDB.AccidentAddressInfoId : AccidentAddressInfoDB.id;
                    PatientAccidentInfoDB.HospitalName          = (IsEditMode == true && PatientAccidentInfoBO.HospitalName == null) ? PatientAccidentInfoDB.HospitalName : PatientAccidentInfoBO.HospitalName;
                    PatientAccidentInfoDB.PoliceAtScene         = (IsEditMode == true && PatientAccidentInfoBO.PoliceAtScene == null) ? PatientAccidentInfoDB.PoliceAtScene : PatientAccidentInfoBO.PoliceAtScene;
                    PatientAccidentInfoDB.Precinct              = (IsEditMode == true && PatientAccidentInfoBO.Precinct == null) ? PatientAccidentInfoDB.Precinct : PatientAccidentInfoBO.Precinct;
                    PatientAccidentInfoDB.ReportNumber          = (IsEditMode == true && PatientAccidentInfoBO.ReportNumber == null) ? PatientAccidentInfoDB.ReportNumber : PatientAccidentInfoBO.ReportNumber;
                    PatientAccidentInfoDB.PatientTypeId         = (IsEditMode == true && PatientAccidentInfoBO.PatientTypeId == null) ? PatientAccidentInfoDB.PatientTypeId : PatientAccidentInfoBO.PatientTypeId.Value;
                    PatientAccidentInfoDB.WearingSeatBelts      = (IsEditMode == true && PatientAccidentInfoBO.WearingSeatBelts == null) ? PatientAccidentInfoDB.WearingSeatBelts : PatientAccidentInfoBO.WearingSeatBelts;
                    PatientAccidentInfoDB.AirBagsDeploy         = (IsEditMode == true && PatientAccidentInfoBO.AirBagsDeploy == null) ? PatientAccidentInfoDB.AirBagsDeploy : PatientAccidentInfoBO.AirBagsDeploy;
                    PatientAccidentInfoDB.PhotosTaken           = (IsEditMode == true && PatientAccidentInfoBO.PhotosTaken == null) ? PatientAccidentInfoDB.PhotosTaken : PatientAccidentInfoBO.PhotosTaken;
                    PatientAccidentInfoDB.AccidentDescription   = (IsEditMode == true && PatientAccidentInfoBO.AccidentDescription == null) ? PatientAccidentInfoDB.AccidentDescription : PatientAccidentInfoBO.AccidentDescription;
                    PatientAccidentInfoDB.Witness               = (IsEditMode == true && PatientAccidentInfoBO.Witness == null) ? PatientAccidentInfoDB.Witness : PatientAccidentInfoBO.Witness;
                    PatientAccidentInfoDB.DescribeInjury        = (IsEditMode == true && PatientAccidentInfoBO.DescribeInjury == null) ? PatientAccidentInfoDB.DescribeInjury : PatientAccidentInfoBO.DescribeInjury;
                    PatientAccidentInfoDB.Ambulance             = (IsEditMode == true && PatientAccidentInfoBO.Ambulance == null) ? PatientAccidentInfoDB.Ambulance : PatientAccidentInfoBO.Ambulance;
                    PatientAccidentInfoDB.HospitalAddressInfoId = (IsEditMode == true && PatientAccidentInfoBO.HospitalAddressInfoId == null) ? PatientAccidentInfoDB.HospitalAddressInfoId : HospitalAddressInfoDB.id;
                    PatientAccidentInfoDB.TreatedAndReleased    = (IsEditMode == true && PatientAccidentInfoBO.TreatedAndReleased == null) ? PatientAccidentInfoDB.TreatedAndReleased : PatientAccidentInfoBO.TreatedAndReleased;
                    PatientAccidentInfoDB.Admitted              = (IsEditMode == true && PatientAccidentInfoBO.Admitted == null) ? PatientAccidentInfoDB.Admitted : PatientAccidentInfoBO.Admitted;
                    PatientAccidentInfoDB.DateOfAdmission       = (IsEditMode == true && PatientAccidentInfoBO.DateOfAdmission == null) ? PatientAccidentInfoDB.DateOfAdmission : PatientAccidentInfoBO.DateOfAdmission;
                    PatientAccidentInfoDB.XRaysTaken            = (IsEditMode == true && PatientAccidentInfoBO.XRaysTaken == null) ? PatientAccidentInfoDB.XRaysTaken : PatientAccidentInfoBO.XRaysTaken;
                    PatientAccidentInfoDB.DurationAtHospital    = (IsEditMode == true && PatientAccidentInfoBO.DurationAtHospital == null) ? PatientAccidentInfoDB.DurationAtHospital : PatientAccidentInfoBO.DurationAtHospital;
                    PatientAccidentInfoDB.MedicalReportNumber   = (IsEditMode == true && PatientAccidentInfoBO.MedicalReportNumber == null) ? PatientAccidentInfoDB.MedicalReportNumber : PatientAccidentInfoBO.MedicalReportNumber;
                    PatientAccidentInfoDB.AdditionalPatients    = (IsEditMode == true && PatientAccidentInfoBO.AdditionalPatients == null) ? PatientAccidentInfoDB.AdditionalPatients : PatientAccidentInfoBO.AdditionalPatients;

                    if (Add_PatientAccidentInfoDB == true)
                    {
                        PatientAccidentInfoDB = _context.PatientAccidentInfoes.Add(PatientAccidentInfoDB);
                    }
                    _context.SaveChanges();

                    List <BO.AccidentWitness> AccidentWitnesses = PatientAccidentInfoBO.AccidentWitnesses;
                    if (AccidentWitnesses != null)
                    {
                        var AccidentWitnessId     = AccidentWitnesses.Select(p => p.ID);
                        var RemoveAccidentWitness = _context.AccidentWitnesses.Where(p => AccidentWitnessId.Contains(p.Id) == false &&
                                                                                     p.PatientAccidentInfoId == PatientAccidentInfoDB.Id &&
                                                                                     (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                                    .ToList();

                        RemoveAccidentWitness.ForEach(p => p.IsDeleted = true);

                        foreach (var eachAccidentWitnesses in AccidentWitnesses)
                        {
                            bool AddUpdateAccidentWitness_Add = false;
                            var  AddUpdateAccidentWitness     = _context.AccidentWitnesses.Where(p => p.Id == eachAccidentWitnesses.ID &&
                                                                                                 p.PatientAccidentInfoId == PatientAccidentInfoDB.Id &&
                                                                                                 (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                                                .FirstOrDefault();

                            if (AddUpdateAccidentWitness == null)
                            {
                                AddUpdateAccidentWitness     = new AccidentWitness();
                                AddUpdateAccidentWitness_Add = true;
                            }

                            AddUpdateAccidentWitness.PatientAccidentInfoId = PatientAccidentInfoDB.Id;
                            AddUpdateAccidentWitness.WitnessName           = eachAccidentWitnesses.WitnessName;
                            AddUpdateAccidentWitness.WitnessContactNumber  = eachAccidentWitnesses.WitnessContactNumber;

                            if (AddUpdateAccidentWitness_Add == true)
                            {
                                _context.AccidentWitnesses.Add(AddUpdateAccidentWitness);
                            }
                        }

                        _context.SaveChanges();
                    }
                    else
                    {
                        var RemoveAccidentWitness = _context.AccidentWitnesses.Where(p => p.PatientAccidentInfoId == PatientAccidentInfoDB.Id &&
                                                                                     (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                                    .ToList();

                        RemoveAccidentWitness.ForEach(p => p.IsDeleted = true);

                        _context.SaveChanges();
                    }

                    List <BO.AccidentTreatment> AccidentTreatments = PatientAccidentInfoBO.AccidentTreatments;
                    if (AccidentTreatments != null)
                    {
                        var AccidentTreatmentId      = AccidentTreatments.Select(p => p.ID);
                        var RemoveAccidentTreatments = _context.AccidentTreatments.Where(p => AccidentTreatmentId.Contains(p.Id) == false &&
                                                                                         p.PatientAccidentInfoId == PatientAccidentInfoDB.Id &&
                                                                                         (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                                       .ToList();

                        RemoveAccidentTreatments.ForEach(p => p.IsDeleted = true);

                        foreach (var eachAccidentTreatment in AccidentTreatments)
                        {
                            bool AddUpdateAccidentTreatments_Add = false;
                            var  AddUpdateAccidentTreatments     = _context.AccidentTreatments.Where(p => p.Id == eachAccidentTreatment.ID &&
                                                                                                     p.PatientAccidentInfoId == PatientAccidentInfoDB.Id &&
                                                                                                     (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                                                   .FirstOrDefault();

                            if (AddUpdateAccidentTreatments == null)
                            {
                                AddUpdateAccidentTreatments     = new AccidentTreatment();
                                AddUpdateAccidentTreatments_Add = true;
                            }

                            AddUpdateAccidentTreatments.PatientAccidentInfoId = PatientAccidentInfoDB.Id;
                            AddUpdateAccidentTreatments.MedicalFacilityName   = eachAccidentTreatment.MedicalFacilityName;
                            AddUpdateAccidentTreatments.DoctorName            = eachAccidentTreatment.DoctorName;
                            AddUpdateAccidentTreatments.ContactNumber         = eachAccidentTreatment.ContactNumber;
                            AddUpdateAccidentTreatments.Address = eachAccidentTreatment.Address;

                            if (AddUpdateAccidentTreatments_Add == true)
                            {
                                _context.AccidentTreatments.Add(AddUpdateAccidentTreatments);
                            }
                        }

                        _context.SaveChanges();
                    }
                    else
                    {
                        var RemoveAccidentTreatments = _context.AccidentTreatments.Where(p => p.PatientAccidentInfoId == PatientAccidentInfoDB.Id &&
                                                                                         (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                                       .ToList();

                        RemoveAccidentTreatments.ForEach(p => p.IsDeleted = true);

                        _context.SaveChanges();
                    }
                }
                else
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        errorObject = "", ErrorMessage = "Please pass valid Patient Accident details.", ErrorLevel = ErrorLevel.Error
                    });
                }

                _context.SaveChanges();
                #endregion

                dbContextTransaction.Commit();

                PatientAccidentInfoDB = _context.PatientAccidentInfoes.Where(p => p.Id == PatientAccidentInfoDB.Id).FirstOrDefault <PatientAccidentInfo>();
            }

            var res = Convert <BO.PatientAccidentInfo, PatientAccidentInfo>(PatientAccidentInfoDB);
            return((object)res);
        }