/// <summary>
        /// Converts the Product to a Get All Response
        /// </summary>
        /// <returns></returns>
        public Sheev.Common.Models.GetAllResponse ConvertToGetAllResponse()
        {
            var response = new Sheev.Common.Models.GetAllResponse();

            // Build the response
            response.Id          = Id;
            response.Name        = Name;
            response.Description = Description;

            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// Get all location groups
        /// </summary>
        /// <param name="queryString"></param>
        /// <param name="context"></param>
        /// <param name="count"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List <Sheev.Common.Models.GetAllResponse> GetAll(string queryString, ref long count, int?pageNumber = 1, int?pageSize = 100)
        {
            // Paging
            int limit = (int)pageSize;
            int start = (int)pageNumber == 1 ? 0 : (int)(pageNumber - 1) * limit;

            // Response
            List <Sheev.Common.Models.GetAllResponse> response = new List <Sheev.Common.Models.GetAllResponse>();

            // Company Id
            var companyId = context.Security.GetCompanyId();

            // Dictonary
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            // Action
            string action = string.Empty;

            // MongoDB Settings
            var    database       = context.MongoDbSettings.Value.Databases.FirstOrDefault(x => x.Name == "DeathStar");
            string collectionName = database.Collections.FirstOrDefault(x => x.Name == "PC_LocationGroup").Name;

            // Get MongoDB
            var db = context.Database;
            var locationGroupCollection = db.GetCollection <Deathstar.Data.Models.PC_LocationGroup>(collectionName);

            // Add Company Id filter
            dictionary.Add("DV_CompanyId", companyId.ToString());

            // Filter
            if (!string.IsNullOrEmpty(queryString))
            {
                Utilities.MongoFilter.BuildFilterDictionary(queryString, ref action, ref dictionary);
            }

            // Check for invalid filters
            //CheckForInvalidFilters(dictionary);

            // Filter Builder
            FilterDefinition <Deathstar.Data.Models.PC_LocationGroup> filters;

            // Handle Action
            switch (action.ToLower())
            {
            case "contains":
                filters = Utilities.MongoFilter.BuildFilters <Deathstar.Data.Models.PC_LocationGroup>(fieldContainsValue: dictionary);
                break;

            default:
                filters = Utilities.MongoFilter.BuildFilters <Deathstar.Data.Models.PC_LocationGroup>(fieldEqValue: dictionary);
                break;
            }

            count = locationGroupCollection.Find(filters).CountDocuments();
            var dbLocationGroups = locationGroupCollection.Find(filters).SortByDescending(x => x.CreatedDateTime).Skip(start).Limit(limit).ToList();

            foreach (var dbLocationGroup in dbLocationGroups)
            {
                var singleResponse = new Sheev.Common.Models.GetAllResponse()
                {
                    Id          = dbLocationGroup.Id,
                    Name        = dbLocationGroup.Name,
                    Description = dbLocationGroup.Description
                };

                response.Add(singleResponse);
            }

            return(response);
        }