Now supports saving card groups, this is probably the ugliest code ive ever written but anything to avoid 20 cardgroup properties. we should see if there's a better way, it could probably be a lot cleaner
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TOOHUCardAPI.Data.Models;
|
||||
|
||||
namespace TOOHUCardAPI.Data.Repositories
|
||||
@@ -16,9 +18,14 @@ namespace TOOHUCardAPI.Data.Repositories
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
private IQueryable<User> GetAllUsersQuery()
|
||||
{
|
||||
return _appDbContext.Users.Include(u => u.EncodedCardGroups).AsQueryable();
|
||||
}
|
||||
|
||||
public User GetUser(string steamId)
|
||||
{
|
||||
return _appDbContext.Users.Where((user => user.SteamId.Equals(steamId))).FirstOrDefault();
|
||||
return GetAllUsersQuery().FirstOrDefault(user => user.SteamId.Equals(steamId));
|
||||
}
|
||||
|
||||
public User CreateUser(string steamId)
|
||||
@@ -29,7 +36,8 @@ namespace TOOHUCardAPI.Data.Repositories
|
||||
Vip = true,
|
||||
EndTime = DateTime.MaxValue,
|
||||
LevelList = string.Empty,
|
||||
PetLevel = 1
|
||||
PetLevel = 1,
|
||||
EncodedCardGroups = new List<EncodedCardGroup>()
|
||||
};
|
||||
_appDbContext.Users.Add(user);
|
||||
_appDbContext.SaveChanges();
|
||||
@@ -38,7 +46,7 @@ namespace TOOHUCardAPI.Data.Repositories
|
||||
|
||||
public User UpdateUser(User user)
|
||||
{
|
||||
var trackedUser = _appDbContext.Users.FirstOrDefault(u => u.SteamId == user.SteamId);
|
||||
var trackedUser = GetAllUsersQuery().FirstOrDefault(u => u.SteamId == user.SteamId);
|
||||
if (trackedUser == default)
|
||||
{
|
||||
return trackedUser;
|
||||
|
||||
Reference in New Issue
Block a user