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); }
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 <ITask> obj) { if (obj.Type == EnumOperation.EDITION) { return(_taskServices.Validation(obj.Item)); } return(Result.Ok); }
protected override IResult ExecuteTemplate(IManagementModelRequest <ITask> obj) { if (obj.Type == EnumOperation.NEW) { if (obj.Item.Status == EnumStatusTask.Pending) { return(Result.Ok); } return(new Result(EnumResultBL.ERROR_STATUS_NOT_ALLOWED_ON_CREATION, obj.Item.Status)); } return(Result.Ok); }
protected override IResult ExecuteTemplate(IManagementModelRequest <T> obj) { if (obj.Type == EnumOperation.NEW) { return(_service.Add(obj.Item)); } else if (obj.Type == EnumOperation.EDITION) { return(_service.Edit(obj.Item)); } return(Result.Ok); }
protected override IResult ExecuteTemplate(IManagementModelRequest <IProductSupply> obj) { var itemRequest = obj.Item; var resProductStock = _productStockService.GetAvailable(itemRequest.Product); if (resProductStock.ComputeResult().IsError()) { return(resProductStock); } itemRequest.ProductsSupplied.Clear(); foreach (var it in resProductStock.GetItems()) { itemRequest.ProductsSupplied.Add(new ProductSupplied { ProductSupply = itemRequest, ProductStock = it }); } var productsInStock = itemRequest.ProductsSupplied.Select(x => x.ProductStock).ToList(); var resultBooking = _productStockService.BookingRequest(productsInStock, itemRequest.WorkerInWorkPlaceId); if (resultBooking.ComputeResult().IsError()) { _productStockService.BookingRequest(productsInStock, 0); if (!resultBooking.TryAgain) { return(resultBooking); } return(ExecuteTemplate(obj)); } if (itemRequest.Id == 0) { _productSupplyService.Add(itemRequest); } else { _productSupplyService.Edit(itemRequest); } return(Result.Ok); }
protected override IResult ExecuteTemplate(IManagementModelRequest <T> req) { if (_permissions == null || _permissions.Length == 0) { return(Result.Ok); } PermisionValidate covered = _permissions.FirstOrDefault(x => req.Type == x.Operation); if (covered == null) { return(Result.Ok); } if (!_userService.Validate(req.User, covered.Permission)) { return(new Result(EnumResultBL.ERROR_PERMISSION_VALIDATIONS)); } return(Result.Ok); }
protected override IResult ExecuteTemplate(IManagementModelRequest <IConfigSupply> obj) { if (obj.Item.SupplyScheduled != null && obj.Item.SupplyScheduled.Id > 0) { obj.Item.SupplyScheduled.Amount = obj.Item.Amount; } else { obj.Item.SupplyScheduled = new SupplyScheduled { Product = obj.Item.Product, PeriodDate = obj.Item.PeriodDate, WorkerInWorkPlace = obj.Item.WorkerInWorkPlace, Amount = obj.Item.Amount }; } obj.Item.SupplyScheduled.ConfiguratedBy.Add(obj.Item); _supplyScheduledService.Save(obj.Item.SupplyScheduled); return(Result.Ok); }
protected override IResult ExecuteTemplate(IManagementModelRequest <ITask> obj) { return(_validationService.Validation(obj.Item)); }