public IActionResult Post([FromBody] ProductionPlanRequest body)
        {
            var load        = body.Load;
            var powerPlants = _mapper.Map <ICollection <PowerPlant> >(body);

            var productionPlan = _productionPlanService.CalculateUnitCommitment(load, powerPlants);

            if (productionPlan.IsSuccessFul)
            {
                return(Ok(_mapper.Map <ICollection <UnitCommitmentResponse> >(productionPlan.PowerPlants)));
            }

            return(BadRequest(productionPlan.ErrorMessage));
        }
Esempio n. 2
0
        public IEnumerable <PowerPlantResult> Post(ProductionPlanRequest productionPlanRequest)
        {
            // Map DTO to core entity
            var plan = mapper.MapToProductionPlan(productionPlanRequest);

            // Execute core logics
            var result = productionPlanner.Plan(plan);

            // Create initial results which is combined with result return from core.
            // This is to make sure power plants that generate no power is also returned in the api response.
            // The core does not return power plants that do not generate power.
            var initialResults = productionPlanRequest.PowerPlants.Select(p => new PowerPlantResult()
            {
                PowerPlantName = p.Name, Power = 0
            });

            // Map and return result.
            return(result.Select(p => mapper.Map <Models.PowerPlantResult>(p)).Union(initialResults));
        }
Esempio n. 3
0
        /// <summary>
        /// Maps <see cref="ProductionPlanRequest"/> to <see cref="Core.Entities.ProductionPlan"/>
        /// </summary>
        /// <param name="mapper">The <see cref="IMapper"/> instance</param>
        /// <param name="request">The <see cref="ProductionPlanRequest"/> instance</param>
        /// <returns>A new instance of <see cref="Core.Entities.ProductionPlan"/></returns>
        public static Core.Entities.ProductionPlan MapToProductionPlan(this IMapper mapper, ProductionPlanRequest request)
        {
            // Map simple fields
            var plan = mapper.Map <Core.Entities.ProductionPlan>(request);

            // Map the power plants by their type
            plan.PowerPlants = request.PowerPlants.Select <PowerPlant, Core.Entities.PowerPlant>(p => {
                switch (p.Type)
                {
                case PowerPlantType.GASFIRED:
                    {
                        var powerPlant = mapper.Map <Core.Entities.GasPowerPlant>(p);

                        powerPlant.GasPrice = request.FuelCosting.GasPrice;

                        return(powerPlant);
                    }

                case PowerPlantType.WINDTURBINE:
                    {
                        var powerPlant = mapper.Map <Core.Entities.WindPowerPlant>(p);

                        powerPlant.WindPercentage = request.FuelCosting.WindPercentage;

                        return(powerPlant);
                    }

                case PowerPlantType.TURBOJET:
                    {
                        var powerPlant = mapper.Map <Core.Entities.TurboJetPowerPlant>(p);

                        powerPlant.KerosinePrice = request.FuelCosting.KerosinePrice;

                        return(powerPlant);
                    }

                default:
                    throw new MappingException($"Cannot map power plant {p.Name}");
                }
            });

            return(plan);
        }