public Achievement AwardAchievement(string achieTitle, Guid userId) { var existingAchie = _achievementService .AsQueryable() .Where(x => x.Title == achieTitle) .FirstOrDefault(); if (existingAchie is null) { throw new Exception($"Achievement with title {achieTitle} does not exist!"); } var userHasAchievement = _userAchievementService .AsQueryable() .Any(x => x.AchievementId == existingAchie.Id && x.UserId == userId); if (!userHasAchievement) { if (EligibleForAchievement(achieTitle, userId)) { var userAchie = new UserAchievement { AchievementId = existingAchie.Id, UserId = userId }; var achie = existingAchie; _userAchievementService.AddUserAchievement(userAchie); return(achie); } } return(null); }
public ActionResult <Achievement> Get(Guid id) { var item = _AchievementService.AsQueryable() .Where(x => x.Id == id) .FirstOrDefault(); if (item is null) { return(NoContent()); } return(Ok(item)); }