public bool CheckCreatePermission(int userId, SingleLeagueCreateModel singleLeagueCreateModel) { bool result = false; if (userId == singleLeagueCreateModel.ScoredByUserId || userId == singleLeagueCreateModel.OpponentId) { result = true; } return(result); }
public SingleLeagueGoalModel CreateSingleLeagueGoal(SingleLeagueCreateModel singleLeagueCreateMode) { DateTime now = DateTime.Now; if (singleLeagueCreateMode == null) { throw new ArgumentNullException(nameof(singleLeagueCreateMode)); } SingleLeagueGoalModel newGoal = new(); newGoal.TimeOfGoal = now; newGoal.MatchId = singleLeagueCreateMode.MatchId; newGoal.ScoredByUserId = singleLeagueCreateMode.ScoredByUserId; newGoal.OpponentId = singleLeagueCreateMode.OpponentId; newGoal.ScorerScore = singleLeagueCreateMode.ScorerScore; newGoal.OpponentScore = singleLeagueCreateMode.OpponentScore; newGoal.WinnerGoal = singleLeagueCreateMode.WinnerGoal; _context.SingleLeagueGoals.Add(newGoal); _context.SaveChanges(); return(newGoal); }
public ActionResult CreateSingleLeagueGoal([FromBody] SingleLeagueCreateModel singleLeagueCreateModel) { try { string userId = User.Identity.Name; bool permission = _singleLeagueGoalService.CheckCreatePermission(int.Parse(userId), singleLeagueCreateModel); if (!permission) { return(Forbid()); } var newGoal = _singleLeagueGoalService.CreateSingleLeagueGoal(singleLeagueCreateModel); var singleLeagueGoalReadDto = _mapper.Map <SingleLeagueGoalReadDto>(singleLeagueCreateModel); return(CreatedAtRoute("getSingleLeagueById", new { goalId = newGoal.Id }, singleLeagueGoalReadDto)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }