public HttpStatusCode Post(GradeBookView.StudentGrade gbUpdate) { var gbRepo = new GradeBookRepository(); gbRepo.EditGradebook(gbUpdate); return(HttpStatusCode.OK); }
public void EditGradebook(GradeBookView.StudentGrade gbUpdate) {//this approach makes two calls to the database there is probably a way to do this all in one SQL Stored Procedure using (var cn = new SqlConnection(Config.GetConnectionString())) { var p = new DynamicParameters(); p.Add("@RosterId", gbUpdate.RosterId); p.Add("@AssignmentId", gbUpdate.AssignmentId); p.Add("@Points", gbUpdate.Points); p.Add("@Score", gbUpdate.Score); if (//checks to see if grade exists cn.Query <AssignmentGrade>("AssignmentGrade_GetByRosterIdAndAssignmentId", p, commandType: CommandType.StoredProcedure) .Any()) { cn.Execute("AssignmentGrade_UpdateScore", p, commandType: CommandType.StoredProcedure); //updates existing grade } else { cn.Execute("AssignmentGrade_Insert", p, commandType: CommandType.StoredProcedure); //creates new grade } } }