public async Task <IActionResult> CreateProductionPlan(ProdPlanHeaderForDetailDto ProdPlanHeaderForDetailDto) { if (ProdPlanHeaderForDetailDto == null) { return(BadRequest(new ErrorModel(1, 400, "Empty Body"))); } if (ProdPlanHeaderForDetailDto.ProdOrdrIds == null) { return(BadRequest(new ErrorModel(2, 400, "Production orders needed"))); } if (ProdPlanHeaderForDetailDto.ProductionPlanDetails == null || ProdPlanHeaderForDetailDto.ProductionPlanRecipes == null || ProdPlanHeaderForDetailDto.ProductionPlanWorkers == null || ProdPlanHeaderForDetailDto.ProductionPlanMachines == null) { return(BadRequest(new ErrorModel(3, 400, "all nested details required"))); } var planHeaderToCreate = _mapper.Map <ProductionPlanHeader>(ProdPlanHeaderForDetailDto); planHeaderToCreate.BusinessPlace = await _repository.Get <BusinessPlace>(ProdPlanHeaderForDetailDto.BusinessPlaceId); planHeaderToCreate.ProductionSession = await _repository.Get <ProductionSession>(ProdPlanHeaderForDetailDto.ProductionSessionId); planHeaderToCreate.User = await _repository.Get <User>(ProdPlanHeaderForDetailDto.UserId); await _repository.CreateProductionPlan(planHeaderToCreate); if (await _repository.SaveAll()) { foreach (var prodOrderId in ProdPlanHeaderForDetailDto.ProdOrdrIds) { var prodOrder = await _repository.GetProductionOrder(prodOrderId); prodOrder.IsNotEditable = true; prodOrder.PlanId = planHeaderToCreate.Id; prodOrder.isProcessed = 0; } if (await _repository.SaveAll()) { var planHeaderToReturn = _mapper.Map <ProdPlanHeaderForDetailDto>(planHeaderToCreate); return(CreatedAtRoute(nameof(GetProductionPlan), new { planHeaderToCreate.Id }, planHeaderToReturn)); } return(BadRequest(new ErrorModel(4, 400, "created production plan, but some error occured"))); } return(BadRequest(new ErrorModel(4, 400, "Could not create production plan"))); }
public async Task <IActionResult> GetProductionSession(int id) { var sessionFromRepo = await _repository.Get <ProductionSession>(id); var sessionToReturn = _mapper.Map <ProdSessionForDetailDto>(sessionFromRepo); return(Ok(sessionToReturn)); }
public async Task <IActionResult> CreateProductionOrder(ProdOrderHeaderForDetailDto prodOrderHeaderForDetailDto) { if (prodOrderHeaderForDetailDto == null) { return(BadRequest("Empty Body")); } var prodOrderHeaderToCreate = _mapper.Map <ProductionOrderHeader>(prodOrderHeaderForDetailDto); prodOrderHeaderToCreate.BusinessPlace = await _repository.Get <BusinessPlace>(prodOrderHeaderForDetailDto.BusinessPlaceId); prodOrderHeaderToCreate.Session = await _repository.Get <ProductionSession>(prodOrderHeaderForDetailDto.SessionId); prodOrderHeaderToCreate.User = await _repository.Get <User>(prodOrderHeaderForDetailDto.UserId); await _repository.CreateProductionOrder(prodOrderHeaderToCreate); if (await _repository.SaveAll()) { var prodOrderHeaderToReturn = _mapper.Map <ProdOrderHeaderForDetailDto>(prodOrderHeaderToCreate); return(CreatedAtRoute(nameof(GetProductionOrder), new { prodOrderHeaderToCreate.Id }, prodOrderHeaderToReturn)); } return(BadRequest("Could not create production Order")); }
public async Task <List <Contract.Production> > Get() { return(await _productionRepository.Get()); }
public async Task <IEnumerable <Production> > Get() { return(await _productionRepository.Get()); }