コード例 #1
0
 public bool AddOrUpdate(td_GenuineSoftware 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 IPdz    = RequestParameters.Pstring("IPdz");
            string Dept_Id = RequestParameters.Pstring("Dept_Id");
            string czxtlx  = RequestParameters.Pstring("czxtlx");
            string bgrjlx  = RequestParameters.Pstring("bgrjlx");
            string yt      = RequestParameters.Pstring("yt");

            if (IPdz.Length < 1)
            {
                sReturnModel.ErrorType      = 0;
                sReturnModel.MessageContent = "操作失败:IP地址不能为空.";
                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_GenuineSoftware();
            td_GenuineSoftware model;
            if (id > 0)
            {
                model = cBll.GetObjectById(id);
                if (model == null)
                {
                    sReturnModel.ErrorType      = 0;
                    sReturnModel.MessageContent = "操作失败.";
                    return(Json(sReturnModel));
                }
            }

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

            model.IPdz   = IPdz;
            model.czxtlx = czxtlx;
            model.bgrjlx = bgrjlx;
            model.yt     = yt;

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