public ActionResult CreateFreehandMatch([FromBody] FreehandMatchCreateDto freehandMatchCreateDto)
        {
            try
            {
                string userId = User.Identity.Name;
                string currentOrganisationId = User.FindFirst("CurrentOrganisationId").Value;

                if (freehandMatchCreateDto.PlayerOneId != int.Parse(userId) && freehandMatchCreateDto.PlayerTwoId != int.Parse(userId))
                {
                    return(Forbid());
                }

                FreehandMatchModel newMatch = _matchService.CreateFreehandMatch(int.Parse(userId), int.Parse(currentOrganisationId), freehandMatchCreateDto);

                var freehandMatchesReadDto = _mapper.Map <FreehandMatchCreateResultDto>(newMatch);

                return(CreatedAtRoute("GetFreehandMatchById", new { matchId = newMatch.Id }, freehandMatchesReadDto));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
示例#2
0
        public FreehandMatchModel CreateFreehandMatch(int userId, int organisationId, FreehandMatchCreateDto freehandMatchCreateDto)
        {
            FreehandMatchModel fmm = new FreehandMatchModel();
            DateTime           now = DateTime.Now;

            fmm.PlayerOneId    = freehandMatchCreateDto.PlayerOneId;
            fmm.PlayerTwoId    = freehandMatchCreateDto.PlayerTwoId;
            fmm.PlayerOneScore = freehandMatchCreateDto.PlayerOneScore;
            fmm.PlayerTwoScore = freehandMatchCreateDto.PlayerTwoScore;
            fmm.StartTime      = now;
            fmm.GameFinished   = freehandMatchCreateDto.GameFinished;
            fmm.GamePaused     = freehandMatchCreateDto.GamePaused;
            fmm.UpTo           = freehandMatchCreateDto.UpTo;
            fmm.OrganisationId = organisationId;
            _context.FreehandMatches.Add(fmm);
            _context.SaveChanges();

            return(fmm);
        }