protected Expression <Func <ProductionTriggerLevel, bool> > SearchExpression(ProductionTriggerLevelsSearchRequestResource searchTerms)
 {
     return(w =>
            (string.IsNullOrWhiteSpace(searchTerms.SearchTerm) || w.PartNumber.ToUpper().Contains(searchTerms.SearchTerm.ToUpper())) &&
            (string.IsNullOrWhiteSpace(searchTerms.CitSearchTerm) || w.CitCode == searchTerms.CitSearchTerm) &&
            (searchTerms.OverrideSearchTerm == "null" || w.OverrideTriggerLevel > int.Parse(searchTerms.OverrideSearchTerm)) &&
            (searchTerms.AutoSearchTerm == "null" || w.VariableTriggerLevel > int.Parse(searchTerms.AutoSearchTerm)));
 }
Beispiel #2
0
        public void SetUp()
        {
            var ptl1 = new ProductionTriggerLevel {
                PartNumber = "pcas1", Description = "d1"
            };
            var ptl2 = new ProductionTriggerLevel {
                PartNumber = "pcas2", Description = "d2"
            };
            var requestResource = new ProductionTriggerLevelsSearchRequestResource
            {
                SearchTerm         = "pcas",
                CitSearchTerm      = "S",
                AutoSearchTerm     = "0",
                OverrideSearchTerm = "0",
            };

            this.ProductionTriggerLevelService.Search(
                Arg.Is <ProductionTriggerLevelsSearchRequestResource>(
                    x => x.CitSearchTerm == "S" && x.SearchTerm == "pcas" && x.AutoSearchTerm == "0" && x.OverrideSearchTerm == "0"),
                Arg.Any <IEnumerable <string> >())
            .Returns(new SuccessResult <ResponseModel <IEnumerable <ProductionTriggerLevel> > >(
                         new ResponseModel <IEnumerable <ProductionTriggerLevel> >(
                             new List <ProductionTriggerLevel> {
                ptl1, ptl2
            },
                             new List <string>())));

            this.Response = this.Browser.Get(
                "/production/maintenance/production-trigger-levels",
                with =>
            {
                with.Header("Accept", "application/json");
                with.Query("SearchTerm", requestResource.SearchTerm);
                with.Query("AutoSearchTerm", requestResource.AutoSearchTerm);
                with.Query("OverrideSearchTerm", requestResource.OverrideSearchTerm);
                with.Query("CitSearchTerm", requestResource.CitSearchTerm);
            }).Result;
        }
 public IResult <ResponseModel <IEnumerable <ProductionTriggerLevel> > > Search(ProductionTriggerLevelsSearchRequestResource searchTerms, IEnumerable <string> privileges)
 {
     try
     {
         return(new SuccessResult <ResponseModel <IEnumerable <ProductionTriggerLevel> > >(
                    new ResponseModel <IEnumerable <ProductionTriggerLevel> >(this.repository.FilterBy(this.SearchExpression(searchTerms)), privileges)));
     }
     catch (NotImplementedException ex)
     {
         return(new BadRequestResult <ResponseModel <IEnumerable <ProductionTriggerLevel> > >("Search is not implemented"));
     }
 }