public List <TurnoverPerGenre> TurnoverPerGenre() { List <TurnoverPerGenre> turnoverPerGenre = new List <TurnoverPerGenre>(); List <int> ls = new List <int>(); foreach (var order in orepository.Orders) { foreach (var cartline in order.Lines) { for (int i = 0; i < cartline.Quantity; i++) { ls.Add(cartline.Game.ID); } } } var GenreTotalCost = from Game in repository.Games where ls.Contains(Game.ID) group Game by Game.Genre into GameGroup select new { Genre = GameGroup.Key, TotalProfit = GameGroup.Sum(x => x.PriceFinal), }; foreach (var s in GenreTotalCost) { turnoverPerGenre.Add(new TurnoverPerGenre { Genre = s.Genre, TotalProfit = Convert.ToDouble(s.TotalProfit) }); } return(turnoverPerGenre); }
public static void CreateOneGroupLoops(List <EntityBase> loopEntities, GameGroup group) { CheckMemberEvennumber(group); int memberCount = group.MemberList.Count; //逆时针轮转法 for (int i = 1; i < memberCount; i++) { foreach (var member in group.MemberList) { int index = group.MemberList.IndexOf(member); if (index + 1 > memberCount / 2) { break; } var loop = CreateLoopGame(group, i, member, index, memberCount - 1 - index); //排除轮空比赛 if (loop != null) { loop.LoopOrderNo = index + 1; loopEntities.Add(loop);//数据保存 } } //轮转位置 var last = group.MemberList[memberCount - 1]; group.MemberList.Remove(last); group.MemberList.Insert(1, last); } }
private static GameLoop CreateLoopGame(GameGroup group, int i, GameGroupMember member, int index, int indexOther) { var team1Id = group.MemberList[index].TeamId; var team2Id = group.MemberList[indexOther].TeamId; //排除轮空比赛 if (team1Id.IsNullOrEmpty() || team2Id.IsNullOrEmpty()) { return(null); } GameLoop loop = new GameLoop(); loop.SetNewId(); loop.SetCreateDate(); loop.SetRowAdded(); loop.OrderNo = i;//分组小轮次 loop.OrderId = group.OrderId; loop.GameId = member.GameId; loop.GroupId = member.GroupId; loop.Team1Id = team1Id; loop.Team2Id = team2Id; loop.IsTeam = member.IsTeam; loop.State = GameLoopState.NOTSTART.Id; loop.IsBye = group.MemberList[index].TeamId.IsNullOrEmpty() || group.MemberList[indexOther].TeamId.IsNullOrEmpty(); loop.JudgeId = group.LeaderId.GetId(); return(loop); }
private void StartCountDown(GameGroup gg) { while (!CountDownQueue.Contains(gg)) { CountDownQueue.Enqueue(gg); } }
///for load test harness - convert add game group from GroupList info private void addGameGroupAndUsers(string groupID) { GameGroup newGameGroup = new GameGroup(groupID); bool failedAdd = false; foreach (UserDetail user in GroupList.FirstOrDefault(o => o.id == groupID).users) { PlayerState playerState = new PlayerState(); playerState.Id = user.ConnectionId; if (!newGameGroup.PlayerStates.TryAdd(user.ConnectionId, playerState)) { failedAdd = true; } //LOW threadsafe Risk, only one client inititates creation of group } //What if not added initially, requires while loop? if (!GameGroups.TryAdd(groupID, newGameGroup)) { failedAdd = true; } //MEDIUM threadsafe Risk if (failedAdd) { //TODO: Add ClientError() callback DebugOut("Failed to Add Player to Group or Group to List"); } else { DebugOut("Added Following Group " + newGameGroup.id + " !!!!!! "); } }
public async Task <IActionResult> OnGetAsync(int Id, string Message) { IdentityUser user = await _userManager.GetUserAsync(User); Group = await _context.GameGroups.FindAsync(Id); if (Group == null) { return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find that Group" })); } if (Group.Owner != user.Email) { return(RedirectToPage("/error", new { errorMessage = "Sorry, Only the owner can manage a Group" })); } SelectedPath = await _context.Paths.FindAsync(Group.PathId); if (SelectedPath == null) { return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find the Path for this Group" })); } _context.Entry(Group) .Collection(g => g.GameTeams) .Load(); ViewData["PathSelectList"] = await GameGroup.GetPathSelectListAsync(_context); UserMessage = GetUserMessage(Message); return(Page()); }
private void InitGame(string groupID) { GameGroup newGroup = new GameGroup(groupID); bool failedAdd = false; foreach (UserDetail user in GroupList.FirstOrDefault(o => o.id == groupID).users) { PlayerState playerState = new PlayerState(); playerState.Id = user.ConnectionId; if (!newGroup.PlayerStates.TryAdd(user.ConnectionId, playerState)) { failedAdd = true; } //LOW threadsafe Risk, only one client inititates creation of group } //What if not added initially, requires while loop? if (!GameGroups.TryAdd(groupID, newGroup)) { failedAdd = true; } //MEDIUM threadsafe Risk if (failedAdd) { //Clients.Group(groupID).clientError("Couldn't Add Player", "Failed to Add a player(s) to the game"); //failed to add player to group or group list DebugOut("failed to add player to group or group list"); } else { Clients.Group(groupID).showGameScreen(); this.StartCountDown(GameGroups[groupID]); } }
public GameGroupUpdated(GameGroup gameGroup) { Id = gameGroup.Id; Name = gameGroup.Name; UpdatedDate = gameGroup.UpdatedDate.GetValueOrDefault(); UpdatedBy = gameGroup.UpdatedBy; }
public async Task <ActionResult <GameGroup> > PostGameGroup(GameGroup gameGroup) { _context.GameGroups.Add(gameGroup); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGameGroup", new { id = gameGroup.Id }, gameGroup)); }
public async Task <IActionResult> PutGameGroup(int id, GameGroup gameGroup) { if (id != gameGroup.Id) { return(BadRequest()); } _context.Entry(gameGroup).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameGroupExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private static void CreateSingleRound(GameOrder firstOrder, List <EntityBase> entities, Game game, List <GameTeam> teamList) { firstOrder.OrderNo = 1; firstOrder.Name = "单循环赛"; var group = new GameGroup { Name = "单循环组", GameId = game.Id, IsTeam = game.IsTeam, OrderNo = 1, LeaderId = game.CreatorId, OrderId = firstOrder.Id, MemberList = new List <GameGroupMember>() }; group.SetNewEntity(); //构建单分组 entities.Add(group); int memberOrderNo = 0; teamList.ForEach(p => { memberOrderNo++; var member = new GameGroupMember { TeamId = p.Id, GameId = firstOrder.GameId, GroupId = group.Id, IsTeam = firstOrder.IsTeam, OrderNo = memberOrderNo }; member.SetNewEntity(); group.MemberList.Add(member); }); //构建分组成员 SaveGameGroup.CreateOneGroupMembers(entities, group); //构建单循环比赛 SaveGameGroup.CreateOneGroupLoops(entities, group); }
public void UpdateGameGroup(GameGroup gameGroup) { gameGroup.UpdatedDate = DateTimeOffset.UtcNow; _repository.GameGroups.AddOrUpdate(gameGroup); _repository.SaveChanges(); }
public GameGroupCreated(GameGroup gameGroup) { Id = gameGroup.Id; Name = gameGroup.Name; Code = gameGroup.Code; CreatedDate = gameGroup.CreatedDate; CreatedBy = gameGroup.CreatedBy; }
public async Task <IActionResult> OnGetAsync() { // IdentityUser user = await _userManager.GetUserAsync(User); ViewData["PathSelectList"] = await GameGroup.GetPathSelectListAsync(_context); return(Page()); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { IdentityUser user = await _userManager.GetUserAsync(User); if (!ModelState.IsValid) { return(RedirectToPage("Group", new { Id = Group.Id })); } GameGroup UpdateGroup = await _context.GameGroups.FindAsync(Group.Id); if (UpdateGroup == null) { return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find that Group" })); } if (UpdateGroup.Owner != user.Email) { return(RedirectToPage("/error", new { errorMessage = "Sorry, Only the owner can manage a Group" })); } _context.Entry(UpdateGroup) .Collection(g => g.GameTeams) .Load(); if (await TryUpdateModelAsync <GameGroup>( UpdateGroup, "Group", // Prefix for form value. t => t.PathId)) { UpdateGroup.GroupState = (int)GameGroup.GameGroupState.InPlay; UpdateGroup.Modified = DateTime.Now; // go get the Path so we can set first step Path path = await _context.Paths.FindAsync(UpdateGroup.PathId); if (path == null) { return(RedirectToPage("/error", new { errorMessage = "That's Very Odd! We were not able to find the Path for this Group" })); } // We will need that first step. _ = await path.AddCalculatedPropertiesAsync(_context); // Now we need to iterate through each Team and reset it. foreach (GameTeam Team in UpdateGroup.GameTeams) { Team.CurrentStepId = path.FirstStepId; Team.TeamType = 0; Team.BoardState = (int)GameTeam.GameBoardState.WordSelect; Team.StepNumber = 1; Team.Modified = DateTime.Now; } await _context.SaveChangesAsync(); return(RedirectToPage("Group", new { Id = UpdateGroup.Id, Message = String.Format("Group {0} has been Restarted!", UpdateGroup.Name) })); } return(Page()); }
//take in list of bo public long Total(List <CalculationBO> calculation) { long value = (from Game in calculation group Game by Game.GameId into GameGroup orderby GameGroup.Sum(g => g.Price) descending select GameGroup.Key).FirstOrDefault(); return(value); }
public void UpdateGameGroup(GameGroup gameGroup) { gameGroup.UpdatedBy = _actorInfoProvider.Actor.UserName; gameGroup.UpdatedDate = DateTimeOffset.UtcNow; _repository.GameGroups.AddOrUpdate(gameGroup); _repository.SaveChanges(); _eventBus.Publish(new GameGroupUpdated(gameGroup)); }
private static void CheckMemberEvennumber(GameGroup group) { if (group.MemberList.Count % 2 != 0) { var emptyMember = new GameGroupMember { TeamId = string.Empty, GameId = group.GameId, GroupId = group.Id, IsTeam = group.IsTeam }; group.MemberList.Add(emptyMember); } }
public static void CreateOneGroupMembers(List <EntityBase> memberEntities, GameGroup group) { group.MemberList.ForEach(p => { p.SetRowAdded(); p.TeamId = p.TeamId.GetId(); p.SetNewId(); p.SetCreateDate(); memberEntities.Add(p); });//数据保存 }
/// <summary> /// 获取并设置比赛小组成员 /// </summary> /// <param name="group"></param> public static void SetGroupMemberList(GameGroup group) { var cmd = CommandHelper.CreateProcedure <GameGroupMember>(text: "sp_GetGameGroupMemberList"); cmd.Params.Add(CommandHelper.CreateParam("@gameId", group.GameId)); cmd.Params.Add(CommandHelper.CreateParam("@groupId", group.Id)); var result = DbContext.GetInstance().Execute(cmd); group.MemberList = new List <GameGroupMember>(); foreach (var user in result.Entities) { group.MemberList.Add(user as GameGroupMember); } }
public Guid CreateGameGroup(GameGroup gameGroup) { if (gameGroup.Id.Equals(Guid.Empty)) { gameGroup.Id = Guid.NewGuid(); } gameGroup.CreatedDate = DateTimeOffset.UtcNow; _repository.GameGroups.Add(gameGroup); _repository.SaveChanges(); return(gameGroup.Id); }
public Guid CreateGameGroup(GameGroup gameGroup) { if (gameGroup.Id.Equals(Guid.Empty)) { gameGroup.Id = Guid.NewGuid(); } gameGroup.CreatedBy = _actorInfoProvider.Actor.UserName; gameGroup.CreatedDate = DateTimeOffset.UtcNow; _repository.GameGroups.Add(gameGroup); _repository.SaveChanges(); _eventBus.Publish(new GameGroupCreated(gameGroup)); return(gameGroup.Id); }
private static void createGameGroup(GameOrder firstOrder, List <EntityBase> groupEntities) { for (int i = 1; i <= firstOrder.GroupCount; i++) { GameGroup group = new GameGroup(); group.SetCreateDate(); group.SetNewId(); group.SetRowAdded(); group.GameId = firstOrder.GameId; group.IsTeam = firstOrder.IsTeam; group.Name = string.Format("第{0}组", i); group.OrderId = firstOrder.Id; group.OrderNo = i; groupEntities.Add(group); } }
public async Task <IViewComponentResult> InvokeAsync(int GroupId, int TeamId) { List <PathNode> TeamSteps = new List <PathNode>(); GameGroup Group = await _context.GameGroups.FindAsync(GroupId); GameTeam Team = await _context.GameTeams.FindAsync(TeamId); string BibleId = await GameTeam.GetValidBibleIdAsync(_context, null); Path Path = await _context.Paths.FindAsync(Group.PathId); _ = await Path.AddCalculatedPropertiesAsync(_context); if (Team.BoardState == (int)GameTeam.GameBoardState.StepSelect) { TeamSteps = await Team.GetTeamStepsAsync(_context, BibleId); } Team.Steps = TeamSteps; return(View(Team)); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } try { Group = await _context.GameGroups.Include(G => G.GameTeams) .Where(G => G.Id == id).SingleAsync(); } catch { return(RedirectToPage("/error", new { errorMessage = "That's Odd! We were unable to retrieve this Group... Not sure what to tell you!" })); } // confirm Group Owner IdentityUser user = await _userManager.GetUserAsync(User); if (Group.Owner != user.Email) { return(RedirectToPage("/error", new { errorMessage = "Sorry! Only a Group Owner may delete a Group" })); } // First we need to iterate through each Step and delete them one by one, steps are a leaf node so this should be OK. foreach (GameTeam team in Group.GameTeams) { _context.GameTeams.Remove(team); } _context.GameGroups.Remove(Group); await _context.SaveChangesAsync(); return(RedirectToPage("./MyGroups")); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { IdentityUser user = await _userManager.GetUserAsync(User); if (!ModelState.IsValid) { ViewData["PathSelectList"] = await GameGroup.GetPathSelectListAsync(_context); return(Page()); } // Now let's create an empty group var emptyGroup = new GameGroup { Created = DateTime.Now, Modified = DateTime.Now, GroupState = (int)GameGroup.GameGroupState.Open, Owner = user.Email }; if (await TryUpdateModelAsync <GameGroup>( emptyGroup, "Group", // Prefix for form value. g => g.Name, g => g.PathId)) { _context.GameGroups.Add(emptyGroup); await _context.SaveChangesAsync(); // go get the Path so we can set first step Path path = await _context.Paths.FindAsync(emptyGroup.PathId); if (path == null) { return(RedirectToPage("/error", new { errorMessage = "That's Very Odd! We were not able to find the Path for this Group" })); } // We will need that first step. _ = await path.AddCalculatedPropertiesAsync(_context); // Now we need to parse our Teams and add/remove foreach (GameTeam Team in Teams) { if (Team.Name != null) { if (Team.Name.Length > 0) { var emptyTeam = new GameTeam { CurrentStepId = path.FirstStepId, TeamType = 0, BoardState = (int)GameTeam.GameBoardState.WordSelect, StepNumber = 1, Created = DateTime.Now, Modified = DateTime.Now, }; emptyTeam.Name = Team.Name; emptyTeam.Group = emptyGroup; _context.GameTeams.Add(emptyTeam); } } } await _context.SaveChangesAsync(); return(RedirectToPage("Group", new { Id = emptyGroup.Id, Message = String.Format("Group {0} successfully created...", emptyGroup.Name) })); } return(Page()); }