Example #1
0
        public void SetUp()
        {
            var wwdResults = new WwdResult()
            {
                PartNumber      = "KYLEGUARD",
                WwdJobId        = 1,
                PtlJobref       = "CJCAIH",
                Qty             = 5,
                WorkStationCode = "KGUARD",
                WwdDetails      = new List <WwdDetail>
                {
                    new WwdDetail {
                        PartNumber = "KYLE", Description = "KYLE", WwdJobId = 1, PtlJobref = "CJCAIH", QtyAtLocation = 1, QtyKitted = 5, StoragePlace = "K-ZONE"
                    },
                    new WwdDetail {
                        PartNumber = "GUARD", Description = "GUARD", WwdJobId = 1, PtlJobref = "CJCAIH", QtyAtLocation = 0, QtyKitted = 5, StoragePlace = "P100"
                    }
                }
            };

            this.WwdResultFacadeService.GenerateWwdResultForTrigger("KYLEGUARD", 5, "CJCAIH")
            .Returns(new SuccessResult <WwdResult>(wwdResults));

            this.Response = this.Browser.Get(
                "/production/reports/wwd",
                with =>
            {
                with.Header("Accept", "application/json");
                with.Query("ptlJobref", "CJCAIH");
                with.Query("qty", "5");
                with.Query("partNumber", "KYLEGUARD");
            }).Result;
        }
        public IResult <WwdResult> GenerateWwdResultForTrigger(string partNumber, int?qty, string ptlJobref)
        {
            if (string.IsNullOrEmpty(partNumber))
            {
                return(new BadRequestResult <WwdResult>("No part number supplied."));
            }

            if (qty == null)
            {
                return(new BadRequestResult <WwdResult>("No qty supplied."));
            }

            var triggerLevel = this.productionTriggerLevelRepository.FindById(partNumber);

            if (triggerLevel == null)
            {
                return(new NotFoundResult <WwdResult>("No production trigger level found"));
            }

            if (string.IsNullOrEmpty(triggerLevel.WorkStationName))
            {
                return(new NotFoundResult <WwdResult>("No work station found"));
            }

            var result = new WwdResult
            {
                PartNumber      = partNumber,
                Qty             = qty.Value,
                WorkStationCode = triggerLevel.WorkStationName,
                PtlJobref       = ptlJobref,
                WwdRunTime      = DateTime.UtcNow,
                WwdJobId        = this.wwdTrigFunction.WwdTriggerRun(partNumber, qty.Value)
            };


            if (result.WwdJobId == 0)
            {
                return(new NotFoundResult <WwdResult>("Could not generate wwd work"));
            }

            result.WwdDetails =
                this.wwdDetailRepository.FilterBy(d => d.WwdJobId == result.WwdJobId && d.PtlJobref == ptlJobref);

            return(new SuccessResult <WwdResult>(result));
        }