笔试考试系统 ____学生信息修改

1.今日任务

学生信息修改

笔试考试系统 ____学生信息修改_第1张图片

 

 控制器对应代码:

 1 using Exam.UI.Filter;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Web;
 6 using System.Web.Mvc;
 7 using Exam.BLL;
 8 using Utility;
 9 using Exam.Model;
10 
11 namespace Exam.UI.Controllers
12 {
13     [AdminFilter]
14     public class StudentController : Controller
15     {
16         // GET: Student
17         public ActionResult Index()
18         {
19             var name = Session[CommonFeild.SessionName] as Exam_User;
20 
21             return View(name);
22         }
23         public ActionResult Main()
24         {
25             return View();
26         }
27         public ActionResult MyInfo()
28         {
29            var currentuser= Session[CommonFeild.SessionName] as Exam_User;
30             return View(currentuser);
31         }
32         [HttpPost]
33         public ActionResult Edit(string uname, string Name, string phone, string id)
34         {
35             Exam_User u = new Exam_User { UserID = System.Convert.ToInt32(id), RealName = Name, UserName = uname, Phone = phone };
36             try
37             {
38                 StudentMannerService.Update(u);
39             }
40             catch (Exception ex)
41             {
42                 return Json(new { msg = "修改失败" + ex, success = false });
43 
44             }
45             return Json(new { msg = "修改成功", success = true });
46 
47         }
48 
49        
50     }
51 }

Service层对应方法

 1 using PagedList;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 using Exam.Model;
 8 using Exam.DAL;
 9 
10 namespace Exam.BLL
11 {
12     public class StudentMannerService
13     {
14         
15         public static Exam_User FindStudentByID(int id)
16         {
17             using (ExamSysDBContext dBContext = new ExamSysDBContext())
18             {
19 
20                 var data = dBContext.Exam_User.Where(x => x.UserID == id).FirstOrDefault();
21                 return data;
22             }
23         }
24     
25         public static int Update(Exam_User u)
26         {
27             using (ExamSysDBContext dBContext = new ExamSysDBContext())
28             {
29                 var data = dBContext.Exam_User.Where(x => x.UserID == u.UserID).FirstOrDefault();
30                 data.UserName = u.UserName;
31                 data.Phone = u.Phone;
32                 data.RealName = u.RealName;
33                 return dBContext.SaveChanges();
34             }                
35         }
36     }
37 }

3.遇到问题

4.解决方案

你可能感兴趣的:(笔试考试系统 ____学生信息修改)