Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public async Task<IActionResult> Edit(int id, [Bind("FloatTripId,Title,Date,Distance,NumberOfFloaters,Duration,Notes,Rating,PicPath,NeedASherpa,UserId,User,RiverId,PutInAPId,TakeOutAPId,DeviceId,SherpaId")] FloatTrip floatTrip)
        {

            if (id != floatTrip.FloatTripId)
            {
                return NotFound();
            }

            //if (ModelState.IsValid)
            //{
            try
            {
                _context.Update(floatTrip);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FloatTripExists(floatTrip.FloatTripId))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }
        
            return RedirectToAction(nameof(Index));

            ViewData["DeviceId"] = new SelectList(_context.Device, "DeviceId", "Type", floatTrip.DeviceId);
            ViewData["PutInAPId"] = new SelectList(_context.AccessPoint, "AccessPointId", "AccessPointId", floatTrip.PutInAPId);
            ViewData["RiverId"] = new SelectList(_context.River, "RiverId", "RiverId", floatTrip.RiverId);
            ViewData["SherpaId"] = new SelectList(_context.Sherpa, "SherpaId", "FirstName", floatTrip.SherpaId);
            ViewData["TakeOutAPId"] = new SelectList(_context.AccessPoint, "AccessPointId", "AccessPointId", floatTrip.TakeOutAPId);
            ViewData["UserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", floatTrip.UserId);
            return View(floatTrip);
        }
Ejemplo n.º 3
0
        //The following line with Type FloatTrip floatTrip is what is coming in from the Get model above
        public async Task<IActionResult> PicAPs(int id, [Bind("User, UserId, Title,RiverId,PutInAPId,TakeOutAPId,")] FloatTrip floatTrip)
        {
            //Don't need this next line because I am IN the new FloatTrip I'm creating - comes from the int id in the call above

            //if (id != floatTrip.FloatTripId)
            //{
            //    return NotFound();
            //}

            //New ThisfloatTrip variable to get the information on this floattrip from the database
           var ThisfloatTrip = await _context.FloatTrip
               .FirstOrDefaultAsync(f => f.FloatTripId == id);

            //Then add the PutInAPId and the TakeoutAPId from the floatTrip that came in from the Model to ThisfloatTrip from the database

            ThisfloatTrip.PutInAPId = floatTrip.PutInAPId;
            ThisfloatTrip.TakeOutAPId = floatTrip.TakeOutAPId;

            //Don't need to check ModelState because it's not valid - I don't have everything I need in the ModelState
            //if (ModelState.IsValid)
             
                try
                {
                    //Don't need to set the UserId because it's already in ThisfloatTrip variable
                    //var user = await GetCurrentUserAsync();
                    //floatTrip.UserId = user.Id;
                    
                    //Update the database with the new ThisfloatTrip parms (PutInApId and TakeOutApId
                    _context.Update(ThisfloatTrip);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FloatTripExists(floatTrip.FloatTripId))
                    {
                        return NotFound();
                    }
                    else
                    {
                        throw;
                    }
                }
                return RedirectToAction(nameof(Index));
            
            //    AccessPointsPickViewModel viewModel = new AccessPointsPickViewModel();
                
            //    viewModel.floatTrip = await _context.FloatTrip
            //        .FirstOrDefaultAsync(f => f.FloatTripId == id);
            //    viewModel.riverId = floatTrip.RiverId.Value;
            //    viewModel.putIns = _context.AccessPoint.Select(p => new SelectListItem
            //    {

            //        Value = p.AccessPointId.ToString(),
            //        Text = p.Name
            //    }
            //    ).ToList();

            //viewModel.takeOuts = _context.AccessPoint.Select(t => new SelectListItem
            //{
            //    Value = t.AccessPointId.ToString(),
            //    Text = t.Name
            //}
            //).ToList();
            //    return View(viewModel);
            }