Exemplo n.º 1
0
        public ActionResult Save(int?deptid, int?pdeptId)
        {
            var obj = new SysDepartments()
            {
                PDeptId = pdeptId.GetValueOrDefault(), Status = true
            };

            if (deptid.HasValue)
            {
                obj = DeptService.Get(deptid.Value);
            }
            ViewBag.ParentDepth = 0;
            if (pdeptId.HasValue)
            {
                var pm = DeptService.Get(pdeptId.Value);
                if (pm != null)
                {
                    ViewBag.Parent      = pm.Title;
                    ViewBag.ParentDepth = pm.Depth;
                }
            }
            ViewBag.users = ListToSelect(UserService.GetList().Select(o => new SelectListItem()
            {
                Text = o.FullName, Value = o.UserId
            }), emptyTitle: "请选择");
            return(View(obj.IsNullThrow()));
        }
Exemplo n.º 2
0
        public SysDepartments GetModelByDepId(int depId)
        {
            SysDepartments model = null;
            var            datas = _dal.GetListByDepId(depId);

            if (datas != null && datas.Count > 0)
            {
                model = datas[0];
            }
            return(model);
        }
        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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 保存组织机构
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public OpResult SaveDep(SysDepartments model)
        {
            var result = OpResult.Fail("数据保存失败");

            try
            {
                model.CompanyId = SysCommonRules.CompanyId;
                if (_dal.ExistsById(model.Id))
                {
                    if (_dal.ExistsColumn(model.Id, "Id", model.SN, "SN", SysCommonRules.CompanyId))
                    {
                        result = OpResult.Fail("代码已存在,不可重复");
                    }
                    else
                    {
                        var re = _dal.Update(model);
                        if (re)
                        {
                            result = OpResult.Success("数据保存成功");
                        }
                    }
                }
                else
                {
                    if (_dal.ExistsColumn(0, "Id", model.SN, "SN", SysCommonRules.CompanyId))
                    {
                        result = OpResult.Fail("代码已存在,不可重复");
                    }
                    else
                    {
                        var maxDepId = _dal.MaxVal("DepId", SysCommonRules.CompanyId);
                        model.DepId = maxDepId + 1;
                        var re = _dal.Insert(model);
                        if (re > 0)
                        {
                            result = OpResult.Success("数据保存成功");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result = OpResult.Fail("数据保存失败!" + ex.Message);
            }
            return(result);
        }
Exemplo n.º 5
0
        ///// <summary>首次连接数据库时初始化数据,仅用于实体类重载,用户不应该调用该方法</summary>
        //[EditorBrowsable(EditorBrowsableState.Never)]
        //protected override void InitData()
        //{
        //    base.InitData();

        //    // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用
        //    // Meta.Count是快速取得表记录数
        //    if (Meta.Count > 0) return;

        //    // 需要注意的是,如果该方法调用了其它实体类的首次数据库操作,目标实体类的数据初始化将会在同一个线程完成
        //    if (XTrace.Debug) XTrace.WriteLine("开始初始化{0}[{1}]数据……", typeof(SysArea).Name, Meta.Table.DataTable.DisplayName);

        //    var entity = new SysArea();
        //    entity.Serialnum = "abc";
        //    entity.CreateTime = DateTime.Now;
        //    entity.CreateSysUserSerialnum = "abc";
        //    entity.UpdateTime = DateTime.Now;
        //    entity.UpdateSysUserSerialnum = "abc";
        //    entity.Name = "abc";
        //    entity.ParentSerialnum = "abc";
        //    entity.AwCode = "abc";
        //    entity.Status = 0;
        //    entity.Description = "abc";
        //    entity.Sort = 0;
        //    entity.Remark = "abc";
        //    entity.Insert();

        //    if (XTrace.Debug) XTrace.WriteLine("完成初始化{0}[{1}]数据!", typeof(SysArea).Name, Meta.Table.DataTable.DisplayName);
        //}

        /// <summary>已重载。删除关联数据</summary>
        /// <returns></returns>
        protected override int OnDelete()
        {
            if (AgrProduceAnniversaryServices != null)
            {
                AgrProduceAnniversaryServices.Delete();
            }
            if (AgrProduceConditions != null)
            {
                AgrProduceConditions.Delete();
            }
            if (SysDepartments != null)
            {
                SysDepartments.Delete();
            }

            return(base.OnDelete());
        }
Exemplo n.º 6
0
        public ActionResult OrgSave(SysDepartments model)
        {
            var result = _departmentRepository.SaveDep(model);

            return(this.ToJsonOperateResult(result));
        }
Exemplo n.º 7
0
        public ActionResult Save(SysDepartments obj, short parentDepth)
        {
            var re = DeptService.SaveOrUpdate(obj, parentDepth);

            return(new OpActionResult(re));
        }