예제 #1
0
 public bool SaveSubOfficeDetails(Guid CustID, int iSubSiteTaxReturn)
 {
     try
     {
         var dbcust = (from cu in db.emp_CustomerInformation where cu.ParentId == CustID select cu);
         foreach (var cid in dbcust)
         {
             DatabaseEntities    _db = new DatabaseEntities();
             SubSiteOfficeConfig oSubSiteOfficeConfigurations = new SubSiteOfficeConfig();
             oSubSiteOfficeConfigurations = _db.SubSiteOfficeConfigs.Where(a => a.RefId == cid.Id).FirstOrDefault();
             if (oSubSiteOfficeConfigurations != null)
             {
                 if (iSubSiteTaxReturn == 1)
                 {
                     oSubSiteOfficeConfigurations.SubSiteSendTaxReturn = true;
                 }
                 else
                 {
                     oSubSiteOfficeConfigurations.SubSiteSendTaxReturn = false;
                 }
                 _db.SaveChanges();
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         EMPPortal.Core.Utilities.ExceptionLogger.LogException(ex.ToString(), "SubSiteConfigService/SaveSubOfficeDetails", CustID);
         return(false);
     }
 }
        /// <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);
            }
        }