コード例 #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));
        }
コード例 #2
0
ファイル: ShoesController.cs プロジェクト: richar35/RaceSite
        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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #5
0
ファイル: PilotRepository.cs プロジェクト: SutoZ/FormulaRace
        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);
        }
コード例 #6
0
ファイル: TeamRepository.cs プロジェクト: SutoZ/FormulaRace
        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);
        }
コード例 #7
0
 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));
 }
コード例 #8
0
 //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();
     }
 }
コード例 #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
            }));
        }