Exemplo n.º 1
0
        public async Task <IActionResult> CalPenaltyAvg(string hTeamGroup, string[] inputName, int[] inputAvg, string hendDate)
        {
            string[] yymm = hendDate.Split('-');
            hendDate = hendDate + "-" + DateTime.DaysInMonth(int.Parse(yymm[0]), int.Parse(yymm[1])).ToString() + " 23:59"; //마지막날 추가

            string startDate = DateTime.Parse(hendDate).AddMonths(-2).ToString("yyyy-MM") + "-01 00:00";


            int cnt            = 0;
            var bowlerAverages = new List <BowlerAverage>();


            //들어온 자료를 list에 채워 넣음
            foreach (var item in inputName)
            {
                BowlerAverage bAvg = new BowlerAverage
                {
                    Average  = inputAvg[cnt],
                    BowlerID = item
                };
                bowlerAverages.Add(bAvg);

                cnt++;
            }

            var penaltyAvg = _context.BowlerAverages.Include(b => b.Bowler)
                             .Where(b => (b.Bowler.Group == hTeamGroup) &&
                                    (b.Bowler.InActivity == false && b.Bowler.RegisterDate <= DateTime.Parse(hendDate) ||
                                     (b.Bowler.InActivity == true && b.Bowler.LeaveDate >= DateTime.Parse(startDate))))
                             .OrderBy(b => b.BowlerID);


            // 업데이트 하기
            //중요   listYearAverages와 tlist의 개수가 같아야 함 ...
            var tlist = bowlerAverages.OrderBy(b => b.BowlerID).ToList();

            cnt = 0;


            foreach (var item in penaltyAvg)
            {
                if (item.Average != tlist[cnt].Average || item.Bigo != yymm[0] + "-" + yymm[1])
                {
                    item.Average = tlist[cnt].Average;
                    item.Bigo    = yymm[0] + "-" + yymm[1];
                }
                cnt++;
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw;
            }

            return(RedirectToAction("Index", "Bowlers"));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Game> > PostGame([FromBody] Game game)
        {
            _context.Games.Add(game);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       "GetGame",
                       new { id = game.GameId },
                       game
                       ));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("BowlerID,Name,Group,InActivity, BowlerAverage, RegisterDate, LeaveDate, Bigo")] Bowler bowler)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bowler);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(bowler));
        }
Exemplo n.º 4
0
        public async Task <ActionResult <Shot> > PostShot([FromBody] Shot shot)
        {
            _context.Shots.Add(shot);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       "GetShot",
                       new { id = shot.ShotId },
                       shot
                       ));
        }
Exemplo n.º 5
0
        public async Task <ActionResult <Frame> > PostFrame([FromBody] Frame frame)
        {
            _context.Frames.Add(frame);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       "GetFrame",
                       new { id = frame.FrameId },
                       frame
                       ));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> StartNewSession([FromBody] BowlingSession session)
        {
            await ThrowIfUserIsGuestAsync();

            _logger.LogInformation($"Starting new session for {session.Date}");
            await _bowlingContext.Sessions.AddAsync(session);

            await _bowlingContext.SaveChangesAsync();

            return(Ok(session));
        }
        public async Task <IActionResult> Create([Bind("ID,BowlerID,Year,Average,Bigo")] YearAverage yearAverage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(yearAverage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BowlerID"] = new SelectList(_context.Bowlers, "BowlerID", "BowlerID", yearAverage.BowlerID);
            return(View(yearAverage));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Playtime,Place,GameKind,GameContent,bCalTotal,Penalty,Group,bFine, bHandicap, bAward, GameMemo")] Game game)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(game);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Game_Create_Error");
            }

            return(View(game));
        }
        public async Task <IActionResult> CreateTeam(int Id, int[] teamCnt, string[] selectLst)
        {
            int teamcnt = 0;
            int cnt     = 0;

            int               round       = 1;
            SubGame           subgame     = new SubGame();
            List <Team>       team        = new List <Team>();
            List <TeamMember> teamMembers = new List <TeamMember>();

            if (_context.SubGames.Where(s => s.GameID == Id).Count() > 0)
            {
                round = _context.SubGames.Where(s => s.GameID == Id).Max(s => s.Round) + 1;
            }

            subgame.GameID = Id;
            subgame.Round  = round;

            await _context.SubGames.AddAsync(subgame);


            int halfcnt = teamCnt.Count() % 2 == 0 ? teamCnt.Count() / 2 : teamCnt.Count() / 2 + 1;

            foreach (var item in teamCnt)
            {
                int idx = 0;

                if (teamcnt < halfcnt)
                {
                    idx = teamcnt * 2;
                }
                else
                {
                    idx = (teamcnt - halfcnt) * 2 + 1;
                }

                team.Add(new Team
                {
                    SubGameID = subgame.ID,
                    TeamName  = ((Char)(65 + idx)).ToString(),
                    TeamOrder = idx
                });

                await _context.AddAsync(team[teamcnt]);

                for (int i = 0; i < item; i++)
                {
                    teamMembers.Add(new TeamMember
                    {
                        BowlerID = selectLst[cnt],
                        Score    = 0,
                        Average  = _context.BowlerAverages.Find(selectLst[cnt]).Average,
                        TeamID   = team[teamcnt].ID,
                        Sequence = i
                    });

                    cnt++;
                }

                teamcnt++;
            }

            await _context.AddRangeAsync(team);

            await _context.AddRangeAsync(teamMembers);

            await _context.SaveChangesAsync();


            return(RedirectToAction(nameof(Index), new { Id = Id }));
        }