public static async Task <IList <Player> > LoadRandom( SocialGamificationAssetContext db, Player player, IList <CustomDataBase> customData, bool alliancesOnly = false, int limit = 1) { var query = db.Players.Where(a => a.Role == AccountType.Player); if (alliancesOnly) { var alliancesList = Alliance.GetAllianceIds(db, player.Id, AllianceState.Accepted); query = query.Where(p => alliancesList.Contains(p.Id)); } else { query = query.Where(p => p.Id != player.Id); } // CustomData conditions var customDataQuery = Models.CustomData.ConditionBuilder(db, customData, CustomDataType.Player); if (customDataQuery != null) { IList <Guid> similarPlayers = await customDataQuery.Select(c => c.ObjectId).Distinct().ToListAsync(); // Check if Players satisfy CustomData constraints query = query.Where(p => similarPlayers.Contains(p.Id)); } IList <Player> players = await query.ToListAsync(); return(GenericHelper.Shuffle(players, limit)); }
public static async Task<IList<Player>> LoadRandom( SocialGamificationAssetContext db, Player player, IList<CustomDataBase> customData, bool alliancesOnly = false, int limit = 1) { var query = db.Players.Where(a => a.Role == AccountType.Player); if (alliancesOnly) { var alliancesList = Alliance.GetAllianceIds(db, player.Id, AllianceState.Accepted); query = query.Where(p => alliancesList.Contains(p.Id)); } else { query = query.Where(p => p.Id != player.Id); } // CustomData conditions var customDataQuery = Models.CustomData.ConditionBuilder(db, customData, CustomDataType.Player); if (customDataQuery != null) { IList<Guid> similarPlayers = await customDataQuery.Select(c => c.ObjectId).Distinct().ToListAsync(); // Check if Players satisfy CustomData constraints query = query.Where(p => similarPlayers.Contains(p.Id)); } IList<Player> players = await query.ToListAsync(); return GenericHelper.Shuffle(players, limit); }
public async Task<Reward> CalculateRewardFromAction(SocialGamificationAssetContext context, string actionVerb) { var actionMatch = Actions.FirstOrDefault(a => a.Verb.Equals(actionVerb)); if (actionMatch != null) { actionMatch.Relations = await context.ActionRelations.Where(a => a.ActionId.Equals(actionMatch.Id)) .Include(ar => ar.AttributeChanges.Select(ac => ac.AttributeType)) .ToListAsync(); foreach (var ar in actionMatch.Relations) { foreach (var reward in ar.AttributeChanges) { var rewardMatch = Rewards.Where(r => r.TypeReward.Equals(RewardType.Store)) .Where(r => r.AttributeType.Name.Equals(reward.AttributeType.Name)) .FirstOrDefault(); if (rewardMatch != null) { rewardMatch.Value += reward.Value; return rewardMatch; } } } } return null; }
public static async Task<IList<Group>> LoadRandom( SocialGamificationAssetContext db, Group group, IList<CustomDataBase> customData, bool alliancesOnly = false, int limit = 1) { IQueryable<Group> query = db.Groups; if (alliancesOnly) { var alliancesList = Alliance.GetAllianceIds(db, group.Id, AllianceState.Accepted); query = query.Where(a => alliancesList.Contains(group.Id)); } else { query = query.Where(g => g.Id != group.Id).Where(g => g.Type == GroupVisibility.Public); } // CustomData conditions var cQuery = Models.CustomData.ConditionBuilder(db, customData, CustomDataType.Group); IList<Guid> similarGroups = await cQuery.Select(c => c.ObjectId).Distinct().ToListAsync(); // Check if Group satisfy CustomData constraints IList<Group> groups = await query.Where(g => similarGroups.Contains(g.Id)).ToListAsync(); return GenericHelper.Shuffle(groups, limit); }
public static async Task <IList <Group> > LoadRandom( SocialGamificationAssetContext db, Group group, IList <CustomDataBase> customData, bool alliancesOnly = false, int limit = 1) { IQueryable <Group> query = db.Groups; if (alliancesOnly) { var alliancesList = Alliance.GetAllianceIds(db, group.Id, AllianceState.Accepted); query = query.Where(a => alliancesList.Contains(group.Id)); } else { query = query.Where(g => g.Id != group.Id).Where(g => g.Type == GroupVisibility.Public); } // CustomData conditions var cQuery = Models.CustomData.ConditionBuilder(db, customData, CustomDataType.Group); IList <Guid> similarGroups = await cQuery.Select(c => c.ObjectId).Distinct().ToListAsync(); // Check if Group satisfy CustomData constraints IList <Group> groups = await query.Where(g => similarGroups.Contains(g.Id)).ToListAsync(); return(GenericHelper.Shuffle(groups, limit)); }
public async Task <Reward> CalculateRewardFromAction(SocialGamificationAssetContext context, string actionVerb) { var actionMatch = Actions.FirstOrDefault(a => a.Verb.Equals(actionVerb)); if (actionMatch != null) { actionMatch.Relations = await context.ActionRelations.Where(a => a.ActionId.Equals(actionMatch.Id)) .Include(ar => ar.AttributeChanges.Select(ac => ac.AttributeType)) .ToListAsync(); foreach (var ar in actionMatch.Relations) { foreach (var reward in ar.AttributeChanges) { var rewardMatch = Rewards.Where(r => r.TypeReward.Equals(RewardType.Store)) .Where(r => r.AttributeType.Name.Equals(reward.AttributeType.Name)) .FirstOrDefault(); if (rewardMatch != null) { rewardMatch.Value += reward.Value; return(rewardMatch); } } } } return(null); }
public static async Task<ContentResult> Add(SocialGamificationAssetContext db, Match match, Actor actor) { // Add actors to this match var matchActor = new MatchActor { MatchId = match.Id, ActorId = actor.Id }; db.MatchActors.Add(matchActor); try { await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { return HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError); } for (var i = 1; i <= match.TotalRounds; ++i) { // Add round(s) entry for each Actor var matchRound = new MatchRound { MatchActorId = matchActor.Id, RoundNumber = i }; db.MatchRounds.Add(matchRound); try { await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { return HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError); } } return null; }
/// <summary> /// <para> /// Assign <see cref="SocialGamificationAsset.Models.Player.Groups" /> /// </para> /// <para>to the Player.</para> /// </summary> public void AddGroups(SocialGamificationAssetContext db, ICollection <Player> groupsList) { var groupIds = groupsList.Select(a => a.Id).ToList(); var groups = db.Groups.Where(g => groupIds.Contains(g.Id)).ToList(); Groups = new List <Group>(groups); }
public ApiController(SocialGamificationAssetContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } _context = context; }
/** * Get the current session of Logged account * * @return Session */ public static async Task <Session> GetSession(SocialGamificationAssetContext db, Guid playerId) { var session = await db.Players.Where(p => p.Id.Equals(playerId)) .Include(p => p.Sessions.Where(s => s.IsExpired.Equals(false)).OrderByDescending(s => s.UpdatedDate)) .Select(p => p.Sessions) .FirstOrDefaultAsync() as Session; return(session); }
/// <summary> /// <para> /// Assign <see cref="SocialGamificationAsset.Models.Group.Players" /> /// </para> /// <para>to the Group.</para> /// </summary> public void AddPlayers(SocialGamificationAssetContext db, ICollection<Player> playersList) { if (playersList.Count < 2) { Console.WriteLine("At least two Players are required to create a Group."); return; } var playerIds = playersList.Select(a => a.Id).ToList(); var players = db.Players.Where(p => playerIds.Contains(p.Id)).ToList(); Players = new List<Player>(players); }
/// <summary> /// <para> /// Assign <see cref="SocialGamificationAsset.Models.Group.Players" /> /// </para> /// <para>to the Group.</para> /// </summary> public void AddPlayers(SocialGamificationAssetContext db, ICollection <Player> playersList) { if (playersList.Count < 2) { Console.WriteLine("At least two Players are required to create a Group."); return; } var playerIds = playersList.Select(a => a.Id).ToList(); var players = db.Players.Where(p => playerIds.Contains(p.Id)).ToList(); Players = new List <Player>(players); }
protected static async Task SaveChanges(SocialGamificationAssetContext _context, bool isAsync = false) { try { if (isAsync) { await _context.SaveChangesAsync(); } else { _context.SaveChanges(); } } catch (DbUpdateException e) { throw e; } }
public static async Task<ContentResult> AddOrUpdate( SocialGamificationAssetContext db, IList<CustomDataBase> sourceData, Guid objectId, CustomDataType objectType) { // Build the filter by CustomData if (sourceData != null && sourceData.Count > 0) { foreach (var data in sourceData) { var customData = await db.CustomData.Where(c => c.Key.Equals(data.Key)) .Where(c => c.ObjectId.Equals(objectId)) .Where(c => c.ObjectType == objectType) .FirstOrDefaultAsync(); if (customData != null) { db.Entry(customData).State = EntityState.Modified; customData.Value = data.Value; } else { customData = new CustomData { Key = data.Key, Value = data.Value, ObjectId = objectId, ObjectType = objectType }; db.CustomData.Add(customData); } } } return await SaveChanges(db, true); }
public static async Task <ContentResult> AddOrUpdate( SocialGamificationAssetContext db, IList <CustomDataBase> sourceData, Guid objectId, CustomDataType objectType) { // Build the filter by CustomData if (sourceData != null && sourceData.Count > 0) { foreach (var data in sourceData) { var customData = await db.CustomData.Where(c => c.Key.Equals(data.Key)) .Where(c => c.ObjectId.Equals(objectId)) .Where(c => c.ObjectType == objectType) .FirstOrDefaultAsync(); if (customData != null) { db.Entry(customData).State = EntityState.Modified; customData.Value = data.Value; } else { customData = new CustomData { Key = data.Key, Value = data.Value, ObjectId = objectId, ObjectType = objectType }; db.CustomData.Add(customData); } } } return(await SaveChanges(db, true)); }
public static async Task <ContentResult> Add(SocialGamificationAssetContext db, Match match, Actor actor) { // Add actors to this match var matchActor = new MatchActor { MatchId = match.Id, ActorId = actor.Id }; db.MatchActors.Add(matchActor); try { await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { return(HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError)); } for (var i = 1; i <= match.TotalRounds; ++i) { // Add round(s) entry for each Actor var matchRound = new MatchRound { MatchActorId = matchActor.Id, RoundNumber = i }; db.MatchRounds.Add(matchRound); try { await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { return(HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError)); } } return(null); }
public static IQueryable <CustomData> ConditionBuilder( SocialGamificationAssetContext db, IList <CustomDataBase> sourceData, CustomDataType objectType) { var query = db.CustomData.Where(c => c.ObjectType == objectType); if (sourceData == null || sourceData.Count <= 0) { return(null); } foreach (var data in sourceData) { query = query.Where(c => c.Key.Equals(data.Key)); if (!AllowedOperators.Contains(data.Operator)) { continue; } switch (data.Operator) { case "=": query = query.Where(c => c.Value.Equals(data.Value)); break; case "!": query = query.Where(c => c.Value != data.Value); break; case "%": query = query.Where(c => c.Value.Contains(data.Value)); break; } } return(query); }
protected static async Task SeedGames(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.GameRegistry.Any()) { IList <GameRegistry> games = new List <GameRegistry> { new GameRegistry { Name = "ButtonGame", DeveloperName = "PlayGen" }, new GameRegistry { Name = "TankGame", DeveloperName = "PlayGen" } }; _context.GameRegistry.AddRange(games); await SaveChanges(_context, isAsync); Debug.WriteLine("Games Seeded."); // GameRegistry Game = await _context.GameRegistry.Where(g => g.Username.Equals("ButtonGame")).FirstOrDefaultAsync(); } }
protected static async Task SeedAlliances(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.Alliances.Any()) { var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync(); var matt = await _context.Players.Where(a => a.Username.Equals("matt")).FirstOrDefaultAsync(); var jack = await _context.Players.Where(a => a.Username.Equals("jack")).FirstOrDefaultAsync(); var kam = await _context.Players.Where(a => a.Username.Equals("kam")).FirstOrDefaultAsync(); var ben = await _context.Players.Where(a => a.Username.Equals("ben")).FirstOrDefaultAsync(); IList <Alliance> alliances = new List <Alliance> { new Alliance { RequesterId = mayur.Id, RequesteeId = matt.Id, State = AllianceState.Pending }, new Alliance { RequesterId = mayur.Id, RequesteeId = jack.Id, State = AllianceState.Accepted }, new Alliance { RequesterId = jack.Id, RequesteeId = matt.Id, State = AllianceState.Declined }, new Alliance { RequesterId = kam.Id, RequesteeId = mayur.Id, State = AllianceState.Accepted } }; _context.Alliances.AddRange(alliances); await SaveChanges(_context, isAsync); Debug.WriteLine("Alliances Seeded."); } }
/// <summary> /// Asynchronously save data /// </summary> /// <returns> /// <para> /// ErrorContentResult if /// <see cref="System.Data.Entity.Infrastructure.DbUpdateException" /> /// </para> /// <para>exception occurs</para> /// </returns> public static async Task <ContentResult> SaveChanges( SocialGamificationAssetContext _context, bool isAsync = false) { try { if (isAsync) { await _context.SaveChangesAsync(); } else { _context.SaveChanges(); } } catch (DbUpdateException e) { return(HttpResponseHelper.ErrorContentResult( GetExceptionString(e), StatusCodes.Status500InternalServerError)); } return(null); }
/// <summary> /// Asynchronously save data /// </summary> /// <returns> /// <para> /// ErrorContentResult if /// <see cref="System.Data.Entity.Infrastructure.DbUpdateException" /> /// </para> /// <para>exception occurs</para> /// </returns> public static async Task<ContentResult> SaveChanges( SocialGamificationAssetContext _context, bool isAsync = false) { try { if (isAsync) { await _context.SaveChangesAsync(); } else { _context.SaveChanges(); } } catch (DbUpdateException e) { return HttpResponseHelper.ErrorContentResult( GetExceptionString(e), StatusCodes.Status500InternalServerError); } return null; }
protected static async Task SeedGroups(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.Alliances.Any()) { IList <Group> groups = new List <Group> { new Group { Username = "******" }, new Group { Username = "******" }, new Group { Username = "******" } }; _context.Groups.AddRange(groups); await SaveChanges(_context, isAsync); Debug.WriteLine("Groups Seeded."); } }
public IQueryable <Actor> Alliances(SocialGamificationAssetContext db, AllianceState state) { return(Alliances(db, Id, state)); }
/** * Check if the current Username already exists * * @return boolean Returns TRUE if Username exists */ public static async Task <bool> ExistsUsername(SocialGamificationAssetContext db, string username) { var player = await db.Players.Where(p => p.Username.Equals(username)).FirstOrDefaultAsync(); return(player != null); }
public async Task <ContentResult> AddOrUpdateCustomData( SocialGamificationAssetContext db, IList <CustomDataBase> sourceData) { return(await Models.CustomData.AddOrUpdate(db, sourceData, Id, CustomDataType.Group)); }
public async Task <Session> GetSession(SocialGamificationAssetContext db) { return(await GetSession(db, Id)); }
public TargetsController(SocialGamificationAssetContext context) : base(context) { }
public AchievementsController(SocialGamificationAssetContext context) : base(context) { }
public InventoryController(SocialGamificationAssetContext context) : base(context) { }
protected static async Task SeedAlliances(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.Alliances.Any()) { var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync(); var matt = await _context.Players.Where(a => a.Username.Equals("matt")).FirstOrDefaultAsync(); var jack = await _context.Players.Where(a => a.Username.Equals("jack")).FirstOrDefaultAsync(); var kam = await _context.Players.Where(a => a.Username.Equals("kam")).FirstOrDefaultAsync(); var ben = await _context.Players.Where(a => a.Username.Equals("ben")).FirstOrDefaultAsync(); IList<Alliance> alliances = new List<Alliance> { new Alliance { RequesterId = mayur.Id, RequesteeId = matt.Id, State = AllianceState.Pending }, new Alliance { RequesterId = mayur.Id, RequesteeId = jack.Id, State = AllianceState.Accepted }, new Alliance { RequesterId = jack.Id, RequesteeId = matt.Id, State = AllianceState.Declined }, new Alliance { RequesterId = kam.Id, RequesteeId = mayur.Id, State = AllianceState.Accepted } }; _context.Alliances.AddRange(alliances); await SaveChanges(_context, isAsync); Debug.WriteLine("Alliances Seeded."); } }
protected static async Task SeedCustomData(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.CustomData.Any()) { var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync(); var matt = await _context.Players.Where(a => a.Username.Equals("matt")).FirstOrDefaultAsync(); var jack = await _context.Players.Where(a => a.Username.Equals("jack")).FirstOrDefaultAsync(); var kam = await _context.Players.Where(a => a.Username.Equals("kam")).FirstOrDefaultAsync(); var ben = await _context.Players.Where(a => a.Username.Equals("ben")).FirstOrDefaultAsync(); IList<CustomData> customData = new List<CustomData> { new CustomData { Key = "ip", Value = "127.0.0.1", ObjectId = mayur.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "ip", Value = "127.0.0.1", ObjectId = matt.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "ip", Value = "127.0.0.1", ObjectId = jack.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "ip", Value = "127.0.0.1", ObjectId = ben.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "video_id", Value = "1234", ObjectId = mayur.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "video_id", Value = "1234", ObjectId = matt.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "video_id", Value = "1234", ObjectId = jack.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "chat_id", Value = "235f73ea-e54f-4150-8dc3-3eb9995d0728", ObjectId = mayur.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "chat_id", Value = "235f73ea-e54f-4150-8dc3-3eb9995d0728", ObjectId = matt.Id, ObjectType = CustomDataType.Player } }; _context.CustomData.AddRange(customData); await SaveChanges(_context, isAsync); Debug.WriteLine("CustomData Seeded."); } }
protected static async Task SeedPlayerSessions(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.Sessions.Any()) { var boardgame = await _context.Groups.Where(a => a.Username.Equals("boardgame")).FirstOrDefaultAsync(); var gameideas = await _context.Groups.Where(a => a.Username.Equals("gameideas")).FirstOrDefaultAsync(); var rage = await _context.Groups.Where(a => a.Username.Equals("rage")).FirstOrDefaultAsync(); IList<Session> sessions = new List<Session> { new Session { Player = new Player { Username = "******", Password = PasswordHelper.HashPassword("admin"), Role = AccountType.Admin } }, new Session { Player = new Player { Username = "******", Password = PasswordHelper.HashPassword("playgen"), Role = AccountType.Admin } }, new Session { Player = new Player { Username = "******", Email = "*****@*****.**", Password = PasswordHelper.HashPassword("mayur"), Groups = new List<Group> { boardgame, gameideas, rage } } }, new Session { Player = new Player { Username = "******", Email = "*****@*****.**", Password = PasswordHelper.HashPassword("jack"), Groups = new List<Group> { gameideas, rage } } }, new Session { Player = new Player { Username = "******", Email = "*****@*****.**", Password = PasswordHelper.HashPassword("matt"), Groups = new List<Group> { boardgame, rage } } }, new Session { Player = new Player { Username = "******", Password = PasswordHelper.HashPassword("ben"), Groups = new List<Group> { boardgame, gameideas } } }, new Session { Player = new Player { Username = "******", Password = PasswordHelper.HashPassword("kam"), Groups = new List<Group> { gameideas } } } }; _context.Sessions.AddRange(sessions); await SaveChanges(_context, isAsync); Debug.WriteLine("Players & Sessions Seeded."); } }
protected static async Task SeedGroups(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.Alliances.Any()) { IList<Group> groups = new List<Group> { new Group { Username = "******" }, new Group { Username = "******" }, new Group { Username = "******" } }; _context.Groups.AddRange(groups); await SaveChanges(_context, isAsync); Debug.WriteLine("Groups Seeded."); } }
/// <summary> /// <see cref="Player" /> API /// </summary> /// <param name="context"></param> public PlayersController(SocialGamificationAssetContext context) : base(context) { }
public async Task <bool> IsOnline(SocialGamificationAssetContext db) { return(await IsOnline(db, Id)); }
protected static async Task SeedGoals(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.ActorGoal.Any()) { var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync(); var goal = new Goal { Concern = new ConcernMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, RewardResource = new RewardResourceMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, Feedback = new GoalFeedback { Threshold = 0, Target = 0, Direction = 0 }, Description = "Test" }; var attributeType = new AttributeType { Name = "testAttribute", DefaultValue = 0f, Type = 0 }; var activity = new Activity { Name = "Testing" }; IList <ActorGoal> goals = new List <ActorGoal> { new ActorGoal { Actor = mayur, Goal = goal, Status = 0, ConcernOutcome = new ConcernMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, RewardResourceOutcome = new RewardResourceMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, Activity = activity, Role = new Role { Name = "Testing", Goal = goal, Activity = activity } } }; _context.ActorGoal.AddRange(goals); IList <Reward> rewards = new List <Reward> { new Reward { AttributeType = attributeType, TypeReward = RewardType.Store, Value = 1.5f, Status = 0, Goal = goal }, new Reward { AttributeType = attributeType, Value = 3.5f, Status = 0, Goal = goal, TypeReward = RewardType.Modify, ActionRelation = new ActionRelation { Action = new Action { Verb = "testVerb", Activity = activity, Goal = goal }, Relationship = 0, ConcernChange = new Matrix { X = 0, Y = 0 }, RewardResourceChange = new Matrix { X = 0, Y = 0 } } } }; _context.Rewards.AddRange(rewards); await SaveChanges(_context, isAsync); Debug.WriteLine("Goals & related Seeded."); } }
/** * Verify if this account is online (with Last session being marked active) * * @return bool Returns TRUE if the account is online */ public static async Task <bool> IsOnline(SocialGamificationAssetContext db, Guid playerId) { var session = await GetSession(db, playerId); return(session != null); }
public async Task<ContentResult> AddOrUpdateCustomData( SocialGamificationAssetContext db, IList<CustomDataBase> sourceData) { return await Models.CustomData.AddOrUpdate(db, sourceData, Id, CustomDataType.Group); }
protected static async Task SeedGoals(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.ActorGoal.Any()) { var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync(); var goal = new Goal { Concern = new ConcernMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, RewardResource = new RewardResourceMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, Feedback = new GoalFeedback { Threshold = 0, Target = 0, Direction = 0 }, Description = "Test" }; var attributeType = new AttributeType { Name = "testAttribute", DefaultValue = 0f, Type = 0 }; var activity = new Activity { Name = "Testing" }; IList<ActorGoal> goals = new List<ActorGoal> { new ActorGoal { Actor = mayur, Goal = goal, Status = 0, ConcernOutcome = new ConcernMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, RewardResourceOutcome = new RewardResourceMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, Activity = activity, Role = new Role { Name = "Testing", Goal = goal, Activity = activity } } }; _context.ActorGoal.AddRange(goals); IList<Reward> rewards = new List<Reward> { new Reward { AttributeType = attributeType, TypeReward = RewardType.Store, Value = 1.5f, Status = 0, Goal = goal }, new Reward { AttributeType = attributeType, Value = 3.5f, Status = 0, Goal = goal, TypeReward = RewardType.Modify, ActionRelation = new ActionRelation { Action = new Action { Verb = "testVerb", Activity = activity, Goal = goal }, Relationship = 0, ConcernChange = new Matrix { X = 0, Y = 0 }, RewardResourceChange = new Matrix { X = 0, Y = 0 } } } }; _context.Rewards.AddRange(rewards); await SaveChanges(_context, isAsync); Debug.WriteLine("Goals & related Seeded."); } }
public static IList <Guid> GetAllianceIds(SocialGamificationAssetContext db, Guid actorId, AllianceState state) { IList <Alliance> alliances = db.Alliances.Where(IsAlliance(actorId)).Where(f => f.State == state).ToList(); return(AlliancesList(alliances, actorId)); }
/** * Check if the current Username already exists * * @return boolean Returns TRUE if Username exists */ public static async Task<bool> ExistsUsername(SocialGamificationAssetContext db, string username) { var group = await db.Groups.Where(g => g.Username.Equals(username)).FirstOrDefaultAsync(); return group != null; }
public IQueryable <Actor> Alliances(SocialGamificationAssetContext db) { return(Alliances(db, Id)); }
protected static async Task SeedCustomData(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.CustomData.Any()) { var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync(); var matt = await _context.Players.Where(a => a.Username.Equals("matt")).FirstOrDefaultAsync(); var jack = await _context.Players.Where(a => a.Username.Equals("jack")).FirstOrDefaultAsync(); var kam = await _context.Players.Where(a => a.Username.Equals("kam")).FirstOrDefaultAsync(); var ben = await _context.Players.Where(a => a.Username.Equals("ben")).FirstOrDefaultAsync(); IList <CustomData> customData = new List <CustomData> { new CustomData { Key = "ip", Value = "127.0.0.1", ObjectId = mayur.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "ip", Value = "127.0.0.1", ObjectId = matt.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "ip", Value = "127.0.0.1", ObjectId = jack.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "ip", Value = "127.0.0.1", ObjectId = ben.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "video_id", Value = "1234", ObjectId = mayur.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "video_id", Value = "1234", ObjectId = matt.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "video_id", Value = "1234", ObjectId = jack.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "chat_id", Value = "235f73ea-e54f-4150-8dc3-3eb9995d0728", ObjectId = mayur.Id, ObjectType = CustomDataType.Player }, new CustomData { Key = "chat_id", Value = "235f73ea-e54f-4150-8dc3-3eb9995d0728", ObjectId = matt.Id, ObjectType = CustomDataType.Player } }; _context.CustomData.AddRange(customData); await SaveChanges(_context, isAsync); Debug.WriteLine("CustomData Seeded."); } }
protected static async Task SeedGames(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.GameRegistry.Any()) { IList<GameRegistry> games = new List<GameRegistry> { new GameRegistry { Name = "ButtonGame", DeveloperName = "PlayGen" }, new GameRegistry { Name = "TankGame", DeveloperName = "PlayGen" } }; _context.GameRegistry.AddRange(games); await SaveChanges(_context, isAsync); Debug.WriteLine("Games Seeded."); // GameRegistry Game = await _context.GameRegistry.Where(g => g.Username.Equals("ButtonGame")).FirstOrDefaultAsync(); } }
public SessionsController(SocialGamificationAssetContext context) : base(context) { }
public TournamentsController(SocialGamificationAssetContext context) : base(context) { }
/** * Check if the current Username already exists * * @return boolean Returns TRUE if Username exists */ public static async Task <bool> ExistsUsername(SocialGamificationAssetContext db, string username) { var group = await db.Groups.Where(g => g.Username.Equals(username)).FirstOrDefaultAsync(); return(group != null); }
public AlliancesController(SocialGamificationAssetContext context) : base(context) { }
protected static async Task SeedPlayerSessions(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.Sessions.Any()) { var boardgame = await _context.Groups.Where(a => a.Username.Equals("boardgame")).FirstOrDefaultAsync(); var gameideas = await _context.Groups.Where(a => a.Username.Equals("gameideas")).FirstOrDefaultAsync(); var rage = await _context.Groups.Where(a => a.Username.Equals("rage")).FirstOrDefaultAsync(); IList <Session> sessions = new List <Session> { new Session { Player = new Player { Username = "******", Password = PasswordHelper.HashPassword("admin"), Role = AccountType.Admin } }, new Session { Player = new Player { Username = "******", Password = PasswordHelper.HashPassword("playgen"), Role = AccountType.Admin } }, new Session { Player = new Player { Username = "******", Email = "*****@*****.**", Password = PasswordHelper.HashPassword("mayur"), Groups = new List <Group> { boardgame, gameideas, rage } } }, new Session { Player = new Player { Username = "******", Email = "*****@*****.**", Password = PasswordHelper.HashPassword("jack"), Groups = new List <Group> { gameideas, rage } } }, new Session { Player = new Player { Username = "******", Email = "*****@*****.**", Password = PasswordHelper.HashPassword("matt"), Groups = new List <Group> { boardgame, rage } } }, new Session { Player = new Player { Username = "******", Password = PasswordHelper.HashPassword("ben"), Groups = new List <Group> { boardgame, gameideas } } }, new Session { Player = new Player { Username = "******", Password = PasswordHelper.HashPassword("kam"), Groups = new List <Group> { gameideas } } } }; _context.Sessions.AddRange(sessions); await SaveChanges(_context, isAsync); Debug.WriteLine("Players & Sessions Seeded."); } }
public AttributesController(SocialGamificationAssetContext context) : base(context) { }
public ActivitiesController(SocialGamificationAssetContext context) : base(context) { }
public IQueryable<Actor> Alliances(SocialGamificationAssetContext db) { return Alliances(db, Id); }
public static IQueryable<CustomData> ConditionBuilder( SocialGamificationAssetContext db, IList<CustomDataBase> sourceData, CustomDataType objectType) { var query = db.CustomData.Where(c => c.ObjectType == objectType); if (sourceData == null || sourceData.Count <= 0) { return null; } foreach (var data in sourceData) { query = query.Where(c => c.Key.Equals(data.Key)); if (!AllowedOperators.Contains(data.Operator)) { continue; } switch (data.Operator) { case "=": query = query.Where(c => c.Value.Equals(data.Value)); break; case "!": query = query.Where(c => c.Value != data.Value); break; case "%": query = query.Where(c => c.Value.Contains(data.Value)); break; } } return query; }
public static IQueryable<Actor> Alliances(SocialGamificationAssetContext db, Guid id, AllianceState state) { var alliancesList = Alliance.GetAllianceIds(db, id, state); return db.Actors.Where(a => alliancesList.Contains(a.Id)); }
public static IQueryable <Actor> Alliances(SocialGamificationAssetContext db, Guid id, AllianceState state) { var alliancesList = Alliance.GetAllianceIds(db, id, state); return(db.Actors.Where(a => alliancesList.Contains(a.Id))); }
public IQueryable<Actor> Alliances(SocialGamificationAssetContext db, AllianceState state) { return Alliances(db, Id, state); }
/** * Check if the current Email already exists * * @return boolean Returns TRUE if Username exists */ public static async Task <bool> ExistsEmail(SocialGamificationAssetContext db, string email) { var player = await db.Players.Where(p => p.Email.Equals(email)).FirstOrDefaultAsync(); return(player != null); }