public NewUserAchievement SubmitAchievement(NewUserAchievementRequest newAchievementRequest) { using (SqlConnection connection = new SqlConnection(_connectionString)) { if (!UserAchievementExists(newAchievementRequest.AchievementId, newAchievementRequest.UserId)) { var newAchievement = new NewUserAchievement() { UserId = newAchievementRequest.UserId, AchievementId = newAchievementRequest.AchievementId, Link = newAchievementRequest.Link, IsApproved = false, IsPending = true, DateSubmitted = DateTime.Now }; var queryString = @"Insert into UserAchievement(UserId, AchievementId, Link, IsPending, IsApproved, DateSubmitted) Output inserted.* Values(@UserId, @AchievementId, @Link, @IsPending, @IsApproved, @DateSubmitted)"; var achievement = connection.QueryFirstOrDefault <NewUserAchievement>(queryString, newAchievement); return(achievement); } } throw new Exception("Could not post new achievement."); }
public ActionResult SubmitAchievement(NewUserAchievementRequest newAchievement) { var achievement = _connection.SubmitAchievement(newAchievement); return(Accepted(achievement)); }