コード例 #1
0
ファイル: PostController.cs プロジェクト: sigeshitou/wkmvc
        public ActionResult Save(Domain.SYS_POST entity)
        {
            bool isEdit = false;
            var  json   = new JsonHelper()
            {
                Msg = "保存岗位成功", Status = "n", ReUrl = "/Post/Index"
            };

            try
            {
                if (entity != null)
                {
                    //添加
                    if (string.IsNullOrEmpty(entity.ID))
                    {
                        entity.ID         = Guid.NewGuid().ToString();
                        entity.CREATEDATE = DateTime.Now;
                        entity.CREATEUSER = CurrentUser.Name;
                        entity.UPDATEDATE = DateTime.Now;
                        entity.UPDATEUSER = this.CurrentUser.Name;
                    }
                    else //修改
                    {
                        entity.UPDATEDATE = DateTime.Now;
                        entity.UPDATEUSER = this.CurrentUser.Name;
                        isEdit            = true;
                    }
                    //判断岗位是否重名
                    if (!this.PostManage.IsExist(p => p.POSTNAME == entity.POSTNAME && p.ID != entity.ID))
                    {
                        if (PostManage.SaveOrUpdate(entity, isEdit))
                        {
                            json.Status = "y";
                        }
                        else
                        {
                            json.Msg = "保存失败";
                        }
                    }
                    else
                    {
                        json.Msg = "岗位" + entity.POSTNAME + "已存在,不能重复添加";
                    }
                }
                else
                {
                    json.Msg = "未找到需要保存的岗位";
                }
                if (isEdit)
                {
                    WriteLog(Common.Enums.enumOperator.Edit, "修改岗位,结果:" + json.Msg, Common.Enums.enumLog4net.INFO);
                }
                else
                {
                    WriteLog(Common.Enums.enumOperator.Add, "添加岗位,结果:" + json.Msg, Common.Enums.enumLog4net.INFO);
                }
            }
            catch (Exception e)
            {
                json.Msg = "保存岗位发生内部错误!";
                WriteLog(Common.Enums.enumOperator.None, "保存岗位:", e);
            }
            return(Json(json));
        }