//删除 /// <summary> /// 删除 int?:可空(null)int类型 /// </summary> /// <param name="cid"></param> /// <returns></returns> public ActionResult Del(IList <int?> cid) { using (HrmDBEntities3 db = new HrmDBEntities3()) { foreach (int id in cid) { //删除 User_YG yg = db.User_YG.Find(id); db.User_YG.Remove(yg); } int count = db.SaveChanges(); return(Content(count + "条删除成功!")); } }
//添加员工信息 public ActionResult Add(User_YG yg) { DB.User_YG.Add(yg); int i = DB.SaveChanges(); if (i <= 0) { return(Content("添加失败")); } else { return(Content("添加成功")); } }
public ActionResult Login(User_YG yg, string Email, string PassWord) { if (Email.Length > 0 && PassWord.Length > 0) { if (ModelState.IsValid && Shujuyanzheng(Email, PassWord)) { var Luser = DB.User_YG.Where(n => n.UserName == Email).FirstOrDefault(); HttpCookie aCookie = new HttpCookie("Email"); aCookie.Value = Luser.UserName; aCookie.Expires = DateTime.Now.AddMinutes(2);//设置Cookie 的过期时间 System.Web.HttpContext.Current.Response.Cookies.Add(aCookie); HttpCookie Cookie = System.Web.HttpContext.Current.Response.Cookies.Get("Email"); Session["Email"] = Luser.UserName; string name = Session["Email"].ToString(); //通过姓名和密码查询他的职位 var one = (from s in DB.User_YG where s.UserName == Email && s.UserPwd == PassWord select s.RoleID).FirstOrDefault(); ViewBag.name = Email; switch (one) { case 5: return(RedirectToAction("Main", "Main", new { admin = "admin" })); case 4: return(RedirectToAction("Main", "Main", new { admin = "人事专员" })); case 3: return(RedirectToAction("Main", "Main", new { admin = "部门员工" })); case 2: return(RedirectToAction("Main", "Main", new { admin = "部门主管" })); case 1: return(RedirectToAction("Main", "Main", new { admin = "校区主任" })); default: return(RedirectToAction("Login")); } } else { ViewBag.yanzheng = "用户名或密码错误"; return(View()); } } else { ViewBag.yanzheng = "用户名或密码不能为空"; return(View()); } }