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


    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.解决方案

  • 相关阅读:
    jmeter常用功能补充介绍
    服务器性能监控
    shell三剑客介绍及实例
    shell基础
    jmeter基本使用及基于jmeter的数据验证
    使用Loadrunner进行性能测试
    react-loadable 源码解析
    DOMException [SecurityError]: localStorage is not available for opaque origins
    mac 安装node并且安装jsdom
    python操作关系型数据库mysql pgsql返回字典类型的数据
  • 原文地址:https://www.cnblogs.com/zhangdongwei/p/13426497.html
Copyright © 2020-2023  润新知