Пример #1
0
        public IActionResult Create(PlantViewModel plantViewModel)
        {
            if (ModelState.IsValid)
            {
                string imageName = SaveAndGenerateImageName(plantViewModel.ImageFile);
                var    newPlant  = new Plant()
                {
                    Id                  = Guid.NewGuid(),
                    UserId              = UserId(),
                    Name                = plantViewModel.Name,
                    Type                = plantViewModel.Type,
                    DateAdded           = DateTime.Now,
                    DaysBetweenWatering = plantViewModel.DaysBetweenWatering,
                    Notes               = plantViewModel.Notes,
                    ImageName           = imageName,
                    Waterings           = new List <Watering>()
                };
                _garden.CreatePlant(newPlant);
                return(RedirectToAction("Index"));
            }

            return(View("Form"));
        }