コード例 #1
0
        public async Task <object> PutAsync(SysDepartments entity)
        {
            var json = new ResJson()
            {
                success = false
            };

            try
            {
                bool IsSave = string.IsNullOrEmpty(entity.GUID);

                if (IsSave)
                {
                    if (await sysDepartmentService.IsAnyAsync(p => p.DepartmentName == entity.DepartmentName))
                    {
                        json.message = "部门名称已存在";
                        return(json);
                    }

                    // Add 初始参数
                    entity.CreateUser = AdminUser.User.Account;
                    entity.CreateDate = DateTime.Now;
                    entity.GUID       = Guid.NewGuid().ToString();
                }

                // Add、Update 默认参数
                entity.UpdateUser = AdminUser.User.Account;
                entity.UpdateDate = DateTime.Now;

                //保存模块
                if (await sysDepartmentService.SaveOrUpdateAsync(entity, IsSave))
                {
                    json.message = "操作成功!";
                    json.success = true;
                }
                else
                {
                    json.message = "操作失败!";
                }
            }
            catch (Exception ex)
            {
                json.message = "网络超时.";
                throw ex;
            }

            return(json);
        }