Ejemplo n.º 1
0
        public IActionResult Add()
        {
            List <PlantRooms> rooms             = context.PlantRooms.ToList();
            AddPlantViewModel addPlantViewModel = new AddPlantViewModel(rooms);

            return(View(addPlantViewModel));
        }
Ejemplo n.º 2
0
 protected override void OnAppearing()
 {
     base.OnAppearing();
     if (BindingContext == null)
     {
         BindingContext = new AddPlantViewModel(Navigation);
     }
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddPlant()
        {
            var currUser = await GetCurrentUserAsync();


            AddPlantViewModel viewmodel = new AddPlantViewModel
            {
                GardenList = await _context.GardenBeds.Where(u => u.userId == currUser.Id).Select(g => new SelectListItem
                {
                    Text  = g.name,
                    Value = g.GardenBedId.ToString()
                }).ToListAsync(),

                PlantList = await _context.Plants.Select(p => new SelectListItem(p.PlantName, p.PlantId.ToString())).ToListAsync()
            };

            return(View(viewmodel));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> AddPlant(AddPlantViewModel viewmodel)
        {
            viewmodel.PlantGarden = new PlantGarden
            {
                Plant      = await _context.Plants.FindAsync(viewmodel.PlantId),
                GardenBed  = await _context.GardenBeds.FindAsync(viewmodel.GardenBedId),
                rowNumber  = viewmodel.PlantGarden.rowNumber,
                plantCount = viewmodel.PlantGarden.plantCount
            };

            if (ModelState.IsValid)
            {
                _context.Add(viewmodel.PlantGarden);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "GardenBeds", new { id = viewmodel.GardenBedId }));
            }
            return(NotFound());
        }
Ejemplo n.º 5
0
        public IActionResult Add(AddPlantViewModel addPlantViewModel)
        {
            if (ModelState.IsValid)
            {
                PlantRooms thePlantRoom = context.PlantRooms.Find(addPlantViewModel.PlantRoomId);
                Plant      newPlant     = new Plant
                {
                    PlantName      = addPlantViewModel.PlantName,
                    PlantGenus     = addPlantViewModel.PlantGenus,
                    LastWatered    = addPlantViewModel.LastWatered,
                    LastFertilized = addPlantViewModel.LastFertilized,
                    PlantRoom      = thePlantRoom
                };

                context.Plants.Add(newPlant);
                context.SaveChanges();

                return(Redirect("/Plants"));
            }

            return(View(addPlantViewModel));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> AddPlant(AddPlantViewModel model)
        {
            var plant = new Plant
            {
                Title       = model.Name,
                Description = model.Description,
                PlantTypeId = model.Type
            };
            var plantId = _db.Plants.Add(plant).Entity.Id;

            foreach (var photo in Request.Form.Files)
            {
                var plantPhoto = new PlantPhoto
                {
                    PlantId     = plantId,
                    PathToPhoto = await _fileKeeper.KeepFileAsync("/images/PlantPhotos/", photo.FileName, photo)
                };
                _db.Photos.Add(plantPhoto);
            }
            _db.SaveChanges();
            return(RedirectToAction(nameof(AddPlant)));
        }
Ejemplo n.º 7
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            AddPlantViewModel ViewModel = new AddPlantViewModel(e.Parameter as Company);

            DataContext = ViewModel;
        }