Example #1
0
 public ActionResult Form(Sys_Organize model)
 {
     if (model.Id == null)
     {
         var primaryKey = _organizeService.Insert(model);
         return(primaryKey != null?Success() : Error());
     }
     else
     {
         int row = _organizeService.Update(model);
         return(row > 0 ? Success() : Error());
     }
 }
Example #2
0
        public ActionResult Create(OrganizeDto model)
        {
            var resultModel = new RespResultCountViewModel();

            try
            {
                #region 验证
                if (string.IsNullOrEmpty(model.OrgName))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "机构名称不允许为空!";
                    return(Ok(resultModel));
                }
                if (string.IsNullOrEmpty(model.OrgCode))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "机构代码不允许为空!";
                    return(Ok(resultModel));
                }
                if (_organizeService.ExistFullName(model.OrgName, model.OrganizeId))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "已存在相同机构名称!";
                    return(Ok(resultModel));
                }
                if (_organizeService.ExistEnCode(model.OrgCode, model.OrganizeId))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "已存在相同机构代码!";
                    return(Ok(resultModel));
                }
                #endregion

                if (model.ParentId == null)
                {
                    model.ParentId = "0";
                }
                OrganizeEntity organizeEntity = _mapper.Map <OrganizeEntity>(model);
                organizeEntity.OrgBrevityCode = CommonHelper.GetPinyinCode(organizeEntity.OrgName);
                organizeEntity.OrganizeId     = ConstDefine.CreateGuid();
                organizeEntity.CreateDate     = DateTime.Now;
                organizeEntity.CreateUserId   = User.GetCurrentUserId();
                organizeEntity.CreateUserName = User.GetCurrentUserName();
                organizeEntity.DeleteMark     = 1;//删除标记,原来为0
                bool result = _organizeService.Insert(organizeEntity);
                if (result)
                {
                    resultModel.code = 0;
                    resultModel.msg  = "新增成功";
                }
                else
                {
                    resultModel.code = -1;
                    resultModel.msg  = "新增失败";
                }
                return(Ok(resultModel));
            }
            catch (Exception ex)
            {
                resultModel.code = -1;
                resultModel.msg  = "操作失败:" + ex.Message;
                return(Ok(resultModel));
            }
        }