Beispiel #1
0
        public async Task<IActionResult> Create([Bind("Title,Date,NumberOfFloaters,UserId,RiverId,DeviceId")] FloatTrip floatTrip)
        {
            ModelState.Remove("floatTrip.User");
            ModelState.Remove("floatTrip.UserId");

            FloatTripCreateViewModel ViewModel = new FloatTripCreateViewModel();
            if (ModelState.IsValid)
            {
                //Check User's Id
                var user = await GetCurrentUserAsync();
                floatTrip.UserId = user.Id;
                _context.Add(floatTrip);
                await _context.SaveChangesAsync();
                return RedirectToAction("PicAPs", new { id = floatTrip.FloatTripId });
            }

            ViewModel.rivers = _context.River.Select(r => new SelectListItem
            {
                Text = r.Name,
                Value = r.RiverId.ToString()
            }).ToList();

            ViewModel.devices = _context.Device.Select(d => new SelectListItem
            {
                Text = d.Type,
                Value = d.DeviceId.ToString()
            }).ToList();

            return View(ViewModel);
        }
Beispiel #2
0
        // GET: FloatTrips/Create
        public IActionResult Create()
        {
            FloatTripCreateViewModel ViewModel = new FloatTripCreateViewModel();

            ViewModel.rivers = _context.River.Select(r => new SelectListItem
            {
                Text = r.Name,
                Value = r.RiverId.ToString()
            }
          ).ToList();

            ViewModel.rivers.Insert(0, new SelectListItem() { Value = "0", Text = "--Select A River--" });

            ViewModel.devices = _context.Device.Select(d => new SelectListItem
            {
                Text = d.Type,
                Value = d.DeviceId.ToString()
            }
            ).ToList();

            ViewModel.devices.Insert(0, new SelectListItem() { Value = "0", Text = "--Select A Device--" });

            return View(ViewModel);
        }