Example #1
0
        public IActionResult Create([FromBody] UserPlantCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(UnprocessableEntity(new ValidationErrorModel(ModelState)));
            }

            PlantType type = _plantData.GetPlantType(model.PlantTypeID);

            UserPlant plant = new UserPlant
            {
                OwnerID              = model.OwnerID,
                NickName             = model.NickName,
                WherePurchased       = model.WherePurchased,
                PlantType            = type,
                LastWatered          = model.LastWatered,
                WaterAgain           = GetNextWater(model.LastWatered, type),
                LastFertalized       = model.LastFertalized,
                FertalizeAgain       = GetNextFeed(model.LastFertalized, type),
                Birtdhday            = model.Birthday,
                IsDeleted            = false,
                ReceiveNotifications = model.ReceiveNotifications,
                IsFavorite           = false,
                PrimaryImageID       = model.PrimaryImageID ?? type.StockImageID
            };

            _plantData.Add(plant);
            _plantData.Commit();
            return(Created("", new UserPlantDisplayViewModel(plant)));
        }
Example #2
0
        public IActionResult Get(int id)
        {
            PlantType plant = _plantData.GetPlantType(id);

            if (plant == null)
            {
                this.logger.LogWarning($"Plant number {id} was not found.");
                return(NotFound());
            }
            return(Ok(new PlantTypeDisplayViewModel(plant)));
        }