Last active
April 10, 2021 18:42
-
-
Save Alexander-Mages/bfaac5dfdd2ebf8df56482d760d9cc96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace SportsAdministrationApp.Models | |
{ | |
public class ApplicationDbContext : IdentityDbContext | |
{ | |
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) | |
: base(options) | |
{ | |
} | |
public DbSet<User> User { get; set; } | |
//public DbSet<AthleteData> AthleteData { get; set; } | |
//public DbSet<PRs> PRs { get; set; } | |
public DbSet<Team> Teams { get; set; } | |
public DbSet<PersonalRecord> PersonalRecord { get; set; } | |
public DbSet<AthleteData> AthleteData { get; set; } | |
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
base.OnModelCreating(modelBuilder); | |
modelBuilder.Seed(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace SportsAdministrationApp.Models | |
{ | |
public class AthleteData | |
{ | |
public int Id { get; set; } | |
public string Location { get; set; } | |
public int FromPersonalRecordId { get; set; } | |
public decimal Time { get; set; } | |
public PersonalRecord PersonalRecord { get; set; } | |
public int PersonalRecordId { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IActionResult Index() | |
{ | |
var user = userManager.Users.Include(u => u.PersonalRecord).ThenInclude(p => p.AthleteData).ToList(); | |
return View(user); | |
} | |
[HttpGet] | |
public async Task<IActionResult> AddTime(string id) | |
{ | |
var user = await userManager.FindByIdAsync(id); | |
return View(user); | |
} | |
[HttpPost] | |
public async Task<IActionResult> AddTime(string id, string time, string Location) | |
{ | |
var user = await userManager.FindByIdAsync(id); | |
PersonalRecord r = new PersonalRecord(); | |
AthleteData d = new AthleteData() { Location = location, Time = Convert.ToDecimal(time) }; | |
user.PersonalRecord.AthleteData.Add(d); | |
var result = await userManager.UpdateAsync(user); | |
if (!result.Succeeded) | |
{ | |
//fix this | |
return View(user); | |
} | |
return RedirectToAction("UserListWithData"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace SportsAdministrationApp.Models | |
{ | |
public class PersonalRecord | |
{ | |
public int Id { get; set; } | |
public decimal PR { get; set; } | |
public List<AthleteData> AthleteData { get; set; } | |
public PersonalRecord() | |
{ | |
AthleteData = new List<AthleteData>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment