示例#1
0
        public async Task <ActionResult <Users> > SearchService(string searchFilter)
        {
            var result = Json(new {
                success = false
            });

            try {
                dynamic      data   = JsonConvert.DeserializeObject(searchFilter);
                SearchFilter filter = new SearchFilter {
                    SearchString = data["SearchString"],
                    Category     = data["Category"]
                };
                using (var business = new SearchBusiness(_context)) {
                    var searchResults = business.search(filter);

                    return(Json(new {
                        data = searchResults,
                        success = true
                    }));
                }
            } catch (Exception e) {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
示例#2
0
        public void TestBusinessServices_Search_Businesses_And_Reorder()
        {
            // Test regional manager1
            var rm1 = GetUserSessionModel("*****@*****.**");

            var search = new SearchBusiness
            {
                SortColumn   = "BusinessName",
                Page         = 1,
                PageSize     = 2,
                ReturnTotals = true
            };

            var response = service.GetBusinessListModel(rm1, search);

            var results = response.Model as List <BusinessListModel>;

            Assert.AreEqual(results.Count(), 2);

            Assert.IsTrue(string.Compare(results[0].BusinessName, results[1].BusinessName) < 0);

            search.IsDesc = true;

            response = service.GetBusinessListModel(rm1, search);

            results = response.Model as List <BusinessListModel>;

            Assert.IsTrue(string.Compare(results[0].BusinessName, results[1].BusinessName) > 0);
        }
示例#3
0
        public ServiceResponse GetBusinessListModel(UserSessionModel admin, SearchBusiness search)
        {
            search.ReturnTotals = true;

            var query = from business in Db.BusinessQueryBySearch(admin, search)
                        join businessType in Db.BusinessTypes on business.BusinessTypeId equals businessType.BusinessTypeId
                        join address in Db.Addresses on business.AddressId equals address.AddressId
                        join state in Db.States on address.StateId equals state.StateId into Lstate
                        from state in Lstate.DefaultIfEmpty()
                        join country in Db.Countries on state.CountryCode equals country.CountryCode into Lcountry
                        from country in Lcountry.DefaultIfEmpty()

                        select new BusinessListModel
            {
                AccountId               = business.AccountId,
                DaikinCityId            = business.DaikinCityId,
                CommissionSchemeAllowed = business.CommissionSchemeAllowed,
                BusinessId              = business.BusinessId,
                WebSite            = business.Contact.Website,
                BusinessName       = business.BusinessName,
                BusinessType       = business.BusinessType.Description,
                Enabled            = business.Enabled,
                Location           = address.Location,
                State              = state.Name,
                Country            = country.Name,
                IsDaikinBranch     = (business.BusinessTypeId == (BusinessTypeEnum)200002) ? true : false,
                IsDaikinComfortPro = business.IsDaikinComfortPro,
                IsVRVPro           = business.IsVRVPro
            };

            this.Response.Model = query.ToList();

            return(this.Response);
        }
示例#4
0
        public ServiceResponse GetBusinessModel(UserSessionModel admin, SearchBusiness search)
        {
            var busId = Db.BusinessQueryBySearch(admin, search).Select(s => s.BusinessId).FirstOrDefault();

            if (busId > 0)
            {
                this.Response = GetBusinessModel(admin, busId, false);
                addressService.FinaliseModel((this.Response.Model as BusinessModel).Address);
            }
            else
            {
                this.Response.Model = null;
            }

            return(this.Response);
        }
示例#5
0
        public IQueryable <Business> BusinessQueryBySearch(SearchBusiness search)
        {
            var query = QueryBusinessViewableByUser(null, true);

            query = Filter(query, search);

            if (search != null && search.ReturnTotals)
            {
                search.TotalRecords = query.Count();
            }

            query = Sort(query, search);

            query = Paging(new UserSessionModel(), query, search); // Must be Last

            return(query);
        }
示例#6
0
        private BusinessModel SearchForBusiness(UserModel model)
        {
            // If no business or business name for lookup, return null
            if (model.Business == null ||
                string.IsNullOrEmpty(model.Business.BusinessName))
            {
                return(null);
            }

            //If there is an ID, we will use that for lookup later
            if (!string.IsNullOrEmpty(model.Business.AccountId) &&
                !string.IsNullOrEmpty(model.Business.DaikinCityId))
            {
                return(null);
            }


            SearchBusiness busSearch = new SearchBusiness
            {
                ExactBusinessName = model.Business.BusinessName,
                ReturnTotals      = true
            };

            if (model.Address != null)
            {
                var addr = model.Address;

                busSearch.CountryCode = addr.CountryCode;
                busSearch.StateId     = addr.StateId;
                busSearch.PostalCode  = addr.PostalCode;
            }

            // Returns all businesses that match without permissions applied
            var bus = businessService.GetBusinessModel(null, busSearch);

            if (bus != null &&
                bus.IsOK &&
                bus.Model != null)
            {
                // TODO:  Send request to super user
                return(bus.Model as BusinessModel);
            }

            return(null);
        }
示例#7
0
        public void TestBusinessServices_Super_Admin_Can_See_All_Businesses()
        {
            var sa = GetUserSessionModel("*****@*****.**");

            var search = new SearchBusiness();

            search.PageSize = Constants.DEFAULT_PAGESIZE_RETURN_ALL;

            var response = service.GetBusinessListModel(null, search);

            var result = response.Model as List <BusinessListModel>;

            // this where clause is necessary becuase the daikin test import currently doesnt have country so canadian businesses
            // have null states
            int count = db.Businesses.Count();

            Assert.AreEqual(result.Count(), count);
        }
示例#8
0
        public void TestBusinessServices_Can_See_All_Businesses_Under_User_Groups()
        {
            // Test regional manager1
            var rm1 = GetUserSessionModel("*****@*****.**");

            var search = new SearchBusiness();

            var response = service.GetBusinessListModel(rm1, search);

            var results = response.Model as List <BusinessListModel>;

            Assert.AreEqual(results.Count(), 5);

            // Test regional manager2
            var rm2 = GetUserSessionModel("*****@*****.**");

            response = service.GetBusinessListModel(rm2, search);

            results = response.Model as List <BusinessListModel>;

            Assert.AreEqual(results.Count(), 5);
        }
示例#9
0
        public ServiceResponse GetBusinessModel(UserSessionModel admin, long?businessId, bool isEditing = false)
        {
            BusinessModel model = null;

            if (businessId.HasValue)
            {
                var query = from business in this.Db.BusinessQueryByBusinessId(admin, businessId.Value)
                            join bustype in this.Db.BusinessTypes on business.BusinessTypeId equals bustype.BusinessTypeId into Lbt
                            from bustype in Lbt
                            select new BusinessModel
                {
                    BusinessId              = business.BusinessId,
                    BusinessName            = business.BusinessName,
                    AccountId               = business.AccountId,
                    DaikinCityId            = business.DaikinCityId,
                    ShowPricing             = business.ShowPricing,
                    CommissionSchemeAllowed = business.CommissionSchemeAllowed,
                    BusinessTypeId          = (int)business.BusinessTypeId,
                    BusinessTypeDescription = bustype.Description,
                    Enabled      = business.Enabled,
                    Timestamp    = business.Timestamp,
                    ERPAccountId = (business.ERPAccountId == null) ? null : business.ERPAccountId,
                    Address      = new AddressModel
                    {
                        AddressId = business.AddressId,
                    },
                    Contact = new ContactModel
                    {
                        ContactId = business.ContactId,
                    },
                    AccountManagerEmail = business.AccountManagerEmail,
                    AccountOwnerEmail   = business.AccountOwnerEmail,
                    IsDaikinBranch      = (business.BusinessTypeId == (BusinessTypeEnum)200002) ? true : false,
                    IsDaikinComfortPro  = business.IsDaikinComfortPro,
                    IsVRVPro            = business.IsVRVPro
                };

                model = query.FirstOrDefault();

                //Get Parent Business if available
                var businessLink = this.Db.BusinessLinkQueryByBusinessId(model.BusinessId).FirstOrDefault();

                if (businessLink != null)
                {
                    if (businessLink.BusinessId != businessLink.ParentBusinessId)// this check to prevent infinite loop
                    {
                        SearchBusiness businessSearch = new SearchBusiness
                        {
                            BusinessId   = businessLink.ParentBusinessId,
                            ReturnTotals = true
                        };
                        var resp = GetBusinessModel(admin, businessSearch);
                        if (resp != null && resp.IsOK && resp.Model != null)
                        {
                            var parentBusiness = resp.Model as BusinessModel;
                            model.ParentBusinessId   = (long)parentBusiness.BusinessId;
                            model.ParentBusinessName = parentBusiness.BusinessName;
                        }
                    }
                }

                if (model == null)
                {
                    this.Response.AddError(Resources.DataMessages.DM006);
                }
            }

            model = model ?? new BusinessModel();

            model.Address = addressService.GetAddressModel(admin, model.Address);

            model.Contact = contactService.GetContactModel(admin, model.Contact);

            FinaliseModel(admin, model, isEditing);

            this.Response.Model = model;

            return(this.Response);
        }
示例#10
0
        private IQueryable <Business> Sort(IQueryable <Business> query, SearchBusiness search)
        {
            if (search == null)
            {
                return(query);
            }

            bool desc = search.IsDesc;

            switch ((search.SortColumn ?? "").ToLower())
            {
            case "accountid":
                query = (desc) ? query.OrderByDescending(s => s.AccountId) : query.OrderBy(s => s.AccountId);
                break;

            case "businesstype":
                query = (desc) ? query.OrderByDescending(s => s.BusinessType.Description) : query.OrderBy(s => s.BusinessType.Description);
                break;

            case "location":
            case "city":
                query = (desc) ? query.OrderByDescending(s => s.Address.Location) : query.OrderBy(s => s.Address.Location);
                break;

            case "state":
                query = (desc) ? query.OrderByDescending(s => s.Address.State.Name) : query.OrderBy(s => s.Address.State.Name);
                break;

            case "country":
                query = (desc) ? query.OrderByDescending(s => s.Address.State.Country.Name) : query.OrderBy(s => s.Address.State.Country.Name);
                break;

            case "webaddress":
                query = (desc) ? query.OrderByDescending(s => s.Contact.Website) : query.OrderBy(s => s.Contact.Website);
                break;

            case "enabled":
                query = (desc) ? query.OrderByDescending(s => s.Enabled) : query.OrderBy(s => s.Enabled);
                break;

            case "commissionable":
                query = (desc) ? query.OrderByDescending(s => s.CommissionSchemeAllowed) : query.OrderBy(s => s.CommissionSchemeAllowed);
                break;

            case "daikinbranch":
                query = (desc) ? query.OrderByDescending(s => s.BusinessTypeId == (BusinessTypeEnum)200002) : query.OrderBy(s => s.BusinessTypeId);
                break;

            case "vrvpro":
                query = (desc) ? query.OrderByDescending(s => s.IsVRVPro) : query.OrderBy(s => s.IsVRVPro);
                break;

            case "daikincomfortpro":
                query = (desc) ? query.OrderByDescending(s => s.IsDaikinComfortPro) : query.OrderBy(s => s.IsDaikinComfortPro);
                break;

            default:
                query = (desc) ? query.OrderByDescending(s => s.BusinessName) : query.OrderBy(s => s.BusinessName);
                break;
            }

            return(query);
        }
示例#11
0
        private IQueryable <Business> Filter(IQueryable <Business> query, SearchBusiness search)
        {
            if (search == null)
            {
                return(query);
            }

            if (search.BusinessId.HasValue)
            {
                query = query.Where(s => s.BusinessId == search.BusinessId);
            }

            if (!string.IsNullOrEmpty(search.BusinessName))
            {
                query = query.Where(s => s.BusinessName.Contains(search.BusinessName));
            }

            if (!string.IsNullOrEmpty(search.ExactBusinessName))
            {
                query = query.Where(s => s.BusinessName == search.ExactBusinessName);
            }

            if (!string.IsNullOrEmpty(search.AccountId))
            {
                query = query.Where(s => s.AccountId == search.AccountId);
            }

            if (!string.IsNullOrEmpty(search.Address))
            {
                query = query.Where(s => s.Address.AddressLine1.Contains(search.Address));
            }

            if (search.StateId != null)
            {
                query = query.Where(s => s.Address.StateId == search.StateId);
            }

            if (!string.IsNullOrEmpty(search.StateCode))
            {
                query = query.Where(s => s.Address.State.Code == search.StateCode);
            }

            if (!string.IsNullOrEmpty(search.PostalCode))
            {
                query = query.Where(s => s.Address.PostalCode == search.PostalCode);
            }

            if (!string.IsNullOrEmpty(search.CountryCode))
            {
                query = query.Where(s => s.Address.State.CountryCode == search.CountryCode);
            }

            if (!string.IsNullOrEmpty(search.Filter))
            {
                query = query.Where(s => s.BusinessName.Contains(search.Filter));
            }

            if (search.Enabled != null)
            {
                query = query.Where(s => s.Enabled == search.Enabled.Value);
            }

            if (search.IsDaikinComfortPro.GetValueOrDefault())
            {
                query = query.Where(s => s.IsDaikinComfortPro == search.IsDaikinComfortPro);
            }

            if (search.IsVRVPro.GetValueOrDefault())
            {
                query = query.Where(s => s.IsVRVPro == search.IsVRVPro);
            }

            if (search.IsDaikinBranch.GetValueOrDefault())
            {
                query = query.Where(s => s.BusinessTypeId == (BusinessTypeEnum)200002);
            }

            return(query);
        }