public async Task <dynamic> addBuddy([FromBody] BuddyDTO buddyReq) { AccountFriend existingFriend = db.AccountFriend.Where(af => af.AccountId == buddyReq.AccountId && af.FriendAccountId == buddyReq.BuddyAccountId).FirstOrDefault(); AccountIgnored existingIgnored = db.AccountIgnored.Where(af => af.AccountId == buddyReq.AccountId && af.IgnoredAccountId == buddyReq.BuddyAccountId).FirstOrDefault(); if (existingFriend != null) { return(StatusCode(403, "Buddy already exists.")); } if (existingIgnored != null) { db.AccountIgnored.Attach(existingIgnored); db.Entry(existingIgnored).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } AccountFriend newFriend = new AccountFriend() { AccountId = buddyReq.AccountId, FriendAccountId = buddyReq.BuddyAccountId, CreateDt = DateTime.UtcNow }; db.AccountFriend.Add(newFriend); db.SaveChanges(); return(Ok("Buddy Added")); }
public async Task <dynamic> postStats([FromBody] StatPostDTO statData) { DateTime modifiedDt = DateTime.UtcNow; List <AccountStat> playerStats = db.AccountStat.Where(s => s.AccountId == statData.AccountId).OrderBy(s => s.StatId).Select(s => s).ToList(); int badStats = playerStats.Where(s => s.StatValue < 0).Count(); if (badStats > 0) { return(BadRequest("Found a negative stat in array. Can't have those!")); } foreach (AccountStat pStat in playerStats) { int newValue = statData.stats[pStat.StatId - 1]; pStat.ModifiedDt = modifiedDt; pStat.StatValue = newValue; db.AccountStat.Attach(pStat); db.Entry(pStat).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } db.SaveChanges(); return(Ok()); }
public async Task <dynamic> updateEULA([FromBody] ChangeEulaDTO request) { var eula = db.DimEula.FirstOrDefault(x => x.Id == request.Id); if (eula == null) { return(StatusCode(403, "Cannot change an eula entry that doesn't exist.")); } db.DimEula.Attach(eula); db.Entry(eula).State = Microsoft.EntityFrameworkCore.EntityState.Modified; eula.EulaTitle = request.EulaTitle ?? eula.EulaTitle; eula.EulaBody = request.EulaBody ?? eula.EulaBody; eula.ModifiedDt = DateTime.UtcNow; eula.FromDt = request.FromDt ?? eula.FromDt; eula.ToDt = request.ToDt ?? eula.ToDt; db.SaveChanges(); return(Ok("EULA Changed")); }
public async Task <dynamic> createAccount([FromBody] AccountRequestDTO request) { DateTime now = DateTime.UtcNow; Account existingAccount = db.Account.Where(a => a.AccountName == request.AccountName).FirstOrDefault(); if (existingAccount == null || existingAccount.IsActive == false) { if (existingAccount == null) { Account acc = new Account() { AccountName = request.AccountName, AccountPassword = request.PasswordPreHashed ? request.AccountPassword : Crypto.ComputeSHA256(request.AccountPassword), CreateDt = now, LastSignInDt = now, MachineId = request.MachineId, MediusStats = request.MediusStats, AppId = request.AppId, }; db.Account.Add(acc); db.SaveChanges(); List <AccountStat> newStats = (from ds in db.DimStats select new AccountStat() { AccountId = acc.AccountId, StatId = ds.StatId, StatValue = ds.DefaultValue }).ToList(); db.AccountStat.AddRange(newStats); AccountStatus newStatusData = new AccountStatus() { AccountId = acc.AccountId, LoggedIn = false, GameId = null, ChannelId = null, WorldId = null }; db.AccountStatus.Add(newStatusData); db.SaveChanges(); return(await getAccount(acc.AccountId)); } else { existingAccount.IsActive = true; existingAccount.AccountPassword = request.AccountPassword; existingAccount.ModifiedDt = now; existingAccount.MediusStats = request.MediusStats; existingAccount.AppId = request.AppId; existingAccount.MachineId = request.MachineId; existingAccount.LastSignInDt = now; db.Account.Attach(existingAccount); db.Entry(existingAccount).State = Microsoft.EntityFrameworkCore.EntityState.Modified; List <AccountStat> newStats = (from ds in db.DimStats select new AccountStat() { AccountId = existingAccount.AccountId, StatId = ds.StatId, StatValue = ds.DefaultValue }).ToList(); db.AccountStat.AddRange(newStats); db.SaveChanges(); return(await getAccount(existingAccount.AccountId)); } } else { return(StatusCode(403, $"Account {request.AccountName} already exists.")); } }