public async Task <IActionResult> NewTeam(CSGOTeam team) { ApplicationUser user = await GetAuthUser(); _dbContext.CSGOTeams.Add(team); team.Members.Add(new TeamMember() { UserId = user.Id, IsActive = true, IsAdmin = true, IsEditor = true }); team.InitializeDefaults(); team.UniqueCustomUrl(_dbContext); try { await _dbContext.SaveChangesAsync(); } catch (DbUpdateException e) { System.Diagnostics.Trace.TraceError($"Team create error: ${e.Message}"); return(BadRequest("Something went wrong...")); } return(Ok(team)); }
public IHttpActionResult TeamFromSteamGroup(SteamUserGroup group) { ApplicationUser user = GetAuthUser(); if (!SteamServiceProvider.VerifyUserIsGroupAdmin(user.Id, group.groupID64)) { return(BadRequest("User is not a steam group owner for " + group.groupName)); } CSGOTeam team = _dbContext.Teams.Add(new CSGOTeam() { SteamGroupId = group.groupID64, TeamName = group.groupName, TeamAvatar = group.avatarFull }); team.InitializeDefaults(); team.UniqueCustomUrl(_dbContext); team.Members.Add(new TeamMember() { UserId = user.Id, IsActive = true, IsAdmin = true, IsEditor = true }); try { _dbContext.SaveChanges(); } catch (DbUpdateException e) { System.Diagnostics.Trace.TraceWarning($"Attempting to register steam group twice: ${group.groupID64} msg: ${e.Message}"); return(BadRequest(group.groupName + " Steam group has already been registered.")); } return(Ok(team)); }