Beispiel #1
0
        public async Task <ActionResult> Create(AddGearTripViewModel viewModel)
        {
            try
            {
                var gearsToAdd = new List <GearViewModel>();
                foreach (var gear in viewModel.AddedGears)
                {
                    if (gear.SelectedGear == true)
                    {
                        gearsToAdd.Add(gear);
                    }
                }


                foreach (var gear in gearsToAdd)
                {
                    AddSingleGearTrip(viewModel.Trip.Id, gear.Gear.Id);
                }
                // TODO: Add update logic here
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Trips"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Beispiel #2
0
        public async Task <ActionResult> Create(int tripId)
        {
            var user = await GetCurrentUserAsync();

            var trip = await _context.Trips.FirstOrDefaultAsync(t => t.Id == tripId);

            var usersGear = await _context.Gears.Where(g => g.ApplicationuserId == user.Id)
                            .Include(g => g.GearType)
                            .ToListAsync();

            var addedGears = new List <GearViewModel>();

            foreach (var gear in usersGear)
            {
                var newGear = new GearViewModel()
                {
                    Gear = gear
                };
                addedGears.Add(newGear);
            }
            var sharedGear = await _context.SharedGears
                             .Include(s => s.Gear)
                             .Include(s => s.Gear.GearType)
                             .Where(s => s.AcceptedRequest == true)
                             .Where(s => s.ApplicationuserId == user.Id)
                             .ToListAsync();

            foreach (var gear in sharedGear)
            {
                var gearModel = new GearViewModel()
                {
                    Gear = gear.Gear
                };
                addedGears.Add(gearModel);
            }

            var viewModel = new AddGearTripViewModel()
            {
                Trip            = trip,
                Gears           = usersGear,
                ApplicationUser = user,
                AddedGears      = addedGears
            };

            return(View(viewModel));
        }