protected override IResult ExecuteTemplate(IManagementModelRequest <IConfigSupply> obj) { IConfigSupply itemRequest = obj.Item; var supplyScheduled = _supplyScheduledService.Get(itemRequest.Product.Code, itemRequest.WorkerInWorkPlace.Worker.Code, itemRequest.WorkerInWorkPlace.WorkPlace.Code, itemRequest.PeriodDate); if (supplyScheduled != null) { if (supplyScheduled.Amount == obj.Item.Amount) { obj.Item.SupplyScheduled = supplyScheduled; return(OkAndFinish("The Configuration is the same as the one already registered in the system")); } var productsReceived = _productSupplyService.GetProductSuppliedToWorker(itemRequest.Product.Code, itemRequest.WorkerInWorkPlace.Worker.Code, itemRequest.WorkerInWorkPlace.WorkPlace.Code, itemRequest.PeriodDate); if (productsReceived.Count() >= obj.Item.Amount) { return(new Result(EnumResultBL.ERROR_THE_NEW_AMOUNT_MEANT_TO_BE_SET_IS_SMALLER_THAN_THE_ONE_ALREADY_SUPPLIED, itemRequest.WorkerInWorkPlace.Worker.Code, supplyScheduled.Amount, obj.Item.Product.Code, itemRequest.WorkerInWorkPlace.WorkPlace.Code, itemRequest.PeriodDate)); } } itemRequest.SupplyScheduled = supplyScheduled; return(Result.Ok); }
protected override IResult ExecuteTemplate(IManagementModelRequest <IProductSupply> obj) { IProductSupply itemRequest = obj.Item; var supplyScheduled = _supplyScheduledService.Get(itemRequest.Product.Code, itemRequest.WorkerInWorkPlace.Worker.Code, itemRequest.WorkerInWorkPlace.WorkPlace.Code, itemRequest.PeriodDate); if (supplyScheduled == null) { return(new Result(EnumResultBL.ERROR_WORKER_NOT_FOUND_A_SUPPLY_SCHEDULED_OF_THE_PRODUCT_FOR_THE_WORKER_AND_WORKPLACE_IN_THE_DATE, itemRequest.WorkerInWorkPlace.Worker.Code, itemRequest.Product.Code, itemRequest.WorkerInWorkPlace.WorkPlace.Code, itemRequest.PeriodDate)); } var productsReceived = _productSupplyService.GetProductSuppliedToWorker(itemRequest.Product.Code, itemRequest.WorkerInWorkPlace.Worker.Code, itemRequest.WorkerInWorkPlace.WorkPlace.Code, itemRequest.PeriodDate); if (productsReceived.ToList().Count >= supplyScheduled.Amount) { return(new Result(EnumResultBL.ERROR_WORKER_HAS_REACHED_THE_LIMIT_OF_PRODUCTS_OF_THIS_TYPE, itemRequest.WorkerInWorkPlace.Worker.Code, supplyScheduled.Amount, itemRequest.Product.Code, itemRequest.WorkerInWorkPlace.WorkPlace.Code, itemRequest.PeriodDate)); } return(Result.Ok); }