コード例 #1
0
 public bool AddOrUpdate(td_ComputerRoom entity)
 {
     if (entity.ID < 1)
     {
         dbContext.Add(entity);
     }
     return(dbContext.Update(entity, c => c.ID == entity.ID));
 }
コード例 #2
0
        public JsonResult AddOrUpdate()
        {
            var sReturnModel = new ReturnMessageModel();

            #region 登录验证
            if (!Utits.IsLogin)
            {
                sReturnModel.ErrorType      = 3;
                sReturnModel.MessageContent = "登录状态已失效.";
                return(Json(sReturnModel));
            }
            #endregion

            int    id     = RequestParameters.Pint("ID");
            string DeptId = RequestParameters.Pstring("Dept_Id");
            int    jg     = RequestParameters.Pint("jg");
            int    kt     = RequestParameters.Pint("kt");
            int    sxt    = RequestParameters.Pint("sxt");
            int    mhq    = RequestParameters.Pint("mhq");
            int    UPS    = RequestParameters.Pint("UPS");
            int    fhm    = RequestParameters.Pint("fhm");
            int    fhdb   = RequestParameters.Pint("fhdb");
            int    qtmhzz = RequestParameters.Pint("qtmhzz");
            int    fljsb  = RequestParameters.Pint("fljsb");
            int    fjdsb  = RequestParameters.Pint("fjdsb");
            int    fdcgr  = RequestParameters.Pint("fdcgr");
            int    fcsb   = RequestParameters.Pint("fcsb");
            int    fwq    = RequestParameters.Pint("fwq");

            if (fwq < 1)
            {
                sReturnModel.ErrorType      = 0;
                sReturnModel.MessageContent = "操作失败:服务器数量不能小于1台.";
                return(Json(sReturnModel));
            }

            var currentUser = Utits.CurrentUser;

            #region 检查参数(暂不做处理)
            //if (ECode.Length < 1)
            //{
            //    sReturnModel.ErrorType = 0;
            //    sReturnModel.MessageContent = "操作失败:员工号不能为空.";
            //    return Json(sReturnModel);
            //}
            //if (WCode.Length < 1)
            //{
            //    sReturnModel.ErrorType = 0;
            //    sReturnModel.MessageContent = "操作失败:考勤号不能为空.";
            //    return Json(sReturnModel);
            //}
            //if (Name.Length < 1)
            //{
            //    sReturnModel.ErrorType = 0;
            //    sReturnModel.MessageContent = "操作失败:姓名不能为空.";
            //    return Json(sReturnModel);
            //}
            //if (Dept.Length < 1)
            //{
            //    sReturnModel.ErrorType = 0;
            //    sReturnModel.MessageContent = "操作失败:部门不能为空.";
            //    return Json(sReturnModel);
            //}
            //if (Login.Length < 1)
            //{
            //    sReturnModel.ErrorType = 0;
            //    sReturnModel.MessageContent = "操作失败:登录名不能为空.";
            //    return Json(sReturnModel);
            //}
            //if (Role == Guid.Empty)
            //{
            //    sReturnModel.ErrorType = 0;
            //    sReturnModel.MessageContent = "操作失败:角色不能为空.";
            //    return Json(sReturnModel);
            //}
            //if (id < 1 && Password.Length < 1)
            //{
            //    sReturnModel.ErrorType = 0;
            //    sReturnModel.MessageContent = "操作失败:密码不能为空.";
            //    return Json(sReturnModel);
            //}
            #endregion

            var             cBll = new BLL_ComputerRoom();
            td_ComputerRoom model;
            if (id > 0)
            {
                model = cBll.GetObjectById(id);
                if (model == null)
                {
                    sReturnModel.ErrorType      = 0;
                    sReturnModel.MessageContent = "操作失败.";
                    return(Json(sReturnModel));
                }
            }

            model            = new td_ComputerRoom();
            model.ID         = id;
            model.OperatPid  = currentUser.user_Id;
            model.OperatTime = DateTime.Now;

            model.Dept_Id = DeptId;

            model.jg     = jg;
            model.kt     = kt;
            model.sxt    = sxt;
            model.mhq    = mhq;
            model.UPS    = UPS;
            model.fhm    = fhm;
            model.fhdb   = fhdb;
            model.qtmhzz = qtmhzz;
            model.fljsb  = fljsb;
            model.fjdsb  = fjdsb;
            model.fdcgr  = fdcgr;
            model.fcsb   = fcsb;
            model.fwq    = fwq;

            if (cBll.AddOrUpdate(model))
            {
                sReturnModel.ErrorType      = 1;
                sReturnModel.MessageContent = "操作成功.";
            }
            else
            {
                sReturnModel.ErrorType      = 0;
                sReturnModel.MessageContent = "操作失败.";
            }
            return(Json(sReturnModel));
        }