public async Task <IActionResult> GetProductionOrder(int id) { var prodOrderFromRepo = await _repository.GetProductionOrder(id); var prodOrderToReturn = _mapper.Map <ProdOrderHeaderForDetailDto>(prodOrderFromRepo); return(Ok(prodOrderToReturn)); }
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"))); }