Ejemplo n.º 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)));
        }
Ejemplo n.º 2
0
        public IActionResult Create([FromBody] PlantTypeCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(UnprocessableEntity(new ValidationErrorModel(ModelState)));
            }

            PlantType plant = new PlantType

            {
                PlantTypeID         = model.PlantTypeID,
                LatinName           = (model.LatinName ?? "").Trim(),
                CommonName          = (model.CommonName ?? "").Trim(),
                StockImageID        = model.StockImageID,
                Description         = model.Description,
                Difficulty          = model.Difficulty,
                HumidityLowLevel    = model.HumidityLowLevel,
                HumidityHighLevel   = model.HumidityHighLevel,
                LightLevel          = model.LightLevel,
                LightTime           = model.LightTime,
                SoilPh              = model.SoilPh,
                FertilizerFrequency = model.FertilizerFrequency,
                FertalizerType      = model.FertalizerType,
                WateringFrequency   = model.WateringFrequency,
                WaterType           = model.WaterType,
                ToxicToCats         = model.ToxicToCats,
                ToxicToDogs         = model.ToxicToDogs,
                ToxicToSmallAnimals = model.ToxicToSmallAnimals,
                ScienceKingdom      = (model.ScienceKingdom ?? "").Trim(),
                ScienceClade1       = (model.ScienceClade1 ?? "").Trim(),
                ScienceClade2       = (model.ScienceClade2 ?? "").Trim(),
                ScienceClade3       = (model.ScienceClade3 ?? "").Trim(),
                ScienceOrder        = (model.ScienceOrder ?? "").Trim(),
                ScienceFamily       = (model.ScienceFamily ?? "").Trim(),
                ScienceSubfamily    = (model.ScienceSubfamily ?? "").Trim(),
                ScienceGenus        = (model.ScienceGenus ?? "").Trim()
            };

            _plantData.Add(plant);
            _plantData.Commit();
            return(Created("", new PlantTypeDisplayViewModel(plant)));
        }