public JsonResult update(String studentNum, Dormitory dormitory)
        {
            //获取学生信息  得到原本宿舍信息
            Student student = db.Students.Find(studentNum);

            if (student == null)
            {
                return(Json(ResultMap.errorMsg("查无此人"), JsonRequestBehavior.AllowGet));
            }
            try
            {
                //保存学生原本宿舍信息
                string buildingNum  = student.buildingNum;
                string dormitoryNum = student.dormitoryNum;
                //修改学生信息
                student.buildingNum  = dormitory.buildingNum;
                student.dormitoryNum = dormitory.dormitoryNum;
                //修改原本宿舍和新宿舍 已住人数   因为mdoel定义时  dormitorynum为1所以参数放前面
                Dormitory old = db.Dormitories.Find(dormitoryNum, buildingNum);
                old.residentNum = old.residentNum - 1;
                Dormitory newd = db.Dormitories.Find(dormitory.dormitoryNum, dormitory.buildingNum);
                newd.residentNum = newd.residentNum + 1;
                //保存修改
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(Json(ResultMap.errorMsg("数据库错误"), JsonRequestBehavior.AllowGet));
            }
            return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
        }
 public JsonResult regist(EquipmentLease el)
 {
     el.leaseDate = DateTime.Now;//传时间
     db.EquipmentLeases.Add(el);
     db.SaveChanges();
     return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
 }
        public JsonResult edit(EquipmentLease el)
        {
            EquipmentLease e = db.EquipmentLeases.Find(el.id);

            e.returnDate = el.returnDate;
            db.SaveChanges();
            return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
        }
        public JsonResult edit(Repair repair)
        {
            Repair r = db.Repairs.Find(repair.id);

            r.resolutionDate = repair.resolutionDate;
            db.SaveChanges();
            return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
        }
        public JsonResult getAll()
        {
            var ds = from item in db.LateReturns
                     where true //此处可以写条件表达式
                     select item;

            return(Json(ResultMap.OK(ds.ToList()), JsonRequestBehavior.AllowGet));
        }
        public JsonResult getAll()
        {
            var ds = from item in db.Dormitories
                     where true //此处可以写条件表达式
                     orderby item.buildingNum descending
                     select item;

            return(Json(ResultMap.OK(ds.ToList()), JsonRequestBehavior.AllowGet));
        }
        public JsonResult getAll()
        {
            var ds = from item in db.WaterElectricityCosts
                     where true //此处可以写条件表达式  升序
                     orderby item.buildingNum ascending
                     select item;

            return(Json(ResultMap.OK(ds.ToList()), JsonRequestBehavior.AllowGet));
        }
        public JsonResult getAll()
        {
            var ds = from item in db.VisitorInfos
                     where true //此处可以写条件表达式  升序
                     orderby item.date ascending
                     select item;

            return(Json(ResultMap.OK(ds.ToList()), JsonRequestBehavior.AllowGet));
        }
        public JsonResult getNoReturn()
        {
            var ds = from item in db.EquipmentLeases
                     where item.returnDate == null //此处可以写条件表达式  升序
                     orderby item.leaseDate ascending
                     select item;

            return(Json(ResultMap.OK(ds.ToList()), JsonRequestBehavior.AllowGet));
        }
        public JsonResult getOne(String studentNum)
        {
            Student student = db.Students.Find(studentNum);

            if (student == null)
            {
                return(Json(ResultMap.errorMsg("查无此人,请确认学号是否正确"), JsonRequestBehavior.AllowGet));
            }
            return(Json(ResultMap.OK(student), JsonRequestBehavior.AllowGet));
        }
        public JsonResult addFeedBack(String content)
        {
            Feedback feedback = new Feedback();

            feedback.content = content;
            feedback.date    = DateTime.Now;
            db.Feedbacks.Add(feedback);
            db.SaveChanges();
            return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
        }
Example #12
0
        public JsonResult getOne(int staffNum)
        {
            Staff staff = db.Staffs.Find(staffNum);

            if (staff == null)
            {
                return(Json(ResultMap.errorMsg("查无此人,请确认员工号是否正确"), JsonRequestBehavior.AllowGet));
            }
            return(Json(ResultMap.OK(staff), JsonRequestBehavior.AllowGet));
        }
Example #13
0
        public JsonResult reset(String studentNum)
        {
            User user = db.Users.Find(studentNum);

            if (user == null)
            {
                return(Json(ResultMap.errorMsg("没有这个用户"), JsonRequestBehavior.AllowGet));
            }
            user.password = studentNum;
            db.SaveChanges();
            return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
        }
