Example #1
0
        public CommandModelDTO ToDTO(CommandModel commandModel)
        {
            CommandModelDTO commandModelDTO = new CommandModelDTO();

            commandModelDTO.Id            = commandModel.Id;
            commandModelDTO.CreatedAt     = commandModel.CreatedAt;
            commandModelDTO.StateEnum     = commandModel.StateEnum;
            commandModelDTO.ChoicePaiment = commandModel.ChoicePaiment;

            List <PlantModelDTO> plantsDTO = new List <PlantModelDTO>();

            foreach (var p in commandModel.Plants)
            {
                PlantModelDTO plantModelDTO = new PlantModelDTO();
                plantModelDTO.Id    = p.Id;
                plantModelDTO.Name  = p.Name;
                plantModelDTO.Price = p.Price;
                plantModelDTO.Type  = p.Type;

                plantsDTO.Add(plantModelDTO);
            }

            commandModelDTO.Plants = plantsDTO;

            return(commandModelDTO);
        }
Example #2
0
        public PlantModelDTO AddPlant(PlantModelDTO plantModel)
        {
            List <PlantModelDTO> plants = FindAll();

            plants.Add(plantModel);

            return(plantModel);
        }
Example #3
0
        public PlantModel ToEntity(PlantModelDTO plantDTO)
        {
            PlantModel plant = new PlantModel();

            plant.Name  = plantDTO.Name;
            plant.Price = plantDTO.Price;
            plant.Type  = plantDTO.Type;
            return(plant);
        }
Example #4
0
        public PlantModelDTO ToDTO(PlantModel plant)
        {
            PlantModelDTO plantDTO = new PlantModelDTO();

            plantDTO.Name  = plant.Name;
            plantDTO.Price = plant.Price;
            plantDTO.Type  = plant.Type;
            return(plantDTO);
        }
Example #5
0
        public ActionResult <PlantModelDTO> UpdatePlant(PlantModelDTO plantModel)
        {
            if (plantModel == null)
            {
                return(BadRequest("Error : null parameter for plant model."));
            }

            PlantModelDTO result = this.plantService.UpdatePlant(plantModel);

            if (result == null)
            {
                return(BadRequest("Error when updating the plant with id : " + plantModel.Id));
            }

            return(result);
        }
Example #6
0
        public PlantModelDTO UpdatePlant(PlantModelDTO plantModel)
        {
            List <PlantModelDTO> plants = FindAll();

            int index = plants.Select(x => x.Id).ToList().IndexOf(plantModel.Id);

            if (index == -1)
            {
                return(null);
            }

            plants.RemoveAt(index);
            plants.Insert(index, plantModel);

            return(plantModel);
        }