Beispiel #1
0
        public async Task <ActionResult <RaceItem> > PostRaceItem(RaceItem item)
        {
            //item.Owner = User.Identity.Name;
            item.FreeSeats = item.Seats;
            _context.RaceItems.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetRaceItem), new { id = item.Id }, item));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("ID,Brand,Name,Use,Support")] Shoe shoe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shoe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shoe));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("ID,RaceDate,RaceName,City,State")] Race race)
        {
            if (ModelState.IsValid)
            {
                _context.Add(race);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(race));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Age,Address,City,State,Zip,Email,PhoneNumber,RaceId,ShoeId")] Registrant registrant)
        {
            if (ModelState.IsValid)
            {
                _context.Add(registrant);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RaceId"] = new SelectList(_context.Race, "ID", "RaceName", registrant.RaceId);
            ViewData["ShoeId"] = new SelectList(_context.Shoe, "ID", "Brand", registrant.ShoeId);
            return(View(registrant));
        }
Beispiel #5
0
        public async Task <int> DeleteAsync(int id)
        {
            var pilot = await context.Pilots.FirstAsync(x => x.Id == id);

            if (pilot == null)
            {
                throw new Exception("Entity not found by given Id");
            }

            context.Pilots.Remove(pilot);

            await context.SaveChangesAsync();

            return(pilot.Id);
        }
Beispiel #6
0
        public async Task <int> DeleteAsync(int id)
        {
            var team = await context.Teams.FirstOrDefaultAsync(ent => ent.Id == id);

            if (team == null)
            {
                throw new Exception("Entity not found by given Id");
            }

            context.Teams.Remove(team);

            await context.SaveChangesAsync();

            return(team.Id);
        }
 public ActionResult Create([Bind(Include = "WorkoutID,AthleteID,WorkoutDescription,WorkoutDate,WorkoutDistance,WorkoutIntensity,WorkoutCategory")] Workout workout)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Workouts.Add(workout);
             db.SaveChangesAsync();
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception)
     {
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     ViewBag.AthleteID = new SelectList(db.Athletes, "AthleteID", "FirstName", workout.AthleteID);
     return(View(workout));
 }
 //Look into asyncronous programming to make my code more efficient.
 public void SaveChangesAsync()
 {
     if (_context != null)
     {
         _context.SaveChangesAsync();
     }
     if (_spellsContext != null)
     {
         _spellsContext.SaveChangesAsync();
     }
     if (_itemsContext != null)
     {
         _itemsContext.SaveChangesAsync();
     }
     if (_playableClassContext != null)
     {
         _playableClassContext.SaveChangesAsync();
     }
     if (_raceContext != null)
     {
         _raceContext.SaveChangesAsync();
     }
 }
Beispiel #9
0
        public async Task <JsonResult> CreateDefaultUsers()
        {
            string role_registeredUser = "******";
            string role_administrator  = "Administrator";

            if (await roleManager.FindByNameAsync(role_registeredUser) == null)
            {
                await roleManager.CreateAsync(new IdentityRole(role_registeredUser));
            }

            if (await roleManager.FindByNameAsync(role_administrator) == null)
            {
                await roleManager.CreateAsync(new IdentityRole(role_administrator));
            }

            //https://www.learnentityframeworkcore.com/concurrency/

            var userList_concurrent = new ConcurrentBag <ApplicationUser>();

            var user_test = await CheckIfTestUserExists(role_registeredUser);

            var user_admin = await CheckIfAdminExists(role_registeredUser, role_administrator);

            userList_concurrent.Add(user_test);
            userList_concurrent.Add(user_admin);

            if (userList_concurrent.Count > 0)
            {
                await context.SaveChangesAsync(true, default);
            }

            return(new JsonResult(new
            {
                Count = userList_concurrent.Count,
                Users = userList_concurrent
            }));
        }