public dynamic SearchRegions(RegionSearchRequest request)
        {
            SearchByID searchByID = new SearchByID();

            SearchByRegionName searchByRegionName = new SearchByRegionName();

            SearchByHeadOffice searchByHeadOffice = new SearchByHeadOffice();

            List <string> errors = new List <string>();

            DBC dbc = DBC.DatabaseConnection();

            if (!string.IsNullOrWhiteSpace(request.RegionID))
            {
                return(searchByID
                       .SearchEntitiesByID(dbc, "Regions", request.RegionID, errors));
            }

            if (!string.IsNullOrWhiteSpace(request.RegionName))
            {
                return(searchByRegionName
                       .SearchRegionsByName(dbc, request.RegionName, errors));
            }

            if (!string.IsNullOrWhiteSpace(request.HeadOffice))
            {
                return(searchByHeadOffice
                       .SearchRegionsByHeadOffice(dbc, request.HeadOffice, errors));
            }
            else
            {
                return(new NoParameterRegionResponse("No regions found. Please check your request for validity against the fields below."));
            }
        }
        public dynamic SearchOffices(OfficeSearchRequest request)
        {
            SearchByID searchByID = new SearchByID();

            SearchByOfficeName searchByOfficeName = new SearchByOfficeName();

            SearchByOfficeManager searchByOfficeManager = new SearchByOfficeManager();

            List <string> errors = new List <string>();

            DBC dbc = DBC.DatabaseConnection();

            if (!string.IsNullOrWhiteSpace(request.OfficeID))
            {
                return(searchByID
                       .SearchEntitiesByID(dbc, "Offices", request.OfficeID, errors));
            }

            if (!string.IsNullOrWhiteSpace(request.OfficeName))
            {
                return(searchByOfficeName
                       .SearchByName(dbc, request.OfficeName, errors));
            }

            if (!string.IsNullOrWhiteSpace(request.OfficeManager))
            {
                return(searchByOfficeManager
                       .SearchByManager(dbc, request.OfficeManager, errors));
            }
            else
            {
                return(new NoParameterOfficeResponse("No offices found. Please check your request for validity against the fields below."));
            }
        }
示例#3
0
        public dynamic SearchSubscriptionTypes(SubscriptionTypeSearchRequest request)
        {
            SearchByID searchByID = new SearchByID();

            SearchByName searchByName = new SearchByName();

            SearchByPriceRange searchByPriceRange = new SearchByPriceRange();

            List <string> errors = new List <string>();

            DBC dbc = DBC.DatabaseConnection();

            if (!string.IsNullOrWhiteSpace(request.SubscriptionID))
            {
                return(searchByID
                       .SearchEntitiesByID(dbc, "SubscriptionTypes", request.SubscriptionID, errors));
            }

            if (!string.IsNullOrWhiteSpace(request.SubscriptionName))
            {
                return(searchByName
                       .SearchSubscriptionTypesByName(dbc, request.SubscriptionName, errors));
            }

            if (!string.IsNullOrWhiteSpace(request.SubscriptionMonthlyFeeMin) &&
                !string.IsNullOrWhiteSpace(request.SubscriptionMonthlyFeeMax))
            {
                return(searchByPriceRange
                       .SearchSubscriptionTypesByPriceRange(dbc,
                                                            request.SubscriptionMonthlyFeeMin,
                                                            request.SubscriptionMonthlyFeeMax,
                                                            errors));
            }
            else if (string.IsNullOrWhiteSpace(request.SubscriptionMonthlyFeeMin) &&
                     !string.IsNullOrWhiteSpace(request.SubscriptionMonthlyFeeMax))
            {
                return(searchByPriceRange
                       .SearchSubscriptionTypesByPriceRange(dbc,
                                                            "0",
                                                            request.SubscriptionMonthlyFeeMax,
                                                            errors));
            }
            else if (!string.IsNullOrWhiteSpace(request.SubscriptionMonthlyFeeMin) &&
                     string.IsNullOrWhiteSpace(request.SubscriptionMonthlyFeeMax))
            {
                return(searchByPriceRange
                       .SearchSubscriptionTypesByPriceRange(dbc,
                                                            request.SubscriptionMonthlyFeeMin,
                                                            "0",
                                                            errors));
            }
            else
            {
                return(new NoParameterSubscriptionTypeResponse("No subscription types found. Please check your request for validity against the fields below."));
            }
        }
示例#4
0
        public dynamic SearchByUser(UsersSearchRequest request)
        {
            SearchByID searchByID = new SearchByID();

            SearchByName searchByName = new SearchByName();

            SearchByRegion searchByRegion = new SearchByRegion();

            SearchBySubscriptionType searchBySubscriptionType = new SearchBySubscriptionType();

            SearchByActiveSubscription searchByActiveSubscription = new SearchByActiveSubscription();

            List <string> errors = new List <string>();

            List <User> matchedUsers = new List <User>();

            DBC dbc = DBC.DatabaseConnection();

            if (!string.IsNullOrEmpty(request.UserID))
            {
                return(searchByID.SearchEntitiesByID(dbc, "Users", request.UserID, errors));
            }

            if (!string.IsNullOrWhiteSpace(request.FirstName) ||
                !string.IsNullOrWhiteSpace(request.LastName))
            {
                var result = searchByName.SearchUsersByName(dbc, request, errors);

                if (result.GetType() == typeof(List <User>))
                {
                    matchedUsers = result;
                }
                else
                {
                    foreach (string error in (List <string>)result)
                    {
                        errors.Add(error);
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(request.Region))
            {
                var result = searchByRegion.SearchUsersByRegion(dbc,
                                                                request.Region,
                                                                errors,
                                                                matchedUsers);

                if (result.GetType() == typeof(List <User>))
                {
                    matchedUsers = result;
                }
                else
                {
                    foreach (string error in (List <string>)result)
                    {
                        errors.Add(error);
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(request.SubscriptionType))
            {
                var result = searchBySubscriptionType
                             .SearchUsersBySubscriptionType(dbc,
                                                            request.SubscriptionType,
                                                            errors,
                                                            matchedUsers);

                if (result.GetType() == typeof(List <User>))
                {
                    matchedUsers = result;
                }
                else
                {
                    foreach (string error in (List <string>)result)
                    {
                        errors.Add(error);
                    }
                }
            }

            if (request.ActiveSubscription != null)
            {
                var result = searchByActiveSubscription
                             .SearchUsersByActiveSubscription(dbc,
                                                              request.ActiveSubscription,
                                                              errors,
                                                              matchedUsers);

                if (result.GetType() == typeof(List <User>))
                {
                    List <UserDTO> userDTOs = new List <UserDTO>();

                    foreach (User user in result)
                    {
                        userDTOs.Add(new UserDTO(user, dbc));
                    }

                    return(userDTOs);
                }
                else
                {
                    matchedUsers = new List <User>();

                    errors = result;
                }
            }

            if (matchedUsers.Any())
            {
                List <UserDTO> userDTOs = new List <UserDTO>();

                foreach (User user in matchedUsers)
                {
                    userDTOs.Add(new UserDTO(user, dbc));
                }

                return(userDTOs);
            }
            else if (errors.Any())
            {
                return(errors);
            }
            else
            {
                return(new NoParameterUserResponse("No users found. Please check your request for validity against the fields below."));
            }
        }