Skip to content

Instantly share code, notes, and snippets.

@Alexander-Mages
Last active April 10, 2021 18:42
Show Gist options
  • Save Alexander-Mages/bfaac5dfdd2ebf8df56482d760d9cc96 to your computer and use it in GitHub Desktop.
Save Alexander-Mages/bfaac5dfdd2ebf8df56482d760d9cc96 to your computer and use it in GitHub Desktop.
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();
}
}
}
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; }
}
}
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");
}
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