public JsonResult UpdateStudentInfo(Student student) { ResultState resultState = CheckCookie(); //ResultState resultState = new ResultState(); // resultState.Code = 1; if (resultState.Code != 0) { var stuInDb = _context.students.Find(student.StudentID); if (stuInDb.Name == student.Name && stuInDb.Password == student.Password && stuInDb.StudentID == student.StudentID && stuInDb.isAdmin == student.isAdmin) { resultState.Message = "未做任何修改"; return(new JsonResult(resultState)); } else if (stuInDb.Name != student.Name) { resultState.Message = "学生名不可修改,请重新设定"; resultState.value = stuInDb; return(new JsonResult(resultState)); } stuInDb.Enrollment = student.Enrollment; stuInDb.Department = student.Department; stuInDb.Password = student.Password; stuInDb.isAdmin = student.isAdmin; _context.SaveChanges(); resultState.Message = "修改成功"; resultState.Success = true; resultState.value = student; } return(new JsonResult(resultState)); }
public JsonResult AddFinalWork([FromForm] IFormFileCollection WorkFile, [FromForm] int coursid) { var file = WorkFile; ResultState resultState = CheckCookie(); //bool success, string message, int code, object value //ResultState resultState = new ResultState(true, "", 2, null); if (resultState.Code != 2) { return(new JsonResult(new ResultState(false, "权限不够或者没有登录", 0, null))); } if (file == null) { return(new JsonResult(new ResultState(false, "未添加文件", 0, null))); } try { string couidString = coursid.ToString(); List <string> url = InputFile.inputFile(file, couidString); if (url[0] == "null") { return(new JsonResult(new ResultState(false, "文件参数异常", 0, null))); } else if (url[0] == "error") { return(new JsonResult(new ResultState(false, "上传失败", 0, null))); } else { var couseInDb = _context.Courses.Where(x => x.CourseID == coursid).FirstOrDefault(); StringBuilder courseurl = new StringBuilder(); courseurl.Append(couseInDb.url); foreach (var urlname in url) { courseurl.Append(urlname); courseurl.Append("|"); } couseInDb.url = courseurl.ToString(); _context.SaveChanges(); return(new JsonResult(new ResultState(true, "上传成功", 1, url))); } } catch (Exception) { throw; } }