コード例 #1
0
        public bool Active(int id)
        {
            var agency = _IAgencyRepository.GetById(id);

            if (agency != null)
            {
                agency.Actived = true;
                _IAgencyRepository.Update(agency);

                return(true);
            }
            return(false);
        }
コード例 #2
0
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var agency = _agencyRepository.GetById(id.Value);

            if (agency == null)
            {
                return(NotFound());
            }

            foreach (var aRepresentative in agency.AgencyRepresentatives)
            {
                aRepresentative.Person = _personRepository.GetById(aRepresentative.PersonId);
            }

            ViewBag.Nationalities               = _personRepository.Nationalities;
            ViewBag.AddressTypes                = _personRepository.AddressTypes;
            ViewBag.PhoneTypes                  = _personRepository.PhoneTypes;
            ViewBag.EmailTypes                  = _personRepository.EmailTypes;
            ViewBag.SocialTypes                 = _personRepository.SocialTypes;
            ViewBag.OTTTypes                    = _personRepository.OTTTypes;
            ViewBag.BankAccountTypes            = _personRepository.BankAccountTypes;
            ViewBag.BankCardTypes               = _personRepository.BankCardTypes;
            ViewBag.Wards                       = _personRepository.Wards;
            ViewBag.DistrictPlaces              = _personRepository.DistrictPlaces;
            ViewBag.Provinces                   = _personRepository.Provinces;
            ViewBag.Representatives             = _personRepository.Representatives;
            ViewBag.Employees                   = _personRepository.Employees;
            ViewBag.AgencyGroups                = _agencyRepository.AgencyGroups;
            ViewBag.AgencyBusinesses            = _agencyRepository.AgencyBusinesses;
            ViewBag.CurrencyTypes               = _agencyRepository.CurrencyTypes;
            ViewBag.PaymentTypes                = _agencyRepository.PaymentTypes;
            ViewBag.PaymentTermTypes            = _agencyRepository.PaymentTermTypes;
            ViewBag.AgencyDiscountTypes         = _agencyRepository.AgencyDiscountTypes;
            ViewBag.PickupTypes                 = _agencyRepository.PickupTypes;
            ViewBag.AgencyDiscountCustomerTypes = _agencyRepository.AgencyDiscountCustomerTypes;

            return(View(agency));
        }
コード例 #3
0
        public IActionResult FilterCustomer(OrderCustomerFilterViewModel model)
        {
            var result   = new List <OrderCustomerFilterResult>();
            var arrNames = !string.IsNullOrEmpty(model.CustomerName) ? model.CustomerName.Split(' ') : null;

            if (model.OrderCustomerType == OrderCustomerType.Customer)
            {
                var customers = _personRepository.Customers.ToList();

                if (!string.IsNullOrEmpty(model.CustomerPhone))
                {
                    customers = customers.Where(c => c.ContactInfo.Phones.Any(p => !string.IsNullOrEmpty(p.PhoneNumber) && p.PhoneNumber.Contains(model.CustomerPhone))).ToList();
                }

                if (arrNames != null)
                {
                    var filterCusName = new List <Person>();
                    foreach (var subName in arrNames)
                    {
                        var subCus = customers.Where(c => c.PrimaryName.ToLower().Contains(subName.ToLower())).ToList();
                        if (subCus.Any())
                        {
                            filterCusName.AddRange(subCus.Except(filterCusName));
                        }
                    }

                    if (filterCusName.Any())
                    {
                        customers = filterCusName;
                    }
                }

                if (customers.Count > 0)
                {
                    foreach (var cus in customers)
                    {
                        var person = _personRepository.GetById(cus.Id);
                        var item   = new OrderCustomerFilterResult
                        {
                            Id                = person.Id,
                            PrimaryName       = person.PrimaryName,
                            FirstName         = person.Names.ElementAt(0).FirstName,
                            MidName           = person.Names.ElementAt(0).MidName,
                            LastName          = person.Names.ElementAt(0).LastName,
                            OrderCustomerType = model.OrderCustomerType,
                            Phones            = person.ContactInfo.Phones.Select(cp => cp.PhoneNumber).ToList()
                        };
                        result.Add(item);
                    }
                }
            }
            else
            {
                var agencies = _agencyRepository.Agencies.ToList();
                if (!string.IsNullOrEmpty(model.CustomerPhone))
                {
                    agencies = agencies.Where(c => c.AgencyContactInfo.Phones.Any(p => !string.IsNullOrEmpty(p.PhoneNumber) && p.PhoneNumber.Contains(model.CustomerPhone))).ToList();
                }

                if (arrNames != null)
                {
                    var filterCusName = new List <Agency>();
                    foreach (var subName in arrNames)
                    {
                        var subAgency = agencies.Where(c => c.Name.ToLower().Contains(subName.ToLower())).ToList();
                        if (subAgency.Any())
                        {
                            filterCusName.AddRange(subAgency.Except(filterCusName));
                        }
                    }

                    if (filterCusName.Any())
                    {
                        agencies = filterCusName;
                    }
                }

                if (agencies.Count > 0)
                {
                    foreach (var cus in agencies)
                    {
                        var agency = _agencyRepository.GetById(cus.Id);
                        var item   = new OrderCustomerFilterResult
                        {
                            Id                = agency.Id,
                            PrimaryName       = agency.Name,
                            OrderCustomerType = model.OrderCustomerType,
                            Phones            = agency.AgencyContactInfo.Phones.Select(cp => cp.PhoneNumber).ToList()
                        };
                        result.Add(item);
                    }
                }
            }
            return(PartialView("_FilterCustomer", result));
        }