public void SelectCustomerClientAtCustomerScope(int clientId, int customerId)
 {
     if (securityManager.CanChangeSelectedClient())
     {
         ICffClient  client   = clientRepository.GetCffClientByClientId(clientId);
         CffCustomer customer = customerRepository.GetCffCustomerByCustomerId(customerId);
         if (client != null)
         {
             view.Client = client;
             CffCustomerExt xC = new CffCustomerExt(customer.Name, customer.Id, customer.Number);
             view.Customer = (ICffCustomer)xC;
         }
     }
 }
예제 #2
0
        public string SelectCustomerFromAutoCompleteDropDown(string customerId)
        {
            //assign new customer instance here based from retrieved customer number and existing clientid
            Scope          xScope    = Scope.AllClientsScope;
            CffCustomerExt xCustomer = null;
            CffCustomer    cCustomer = null;

            if (SessionWrapper.Instance.Get != null)
            {
                if (SessionWrapper.Instance.Get.EmptyWindowHit == 0)
                {
                    SessionWrapper.Instance.Get.EmptyWindowHit = 1;
                }
                if (xCustomer == null)
                {
                    if (customerId.Contains("("))
                    { //this is customer number! we should be able to retrieve correct customer id + client id
                        customerId = customerId.Substring(customerId.IndexOf("(") + 1);
                        customerId = customerId.Replace(")", "");
                    }

                    if (!string.IsNullOrEmpty(customerId))
                    {
                        cCustomer = (RepositoryFactory.CreateCustomerRepository().GetMatchedCustomerInfo(Convert.ToInt32(customerId),
                                                                                                         SessionWrapper.Instance.Get.ClientFromQueryString.Id).CffCustomerInformation.Customer);
                        xCustomer = new CffCustomerExt(cCustomer.Name, cCustomer.Id, cCustomer.Number);
                    }
                }

                if (xCustomer != null)
                {
                    SessionWrapper.Instance.Get.CustomerFromQueryString = (ICffCustomer)xCustomer;
                    if (SessionWrapper.Instance.Get.CurrentUserID != (System.Web.HttpContext.Current.User as CffPrincipal).CffUser.UserId.ToString())
                    {
                        SessionWrapper.Instance.Get.CurrentUserID = (System.Web.HttpContext.Current.User as CffPrincipal).CffUser.UserId.ToString();
                    }
                }
            }
            else if (!string.IsNullOrEmpty(QueryString.ViewIDValue))
            {
                if (SessionWrapper.Instance.GetSession(QueryString.ViewIDValue) != null)
                {
                    xScope = SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).Scope;
                    if (SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).EmptyWindowHit == 0)
                    {
                        SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).EmptyWindowHit = 1;
                    }

                    cCustomer = (RepositoryFactory.CreateCustomerRepository().GetMatchedCustomerInfo(Convert.ToInt32(customerId),
                                                                                                     SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).ClientFromQueryString.Id).CffCustomerInformation.Customer);
                    xCustomer = new CffCustomerExt(cCustomer.Name, cCustomer.Id, cCustomer.Number);
                    if (xCustomer != null)
                    {
                        SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).CustomerFromQueryString = (ICffCustomer)xCustomer;
                    }

                    if (SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).CurrentUserID != (System.Web.HttpContext.Current.User as CffPrincipal).CffUser.UserId.ToString())
                    {
                        SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).CurrentUserID = (System.Web.HttpContext.Current.User as CffPrincipal).CffUser.UserId.ToString();
                    }
                }
            }


            IScopeService scopeService = new ScopeService(this,
                                                          SecurityManagerFactory.Create(Context.User as CffPrincipal, xScope),
                                                          RepositoryFactory.CreateClientRepository(),
                                                          RepositoryFactory.CreateCustomerRepository());

            string jSon = string.Empty;

            if (!string.IsNullOrEmpty(customerId))
            {
                try
                {
                    scopeService.SelectCustomer(int.Parse(customerId));
                    using (MemoryStream stream = new MemoryStream())
                    {
                        serializer.WriteObject(stream, Client);
                        jSon = Encoding.Default.GetString(stream.ToArray());
                    }
                }
                catch (FormatException)
                {
                }
            }

            return(jSon);
        }