public List <int> reportUpdate([FromBody] reportStudent RS) { if (RS.level2_score > 0) { var all = data.Database.ExecuteSqlCommand(@"update Reports set level2_score =" + RS.level2_score + " where report_id =" + RS.report_id); var report_id = data.Database.SqlQuery <int>(@"select top 1 report_id from Reports order by report_id desc").ToList(); return(report_id); } else if (RS.level3_score > 0) { var all = data.Database.ExecuteSqlCommand(@"update Reports set level3_score =" + RS.level3_score + " where report_id =" + RS.report_id); List <int> list = new List <int>() { 1 }; return(list); } else { List <int> list = new List <int>() { 0 }; return(list); } }
public List <int> reportInsert([FromBody] reportStudent RS) { var exam_id = data.Database.SqlQuery <int>(@"select exam_id from Exam_List where exam_name = @exam_name", new SqlParameter("@exam_name", RS.subject)).ToList(); var all = data.Database.ExecuteSqlCommand(@"insert into Reports(user_id,exam_id,exam_name,level1_score,level2_score,level3_score) values (@user_id,@exam_id,@exam_name,@level1_score,@level2_score,@level3_score)", new SqlParameter("@user_id", RS.user_id), new SqlParameter("@exam_id", exam_id.First()), new SqlParameter("@exam_name", RS.subject), new SqlParameter("@level1_score", RS.level1_score), new SqlParameter("@level2_score", RS.level2_score), new SqlParameter("@level3_score", RS.level3_score)); var report_id = data.Database.SqlQuery <int>(@"select top 1 report_id from Reports order by report_id desc").ToList(); return(report_id); }