/// <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);
            }
        }
Ejemplo n.º 2
0
        public int Save(CustomerLoginInformationModel model)
        {
            int entityState = 0;
            emp_CustomerLoginInformation customerLoginInformation = new emp_CustomerLoginInformation();

            if (model != null)
            {
                Guid newguid1;
                Guid CustomerOfficeId = model.CustomerOfficeId ?? Guid.Empty;
                if (Guid.TryParse(model.Id, out newguid1))
                {
                    //var ExistCust = db.emp_CustomerLoginInformation.Any(a => a.EFIN == model.EFIN && a.Id != newguid1);
                    //if (ExistCust)
                    //    return -1;

                    //11212016 - If

                    int EFIN = model.EFIN ?? 0;
                    if (EFIN > 0 && (model.EFINStatus == 16 || model.EFINStatus == 19))
                    {
                        //if (CustomerOfficeId != Guid.Empty)
                        //{
                        var ExistCust = db.emp_CustomerInformation.Any(a => a.EFIN == model.EFIN && a.Id != CustomerOfficeId);
                        if (ExistCust)
                        {
                            return(-1);
                        }
                        //}
                    }

                    var ExistCrossCust = db.emp_CustomerLoginInformation.Any(a => a.CrossLinkUserId == model.CrossLinkUserId && a.Id != newguid1);
                    if (ExistCrossCust)
                    {
                        return(-2);
                    }
                }

                if (string.IsNullOrEmpty(model.Id))
                {
                    customerLoginInformation.Id = Guid.NewGuid();
                }
                else
                {
                    Guid newguid;
                    if (Guid.TryParse(model.Id, out newguid))
                    {
                        customerLoginInformation.Id = newguid;
                        entityState = (int)System.Data.Entity.EntityState.Modified;
                    }
                }

                // customerLoginInformation.EFIN = model.EFIN;
                customerLoginInformation.MasterIdentifier  = model.MasterIdentifier;
                customerLoginInformation.CrossLinkUserId   = model.CrossLinkUserId;
                customerLoginInformation.CrossLinkPassword = PasswordManager.CryptText(model.CrossLinkPassword);// model.CrossLinkPassword;
                customerLoginInformation.OfficePortalUrl   = model.OfficePortalUrl;
                customerLoginInformation.TaxOfficeUsername = model.TaxOfficeUsername;
                customerLoginInformation.TaxOfficePassword = PasswordManager.CryptText(model.TaxOfficePassword); // model.TaxOfficePassword;
                customerLoginInformation.CustomerOfficeId  = model.CustomerOfficeId;
                customerLoginInformation.EMPPassword       = PasswordManager.CryptText(model.EMPPassword);       //model.EMPPassword;
                customerLoginInformation.EMPUserId         = model.EMPUserId;
                customerLoginInformation.StatusCode        = EMPConstants.Active;

                customerLoginInformation.CLAccountId       = model.CLAccountId;
                customerLoginInformation.CLLogin           = model.CLLogin;
                customerLoginInformation.CLAccountPassword = string.IsNullOrEmpty(model.CLAccountPassword) ? "" : PasswordManager.CryptText(model.CLAccountPassword);

                if (entityState == (int)System.Data.Entity.EntityState.Modified)
                {
                    customerLoginInformation.CreatedDate     = DateTime.Now;
                    customerLoginInformation.LastUpdatedDate = DateTime.Now;
                    customerLoginInformation.LastUpdatedBy   = model.UserId;
                    customerLoginInformation.CreatedBy       = model.UserId;
                    db.Entry(customerLoginInformation).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    db.Entry(customerLoginInformation).State = System.Data.Entity.EntityState.Added;
                    customerLoginInformation.LastUpdatedBy   = model.UserId;
                    customerLoginInformation.LastUpdatedDate = DateTime.Now;
                    db.emp_CustomerLoginInformation.Add(customerLoginInformation);
                }

                emp_CustomerInformation empCustInfo = new emp_CustomerInformation();
                empCustInfo = db.emp_CustomerInformation.Where(o => o.Id == model.CustomerOfficeId).FirstOrDefault();
                if (empCustInfo != null)
                {
                    //11212016 - 2
                    empCustInfo.EFIN          = model.EFIN;
                    empCustInfo.EFINStatus    = model.EFINStatus;
                    empCustInfo.StatusCode    = empCustInfo.IsActivationCompleted == 1 ? EMPConstants.Active : EMPConstants.Created;
                    empCustInfo.CreatedBy     = model.UserId;
                    empCustInfo.LastUpdatedBy = model.UserId;

                    if (empCustInfo.EntityId == (int)EMPConstants.Entity.SO || empCustInfo.EntityId == (int)EMPConstants.Entity.SOME)
                    {
                        if (empCustInfo.StatusCode == EMPConstants.Active || empCustInfo.IsActivationCompleted == 1)
                        {
                            empCustInfo.StatusCode            = EMPConstants.Active;
                            empCustInfo.IsActivationCompleted = 1;
                            empCustInfo.AccountStatus         = "Active";
                            if (empCustInfo.EntityId == (int)EMPConstants.Entity.SO)
                            {
                                empCustInfo.EROType = "Single Office";
                            }
                            else if (empCustInfo.EntityId == (int)EMPConstants.Entity.SOME)
                            {
                                empCustInfo.EROType = "SOME";
                            }
                        }
                    }

                    empCustInfo.CreatedDate     = System.DateTime.Now;
                    empCustInfo.LastUpdatedDate = System.DateTime.Now;

                    db.Entry(empCustInfo).State = System.Data.Entity.EntityState.Modified;
                }
            }
            try
            {
                db.SaveChanges();
                db.Dispose();

                if (model != null)
                {
                    if (model.CustomerOfficeId != Guid.Empty)
                    {
                        DropDownService ddService = new DropDownService();
                        var             items     = ddService.GetBottomToTopHierarchy(model.CustomerOfficeId ?? Guid.Empty);
                    }
                }

                return(1);
            }
            catch (Exception ex)
            {
                EMPPortal.Core.Utilities.ExceptionLogger.LogException(ex.ToString(), "CustomerLoginInformationService/Save", Guid.Empty);
                return(0);

                throw;
            }
        }