Example #14
0
        public JsonResult update(Staff staff)
        {
            Staff s = db.Staffs.Find(staff.staffNum);

            s.name         = staff.name;
            s.position     = staff.position;
            s.sex          = staff.sex;
            s.age          = staff.age;
            s.contractInfo = staff.contractInfo;
            db.SaveChanges();
            return(Json(ResultMap.OK(s), JsonRequestBehavior.AllowGet));
        }
        public JsonResult update(Student student)
        {
            //try懒得写了
            Student s = db.Students.Find(student.studentNum);

            if (s == null)
            {
                return(Json(ResultMap.errorMsg("查无此人,请确认学号是否正确"), JsonRequestBehavior.AllowGet));
            }
            //s = student;   不能直接赋值会修改s的引用,导致save操作没办法更新
            s.major        = student.major;
            s.name         = student.name;
            s.sex          = student.sex;
            s.contractInfo = student.contractInfo;
            db.SaveChanges();
            return(Json(ResultMap.OK(s), JsonRequestBehavior.AllowGet));
        }
        public JsonResult getWE(String studentNum)
        {
            //查找学生宿舍信息
            Student student = db.Students.Find(studentNum);

            if (student == null)
            {
                return(Json(ResultMap.errorMsg("查无此人,请确认学号是否正确"), JsonRequestBehavior.AllowGet));
            }
            //根据楼号宿舍号查找该宿舍所有
            var ds = from item in db.WaterElectricityCosts
                     where item.buildingNum == student.buildingNum && item.dormitoryNum == student.dormitoryNum //此处可以写条件表达式  升序
                     orderby item.month ascending
                     select item;

            return(Json(ResultMap.OK(ds.ToList()), JsonRequestBehavior.AllowGet));
        }
Example #17
0
        public JsonResult login(User user)
        {
            if (ModelState.IsValid)
            {
                var u = db.Users.Find(user.username);
                //if(user)

                /*if (u == null) {
                 *  var error = "账号密码不匹配,请检查";
                 * }
                 *  return Json()*/
                //Console.WriteLine("方法执行" + user.password);
                if (u == null)
                {
                    return(Json(ResultMap.errorMsg("用户不存在"), JsonRequestBehavior.AllowGet));
                }
                else if (u.password != user.password && u.type == user.type)
                {
                    return(Json(ResultMap.errorMsg("密码错误或者类型错误"), JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                StringBuilder errMsg = new StringBuilder();
                //获取错误信息并返回
                var values = ModelState.Values;

                foreach (var item in values)
                {
                    foreach (var error in item.Errors)
                    {
                        errMsg.Append(error.ErrorMessage + " ");
                    }
                }
                //ResultMap.errorMsg(errMsg.ToString())
                return(Json(ResultMap.errorMsg(errMsg.ToString()), JsonRequestBehavior.AllowGet));
            }
        }
 public JsonResult quit(String studentNum)
 {
     try
     {
         //得到学生对象
         Student student = db.Students.Find(studentNum);
         User    user    = db.Users.Find(studentNum);//学生学号为登录名
         //得到对应宿舍对象
         Dormitory dormitory = db.Dormitories.Find(student.dormitoryNum, student.buildingNum);
         dormitory.residentNum = dormitory.residentNum - 1;
         //删除学生记录  删除学生账号
         db.Students.Remove(student);
         db.Users.Remove(user);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         return(Json(ResultMap.errorMsg("数据库异常,请稍后再试"), JsonRequestBehavior.AllowGet));
     }
     return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
 }
Example #19
0
        public JsonResult Upload(HttpPostedFileBase file, String username)
        {
            if (file == null)
            {
                return(Json(ResultMap.errorMsg("没有上传文件"), JsonRequestBehavior.AllowGet));
            }

            var fileName = file.FileName;
            var filePath = Path.Combine(Server.MapPath("~/upload"), fileName);

            try
            {
                file.SaveAs(filePath);
                //查询该用户并更新iconpath字段并保存修改
                User user = db.Users.Find(username);
                user.iconPath = "../upload/" + fileName;
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(Json(ResultMap.errorMsg("服务器异常"), JsonRequestBehavior.AllowGet));
            }
            return(Json(ResultMap.OK("../upload/" + fileName), JsonRequestBehavior.AllowGet));
        }
 public JsonResult add(VisitorInfo vs)
 {
     db.VisitorInfos.Add(vs);
     db.SaveChanges();
     return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
 }
 public JsonResult add(OutInCheck oc)
 {
     db.OutInChecks.Add(oc);
     db.SaveChanges();
     return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
 }
 public JsonResult add(LateReturn lr)
 {
     db.LateReturns.Add(lr);
     db.SaveChanges();
     return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
 }
 public JsonResult addRepair(Repair repair)
 {
     db.Repairs.Add(repair);
     db.SaveChanges();
     return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
 }