Exemplo n.º 1
0
        public async Task <String> UpdateProductsAsync(HttpRequestMessage request, [FromBody] SingleOptions options)
        {
            var client     = new MongoClient(connectionStr);
            var db         = client.GetDatabase("dev-db");
            var collection = db.GetCollection <ProductFamilies>("product_families");
            var builder    = Builders <ProductFamilies> .Filter;
            FilterDefinition <ProductFamilies> filter = new BsonDocument();

            switch (options.MainCat)
            {
            case "REHAB":
                filter = builder.AnyEq(x => x.Categories, "REHAB");
                break;

            case "LTC":
                filter = builder.AnyEq(x => x.Categories, "LTC");
                break;

            default:
                break;
            }

            switch (options.ProdType)
            {
            case "SEATCU":
                filter &= builder.AnyEq(x => x.Categories, "SEATCU");
                break;

            case "BACKCU":
                filter &= builder.AnyEq(x => x.Categories, "BACKCU");
                break;

            case "ACCESS":
                filter &= builder.AnyEq(x => x.Categories, "ACCESS");
                break;

            default:
                break;
            }

            if (options.Hcpcs.Length > 0)
            {
                filter &= builder.AnyIn("hcpcs", options.Hcpcs);
            }

            var products = await collection.Find(filter)
                           .Project(Builders <ProductFamilies> .Projection.Exclude("_id"))
                           .ToListAsync();

            return(products.ToJson());
        }
Exemplo n.º 2
0
        public void SetResponse(object response)
        {
            if (ShowTextObs)        // Text
            {
                ResponseText = response.ToString();
            }

            if (ShowSingleObs)      //"Single";
            {
                var text = response.ToString();
                if (!string.IsNullOrWhiteSpace(text))
                {
                    var option = SingleOptions.FirstOrDefault(x => x.ItemId == new Guid(text));
                    SelectedSingleOption = option;
                }
            }

            if (ShowNumericObs)     //"Numeric";
            {
                var text = response.ToString();
                if (!string.IsNullOrWhiteSpace(text))
                {
                    decimal numeric;
                    decimal.TryParse(text, out numeric);
                    ResponseNumeric = numeric;
                }
            }

            if (ShowMultiObs)       //"Multi";
            {
                var itemIds = new List <Guid>();
                var ids     = response.ToString().Split(',');
                foreach (var id in ids)
                {
                    itemIds.Add(new Guid(id));
                }
                if (itemIds.Count > 0)
                {
                    var multiOptions = new List <CategoryItem>();
                    var options      = MultiOptions
                                       .Where(
                        x => itemIds.Contains(x.ItemId) &&
                        x.ItemId != Guid.Empty)
                                       .ToList();

                    foreach (var categoryItem in MultiOptions)
                    {
                        if (options.Any(x => x.ItemId == categoryItem.ItemId))
                        {
                            if (!categoryItem.Selected)
                            {
                                categoryItem.Selected = true;
                            }
                        }
                        multiOptions.Add(categoryItem);
                    }

                    MultiOptions = multiOptions;
                }
            }

            if (ShowDateObs)     //"Date";
            {
                var text = response.ToString();
                if (!string.IsNullOrWhiteSpace(text))
                {
                    DateTime dateTime;
                    DateTime.TryParse(text, out dateTime);
                    ResponseDate = dateTime;
                }
            }
        }