public IHttpActionResult PostOnBoardingService(SubSiteOfficeConfigDTO oDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = subsiteofficeconfigService.SaveSubSiteOfficeConfigInfo(oDto);

            if (result == Guid.Empty)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
        /// <summary>
        /// This Method is used to Get SubSite Office Configuration Details
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public async Task <SubSiteOfficeConfigDTO> GetSubSiteOfficeConfigById(Guid userid, Guid parentId)
        {
            try
            {
                DropDownService           ddService           = new DropDownService();
                List <EntityHierarchyDTO> EntityHierarchyDTOs = new List <EntityHierarchyDTO>();
                EntityHierarchyDTOs = ddService.GetEntityHierarchies(userid);

                Guid ParentId = Guid.Empty;

                if (EntityHierarchyDTOs.Count > 2)
                {
                    var LevelOne = EntityHierarchyDTOs.Where(o => o.Customer_Level == 1).FirstOrDefault();
                    if (LevelOne != null)
                    {
                        ParentId = LevelOne.CustomerId ?? Guid.Empty;
                    }
                    else
                    {
                        ParentId = EntityHierarchyDTOs.Where(o => o.Customer_Level == 0).Select(o => o.CustomerId).FirstOrDefault() ?? Guid.Empty;
                    }
                }


                db = new DatabaseEntities();
                var data = await db.SubSiteOfficeConfigs.Where(o => o.RefId == userid).Select(o => new SubSiteOfficeConfigDTO
                {
                    Id    = o.Id.ToString(),
                    RefId = o.RefId.ToString(),
                    EFINListedOtherOffice       = o.EFINListedOtherOffice,
                    SiteOwnthisEFIN             = o.SiteOwnthisEFIN,
                    EFINOwnerSite               = o.EFINOwnerSite,
                    SOorSSorEFIN                = o.SOorSSorEFIN.ToString(),
                    SubSiteSendTaxReturn        = o.SubSiteSendTaxReturn,
                    SiteanMSOLocation           = o.SiteanMSOLocation,
                    IsMainSiteTransmitTaxReturn = o.IsMainSiteTransmitTaxReturn,
                    NoofTaxProfessionals        = o.NoofTaxProfessionals,
                    IsSoftwareOnNetwork         = o.IsSoftwareOnNetwork,
                    NoofComputers               = o.NoofComputers,
                    PreferredLanguage           = o.PreferredLanguage,
                    CanSubSiteLoginToEmp        = o.CanSubSiteLoginToEmp ?? false,
                    IsBusinessSoftware          = o.HasBusinessSoftware,
                    IsSharingEFIN               = o.IsSharingEFIN
                }).FirstOrDefaultAsync();

                if (data == null)
                {
                    if (EntityHierarchyDTOs.Count > 2)
                    {
                        SubSiteOfficeConfigDTO data1 = new SubSiteOfficeConfigDTO();
                        var subsiteconfig            = (from ssc in db.SubSiteOfficeConfigs where ssc.RefId == parentId select ssc).FirstOrDefault();
                        //  data1.Id = "0";
                        if (subsiteconfig != null)
                        {
                            data1.SubSiteSendTaxReturn = subsiteconfig.SubSiteSendTaxReturn;
                        }
                        else
                        {
                            data1.SubSiteSendTaxReturn = true;
                        }
                        data1.IsBusinessSoftware = db.emp_CustomerInformation.Where(x => x.Id == userid).Select(x => x.QuoteSoftwarePackage).FirstOrDefault() == EMPConstants.EnterprisePackage;
                        return(data1);
                    }
                    else
                    {
                        SubSiteOfficeConfigDTO data1 = new SubSiteOfficeConfigDTO();
                        var subsiteconfig            = (from ssc in db.SubSiteConfigurations where ssc.emp_CustomerInformation_ID == parentId select ssc).FirstOrDefault();
                        //  data1.Id = "0";
                        if (subsiteconfig != null)
                        {
                            data1.iIsSubSiteSendTaxReturn = subsiteconfig.SubSiteTaxReturn ?? 0;
                        }
                        else
                        {
                            data1.iIsSubSiteSendTaxReturn = 0;
                        }
                        data1.IsBusinessSoftware = db.emp_CustomerInformation.Where(x => x.Id == userid).Select(x => x.QuoteSoftwarePackage).FirstOrDefault() == EMPConstants.EnterprisePackage;
                        return(data1);
                    }
                }
                else
                {
                    if (EntityHierarchyDTOs.Count < 3)
                    {
                        var subsiteconfig = (from ssc in db.SubSiteConfigurations where ssc.emp_CustomerInformation_ID == parentId select ssc).FirstOrDefault();
                        if (subsiteconfig != null)
                        {
                            data.iIsSubSiteSendTaxReturn = subsiteconfig.SubSiteTaxReturn ?? 0;
                        }
                        else
                        {
                            data.iIsSubSiteSendTaxReturn = (data.SubSiteSendTaxReturn == true) ? 1 : 0;
                        }
                    }
                }
                return(data);
            }
            catch (Exception ex)
            {
                EMPPortal.Core.Utilities.ExceptionLogger.LogException(ex.ToString(), "CustomerPaymentOptionsService/GetSubSiteOfficeConfigById", Guid.Empty);
                return(null);
            }
        }
        /// <summary>
        /// This method is used to save and update the Sub Site Office Configuration Details
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public Guid SaveSubSiteOfficeConfigInfo(SubSiteOfficeConfigDTO dto)
        {
            db = new DatabaseEntities();
            Guid MyId                 = Guid.Empty;
            int  entityState          = 0;
            bool prevBS               = false;
            SubSiteOfficeConfig model = new SubSiteOfficeConfig();

            if (dto != null)
            {
                Guid Id, refId;
                if (Guid.TryParse(dto.Id, out Id))
                {
                    model = db.SubSiteOfficeConfigs.Where(a => a.Id == Id).FirstOrDefault();
                    if (model != null)
                    {
                        prevBS      = model.HasBusinessSoftware;
                        entityState = (int)System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        return(Guid.Empty);
                    }
                }
                else
                {
                    model.Id    = Guid.NewGuid();
                    entityState = (int)System.Data.Entity.EntityState.Added;
                }

                bool IsRefId = Guid.TryParse(dto.RefId, out refId);
                if (!IsRefId)
                {
                    return(Guid.Empty);
                }
                model.RefId = refId;
                model.EFINListedOtherOffice = dto.EFINListedOtherOffice ?? false;
                model.SiteOwnthisEFIN       = dto.SiteOwnthisEFIN ?? false;
                model.EFINOwnerSite         = dto.EFINOwnerSite;
                int SOorSSorEFIN = 0;
                if (int.TryParse(dto.SOorSSorEFIN, out SOorSSorEFIN))
                {
                    model.SOorSSorEFIN = SOorSSorEFIN;
                }
                else
                {
                    return(Guid.Empty);
                }

                model.CanSubSiteLoginToEmp = true;
                model.SubSiteSendTaxReturn = dto.SubSiteSendTaxReturn ?? false;
                model.SiteanMSOLocation    = dto.SiteanMSOLocation ?? false;
                model.LastUpdatedBy        = dto.UserId ?? Guid.Empty;
                model.LastUpdatedDate      = System.DateTime.Now;

                ///// Main Site Data
                model.IsMainSiteTransmitTaxReturn = dto.IsMainSiteTransmitTaxReturn;
                model.NoofTaxProfessionals        = dto.NoofTaxProfessionals;
                model.IsSoftwareOnNetwork         = dto.IsSoftwareOnNetwork;
                model.NoofComputers       = dto.NoofComputers;
                model.PreferredLanguage   = dto.PreferredLanguage;
                model.HasBusinessSoftware = dto.IsBusinessSoftware;
                model.IsSharingEFIN       = dto.IsSharingEFIN;

                if (entityState == (int)System.Data.Entity.EntityState.Added)
                {
                    model.CreatedBy   = dto.UserId ?? Guid.Empty;
                    model.CreatedDate = System.DateTime.Now;
                    db.SubSiteOfficeConfigs.Add(model);
                }
                else
                {
                    db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                }

                //var enrollconfig = db.EnrollmentOfficeConfigurations.Where(x => x.CustomerId == refId && x.StatusCode == EMPConstants.Active).FirstOrDefault();
                //if (enrollconfig != null)
                //{
                //    enrollconfig.IsSoftwareOnNetwork = dto.IsSoftwareOnNetwork;
                //    enrollconfig.LastUpdatedBy = dto.UserId ?? Guid.Empty;
                //    enrollconfig.LastUpdatedDate = DateTime.Now;
                //    enrollconfig.NoofComputers = dto.NoofComputers;
                //    enrollconfig.NoofTaxProfessionals = dto.NoofTaxProfessionals;
                //    enrollconfig.PreferredLanguage = dto.PreferredLanguage;
                //}

                //if (model.SOorSSorEFIN == 3 && model.LastUpdatedBy != Guid.Empty)
                //{
                //    var emp_Info = db.emp_CustomerInformation.Where(o => o.Id == dto.UserId).FirstOrDefault();
                //    if (emp_Info != null)
                //    {
                //        emp_Info.IsAdditionalEFINAllowed = true;
                //        db.Entry(emp_Info).State = System.Data.Entity.EntityState.Modified;
                //    }
                //}


                var emp_MyInfo = db.emp_CustomerInformation.Where(o => o.Id == refId).FirstOrDefault();
                if (emp_MyInfo != null)
                {
                    var emp_ParentInfo = db.emp_CustomerInformation.Where(o => o.Id == emp_MyInfo.ParentId).FirstOrDefault();
                    if (emp_ParentInfo != null)
                    {
                        MyId = emp_MyInfo.Id;

                        if (emp_ParentInfo.EntityId == (int)EMPConstants.Entity.MO)
                        {
                            if (model.SOorSSorEFIN == 1)
                            {
                                emp_MyInfo.EROType  = "Multi Office - Single Office";
                                emp_MyInfo.EntityId = (int)EMPConstants.Entity.MO_SO;
                            }
                            else if (model.SOorSSorEFIN == 3)
                            {
                                emp_MyInfo.EROType  = "Multi Office - Additional EFIN";
                                emp_MyInfo.EntityId = (int)EMPConstants.Entity.MO_AE;
                            }
                        }
                        else if (emp_ParentInfo.EntityId == (int)EMPConstants.Entity.SVB_MO)
                        {
                            if (model.SOorSSorEFIN == 1)
                            {
                                emp_MyInfo.EROType  = "Service Bureau - Multi Office - Single Office";
                                emp_MyInfo.EntityId = (int)EMPConstants.Entity.SVB_MO_SO;
                            }
                            else if (model.SOorSSorEFIN == 3)
                            {
                                emp_MyInfo.EROType  = "Service Bureau - Multi Office - Additional EFIN";
                                emp_MyInfo.EntityId = (int)EMPConstants.Entity.SVB_MO_AE;
                            }
                        }
                        else if (emp_ParentInfo.EntityId == (int)EMPConstants.Entity.SVB)
                        {
                            if (model.SOorSSorEFIN == 1)
                            {
                                emp_MyInfo.EROType  = "Service Bureau - Single Office";
                                emp_MyInfo.EntityId = (int)EMPConstants.Entity.SVB_SO;
                            }
                            else if (model.SOorSSorEFIN == 2)
                            {
                                emp_MyInfo.EROType  = "Service Bureau - Multi Office";
                                emp_MyInfo.EntityId = (int)EMPConstants.Entity.SVB_MO;
                            }
                            else if (model.SOorSSorEFIN == 3)
                            {
                                emp_MyInfo.EROType  = "Service Bureau - Additional EFIN";
                                emp_MyInfo.EntityId = (int)EMPConstants.Entity.SVB_AE;
                            }
                        }

                        if (model.SOorSSorEFIN == 3)
                        {
                            emp_MyInfo.IsAdditionalEFINAllowed = true;
                        }

                        if (emp_MyInfo.EFINStatus == (int)EMPConstants.EFINStatus_ForSub.Sharing && model.SiteOwnthisEFIN == false)
                        {
                            var UserId = model.EFINOwnerSite;
                            if (!string.IsNullOrEmpty(UserId))
                            {
                                var UserMain = (from emp in db.emp_CustomerInformation
                                                join emplog in db.emp_CustomerLoginInformation
                                                on emp.Id equals emplog.CustomerOfficeId
                                                where emplog.EMPUserId == UserId
                                                select new { emp.EFIN }).FirstOrDefault();

                                if (UserMain != null)
                                {
                                    emp_MyInfo.EFIN = UserMain.EFIN ?? 0;
                                }
                            }
                        }

                        db.Entry(emp_MyInfo).State = System.Data.Entity.EntityState.Modified;
                    }

                    if (emp_MyInfo.IsActivationCompleted == 1)
                    {
                        if (prevBS != dto.IsBusinessSoftware && dto.IsBusinessSoftware)
                        {
                            var loginfo = db.emp_CustomerLoginInformation.Where(x => x.CustomerOfficeId == refId).FirstOrDefault();

                            var sy = db.SalesYearMasters.Where(x => x.Id == emp_MyInfo.SalesYearID).Select(x => x.SalesYear).FirstOrDefault();
                            CustomerInformationService cis = new CustomerInformation.CustomerInformationService();
                            cis.SaveEmpCsrData(refId, "Business Software", emp_MyInfo.SalesforceAccountID, sy.Value.ToString());

                            EmailNotification _email = new EmailNotification();
                            _email.CreatedBy    = dto.UserId ?? Guid.Empty;
                            _email.CreatedDate  = DateTime.Now;
                            _email.EmailCC      = "";
                            _email.EmailContent = "";
                            _email.EmailSubject = "Business Software";
                            _email.EmailTo      = EMPConstants.SupportutaxEmail;
                            _email.EmailType    = (int)EMPConstants.EmailTypes.BusinessSoftware;
                            _email.IsSent       = false;
                            _email.Parameters   = loginfo.EMPUserId + "$|$" + loginfo.MasterIdentifier + "$|$" + dto.IsBusinessSoftware;
                            db.EmailNotifications.Add(_email);
                        }
                    }
                    if (prevBS != dto.IsBusinessSoftware && dto.IsBusinessSoftware && emp_MyInfo.EntityId != (int)EMPConstants.Entity.SO)
                    {
                        var loginfo    = db.emp_CustomerLoginInformation.Where(x => x.CustomerOfficeId == refId).FirstOrDefault();
                        var parentinfo = db.emp_CustomerInformation.Where(x => x.Id == emp_MyInfo.ParentId).FirstOrDefault();
                        var parentsb   = db.MainOfficeConfigurations.Where(x => x.emp_CustomerInformation_ID == emp_MyInfo.ParentId).Select(x => x.HasBusinessSoftware).FirstOrDefault();
                        if (parentinfo != null)
                        {
                            if (parentinfo.QuoteSoftwarePackage != EMPConstants.EnterprisePackage && !parentsb)
                            {
                                EmailNotification _email = new EmailNotification();
                                _email.CreatedBy    = dto.UserId ?? Guid.Empty;
                                _email.CreatedDate  = DateTime.Now;
                                _email.EmailCC      = "";
                                _email.EmailContent = "";
                                _email.EmailSubject = "Business Software";
                                _email.EmailTo      = EMPConstants.accountutaxEmail;
                                _email.EmailType    = (int)EMPConstants.EmailTypes.BusinessSoftware;
                                _email.IsSent       = false;
                                _email.Parameters   = loginfo.EMPUserId + "$|$" + loginfo.MasterIdentifier + "$|$" + dto.IsBusinessSoftware;
                                db.EmailNotifications.Add(_email);
                            }
                        }
                    }
                }
            }

            try
            {
                db.SaveChanges();
                db.Dispose();

                if (MyId != Guid.Empty)
                {
                    DropDownService ddService = new DropDownService();
                    var             items     = ddService.GetBottomToTopHierarchy(MyId);
                }

                return(model.Id);
            }
            catch (Exception ex)
            {
                EMPPortal.Core.Utilities.ExceptionLogger.LogException(ex.ToString(), "CustomerPaymentOptionsService/SaveSubSiteOfficeConfigInfo", Guid.Empty);
                return(Guid.Empty);
            }
        }