public IHttpActionResult PostAward(int userId, int awardId) { if (_personRepository.Get(userId) == null || _badgeRepository.Get(awardId) == null) { return(NotFound()); } if (_recognitionRepository.GetByPersonId(userId).Any(p => p.BadgeId == awardId)) { return(BadRequest("User already has that badge")); } if (_recognitionRepository.Add(userId, awardId)) { return(Ok()); } return(InternalServerError()); }
public ActionResult AddRecognition(AddNewBadgeViewModel recognition) { if (_recognitionRepository.Exists(recognition.PersonId, recognition.BadgeId)) { var errors = new Dictionary <string, string[]> { { "Badges", new [] { "Person already has that badge" } } }; var errorMessage = new JavaScriptSerializer().Serialize(errors); return(Json(new { error = true, message = errorMessage })); } if (_recognitionRepository.Add(recognition.PersonId, recognition.BadgeId)) { return(Json(new { success = true })); } return(Json(new { error = true })); }