public IActionResult Post([FromBody] Achievement item) { try { if (item == null || !ModelState.IsValid || item.Goal != null || item.AchievementId != 0 || item.GoalId == 0 || item.Achieved < 0) { return(BadRequest(ErrorCode.DataProvidedIsInvalid.ToString())); } var goalItem = _goalRepository.Find(item.GoalId); if (goalItem == null || goalItem.User.Email != User.FindFirstValue(ClaimTypes.Email)) { return(BadRequest(ErrorCode.DataProvidedIsInvalid.ToString())); } _achievementRepository.Insert(item); } catch (Exception) { return(BadRequest(ErrorCode.CouldNotCreateItem.ToString())); } return(Ok(item)); }
public IActionResult Get(long id) { var goalItem = _goalRepository.Find(id); if (goalItem == null) { return(NotFound(ErrorCode.ItemNotFound.ToString())); } return(Ok(goalItem)); }