コード例 #1
0
        public ActionResult CreateDoubleLeagueGoal([FromBody] DoubleLeagueGoalCreateDto doubleLeagueGoalCreateDto)
        {
            try
            {
                string userId = User.Identity.Name;
                string currentOrganisationId = User.FindFirst("CurrentOrganisationId").Value;

                bool hasPermission = _doubleLeaugeMatchService.CheckMatchAccess(doubleLeagueGoalCreateDto.MatchId, int.Parse(userId), int.Parse(currentOrganisationId));

                if (!hasPermission)
                {
                    return(Forbid());
                }

                var newGoal = _goalService.CreateDoubleLeagueGoal(doubleLeagueGoalCreateDto);

                var doubleLeagueGoalReadDto = _mapper.Map <DoubleLeagueGoalReadDto>(newGoal);

                return(CreatedAtRoute("GetDoubleLeagueGoalById", new { goalId = newGoal.Id }, doubleLeagueGoalReadDto));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
コード例 #2
0
        public DoubleLeagueGoalModel CreateDoubleLeagueGoal(DoubleLeagueGoalCreateDto doubleLeagueGoalCreateDto)
        {
            DateTime now = DateTime.Now;
            DoubleLeagueGoalModel newGoal = new();

            newGoal.TimeOfGoal        = now;
            newGoal.MatchId           = doubleLeagueGoalCreateDto.MatchId;
            newGoal.ScoredByTeamId    = doubleLeagueGoalCreateDto.ScoredByTeamId;
            newGoal.OpponentTeamId    = doubleLeagueGoalCreateDto.OpponentTeamId;
            newGoal.ScorerTeamScore   = doubleLeagueGoalCreateDto.ScorerTeamScore;
            newGoal.OpponentTeamScore = doubleLeagueGoalCreateDto.OpponentTeamScore;

            if (doubleLeagueGoalCreateDto.WinnerGoal != null)
            {
                newGoal.WinnerGoal = (bool)doubleLeagueGoalCreateDto.WinnerGoal;
            }

            newGoal.UserScorerId = doubleLeagueGoalCreateDto.UserScorerId;

            _context.DoubleLeagueGoals.Add(newGoal);
            _context.SaveChanges();

            return(newGoal);
        }