/// <summary>
        /// 删除
        /// </summary>
        /// <param name="DataType">字典分类</param>
        /// <param name="ItemId">字典Id</param>
        /// <param name="UserId">登陆用户ID</param>
        /// <param name="UserName">登陆用户名称</param>
        /// <returns></returns>
        public bool Delete(string DataType, string ItemId, string UserId, string UserName)
        {
            var dataDictEntity = new DataDictEntity();

            dataDictEntity.DeleteMark     = 0;
            dataDictEntity.ModifyUserId   = UserId;
            dataDictEntity.ModifyUserName = UserName;
            dataDictEntity.ModifyDate     = DateTime.Now;
            using (var db = _dbContext.GetIntance())
            {
                try
                {
                    db.Ado.BeginTran();
                    //逻辑删除
                    db.Updateable(dataDictEntity).UpdateColumns(it => new { it.DeleteMark, it.ModifyDate, it.ModifyUserId, it.ModifyUserName })
                    .Where(it => it.DataType == DataType && it.ItemCode == ItemId)
                    .ExecuteCommand();
                    if (DataType == "type")
                    {
                        db.Updateable(dataDictEntity).UpdateColumns(it => new { it.DeleteMark, it.ModifyDate, it.ModifyUserId, it.ModifyUserName })
                        .Where(it => it.DataType == ItemId)
                        .ExecuteCommand();
                    }
                    db.Ado.CommitTran();
                }
                catch (Exception)
                {
                    db.Ado.RollbackTran();
                    return(false);
                }
                return(true);
            }
        }
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="dataDictEntity">字典实体</param>
 /// <returns></returns>
 public bool Insert(DataDictEntity dataDictEntity)
 {
     using (var db = _dbContext.GetIntance())
     {
         var count = db.Insertable(dataDictEntity).ExecuteCommand();
         result = count > 0 ? true : false;
     }
     return(result);
 }
示例#3
0
        public async Task <TData <string> > SaveForm(DataDictEntity entity)
        {
            var obj = new TData <string>();
            await _dataDictService.SaveForm(entity);

            obj.Data = entity.Id.ParseToString();
            obj.Tag  = 1;
            return(obj);
        }
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="dataDictEntity">字典实体</param>
 /// <returns></returns>
 public bool Update(DataDictEntity dataDictEntity)
 {
     using (var db = _dbContext.GetIntance())
     {
         var count = db.Updateable(dataDictEntity)
                     .IgnoreColumns(it => new { it.CreateDate, it.CreateUserId, it.CreateUserName, it.DeleteMark, it.OrgId })
                     .Where(it => it.CRowId == dataDictEntity.CRowId)
                     .ExecuteCommand();
         result = count > 0 ? true : false;
     }
     return(result);
 }
示例#5
0
 public async Task SaveForm(DataDictEntity entity)
 {
     if (entity.Id.IsNullOrZero())
     {
         // 默认赋值
         entity.Id = IdGeneratorHelper.Instance.GetId();
         await _dataDictEntityDB.InsertNowAsync(entity);
     }
     else
     {
         await _dataDictEntityDB.UpdateNowAsync(entity, ignoreNullValues : true);
     }
 }
示例#6
0
        public bool ExistDictType(DataDictEntity entity)
        {
            var expression = LinqExtensions.True <DataDictEntity>();

            expression = expression.And(t => t.BaseIsDelete == 0);
            if (entity.Id.IsNullOrZero())
            {
                expression = expression.And(t => t.DictType == entity.DictType);
            }
            else
            {
                expression = expression.And(t => t.DictType == entity.DictType && t.Id != entity.Id);
            }
            return(this.BaseRepository().IQueryable(expression).Count() > 0 ? true : false);
        }
示例#7
0
        public async Task SaveForm(DataDictEntity entity)
        {
            if (entity.Id.IsNullOrZero())
            {
                await entity.Create();

                await this.BaseRepository().Insert <DataDictEntity>(entity);
            }
            else
            {
                await entity.Modify();

                await this.BaseRepository().Update <DataDictEntity>(entity);
            }
        }
示例#8
0
        public async Task <TData <string> > SaveForm(DataDictEntity entity)
        {
            TData <string> obj = new TData <string>();

            if (dataDictService.ExistDictType(entity))
            {
                obj.Message = "字典类型已经存在!";
                return(obj);
            }

            await dataDictService.SaveForm(entity);

            obj.Result = entity.Id.ParseToString();
            obj.Tag    = 1;
            return(obj);
        }
示例#9
0
        public async Task <TData> DeleteForm(string ids)
        {
            TData obj = new TData();

            foreach (long id in CommonHelper.SplitToArray <long>(ids, ','))
            {
                DataDictEntity dbEntity = await dataDictService.GetEntity(id);

                if (dataDictService.ExistDictDetail(dbEntity.DictType))
                {
                    obj.Message = "请先删除字典值!";
                    return(obj);
                }
            }
            await dataDictService.DeleteForm(ids);

            obj.Tag = 1;
            return(obj);
        }
示例#10
0
        public async Task SaveForm(DataDictEntity entity)
        {
            var db = await this.BaseRepository().BeginTrans();

            try
            {
                if (!entity.Id.IsNullOrZero())
                {
                    var dbEntity = await db.FindEntity <DataDictEntity>(entity.Id.Value);

                    if (dbEntity.DictType != entity.DictType)
                    {
                        // 更新子表的DictType,因为2个表用DictType进行关联
                        IEnumerable <DataDictDetailEntity> detailList = await db.FindList <DataDictDetailEntity>(p => p.DictType == dbEntity.DictType);

                        foreach (DataDictDetailEntity detailEntity in detailList)
                        {
                            detailEntity.DictType = entity.DictType;
                            await detailEntity.Modify();
                        }
                    }
                    dbEntity.DictType = entity.DictType;
                    dbEntity.Remark   = entity.Remark;
                    dbEntity.DictSort = entity.DictSort;
                    await dbEntity.Modify();

                    await db.Update <DataDictEntity>(dbEntity);
                }
                else
                {
                    await entity.Create();

                    await db.Insert <DataDictEntity>(entity);
                }
                await db.CommitTrans();
            }
            catch
            {
                await db.RollbackTrans();

                throw;
            }
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="DataType">字典分类</param>
        /// <param name="ItemId">字典Id</param>
        /// <param name="UserId">登陆用户ID</param>
        /// <param name="UserName">登陆用户名称</param>
        /// <returns></returns>
        public bool DeleteBatch(List <string> DataType, List <string> ItemId, string UserId, string UserName)
        {
            bool result = false;

            if (DataType.Count() > 0 || ItemId.Count() > 0)
            {
                using (var db = _dbContext.GetIntance())
                {
                    var dataDictEntity = new DataDictEntity();
                    dataDictEntity.DeleteMark     = 0;
                    dataDictEntity.ModifyUserId   = UserId;
                    dataDictEntity.ModifyUserName = UserName;
                    dataDictEntity.ModifyDate     = DateTime.Now;
                    var counts = 0;
                    for (int i = 0; i < DataType.Count(); i++)
                    {
                        //逻辑删除
                        counts += db.Updateable(dataDictEntity).UpdateColumns(it => new { it.DeleteMark, it.ModifyDate, it.ModifyUserId, it.ModifyUserName })
                                  .Where(it => it.DataType == DataType[i] && it.ItemCode == ItemId[i]).ExecuteCommand();
                        if (DataType[i] == "type")
                        {
                            db.Updateable(dataDictEntity).UpdateColumns(it => new { it.DeleteMark, it.ModifyDate, it.ModifyUserId, it.ModifyUserName })
                            .Where(it => it.DataType == ItemId[i])
                            .ExecuteCommand();
                        }
                        //物理删除
                        //counts += db.Deleteable<DataDictEntity>().Where(it => it.DataType == DataType[i] && it.ItemCode == ItemId[i]).ExecuteCommand();
                    }
                    result = counts > 0 ? result = true : false;
                }
            }
            else
            {
                result = false;
            }
            return(result);
        }
示例#12
0
        public async Task <IActionResult> SaveFormJson(DataDictEntity entity)
        {
            TData <string> obj = await dataDictBLL.SaveForm(entity);

            return(Json(obj));
        }
示例#13
0
        public ActionResult Edit(DataDictDto model)
        {
            var resultModel = new RespResultCountViewModel();

            try
            {
                #region 验证
                if (string.IsNullOrEmpty(model.DataType) && string.IsNullOrEmpty(model.ItemCode))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "修改失败!原因:字典分类ID或字典ID是空";
                    return(Ok(resultModel));
                }
                if (string.IsNullOrEmpty(model.ItemName))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "名称不允许为空";
                    return(Ok(resultModel));
                }
                if (string.IsNullOrEmpty(model.ItemCode))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "编码不允许为空";
                    return(Ok(resultModel));
                }
                if (string.IsNullOrEmpty(model.CRowId))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "主键不允许为空";
                    return(Ok(resultModel));
                }
                if (_dataDictService.ExistFullName(model.DataType, model.ItemName, model.CRowId, User.GetCurrentUserOrganizeId()))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "已存在相同名称!";
                    return(Ok(resultModel));
                }
                if (_dataDictService.ExistEnCode(model.DataType, model.ItemCode, model.CRowId, User.GetCurrentUserOrganizeId()))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "已存在相同编号!";
                    return(Ok(resultModel));
                }
                #endregion

                DataDictEntity dataDictEntity = _mapper.Map <DataDictEntity>(model);
                dataDictEntity.ItemName       = model.ItemName;
                dataDictEntity.ModifyDate     = DateTime.Now;
                dataDictEntity.ModifyUserId   = User.GetCurrentUserId();
                dataDictEntity.ModifyUserName = User.GetCurrentUserName();

                bool result = _dataDictService.Update(dataDictEntity);
                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));
            }
        }
示例#14
0
        public ActionResult Create(DataDictDto model)
        {
            RespResultViewModel resultModel = new RespResultCountViewModel();

            try
            {
                #region 验证
                if (string.IsNullOrEmpty(model.ItemName))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "名称不允许为空";
                    return(Ok(resultModel));
                }
                if (string.IsNullOrEmpty(model.ItemCode))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "编码不允许为空";
                    return(Ok(resultModel));
                }

                if (_dataDictService.ExistFullName(model.DataType, model.ItemName, model.CRowId, User.GetCurrentUserOrganizeId()))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "已存在相同名称!";
                    return(Ok(resultModel));
                }
                if (_dataDictService.ExistEnCode(model.DataType, model.ItemCode, model.CRowId, User.GetCurrentUserOrganizeId()))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "已存在相同编号!";
                    return(Ok(resultModel));
                }
                #endregion

                DataDictEntity dataDictEntity = _mapper.Map <DataDictEntity>(model);
                dataDictEntity.ItemName       = model.ItemName;
                dataDictEntity.CRowId         = ConstDefine.CreateGuid();
                dataDictEntity.CreateUserId   = User.GetCurrentUserId();
                dataDictEntity.CreateUserName = User.GetCurrentUserName();
                dataDictEntity.CreateDate     = DateTime.Now;
                dataDictEntity.DeleteMark     = 1;
                dataDictEntity.ModifyDate     = System.DateTime.Now;
                dataDictEntity.ModifyUserId   = "";
                dataDictEntity.ModifyUserName = "";
                dataDictEntity.OrgId          = User.GetCurrentUserOrganizeId();

                bool result = _dataDictService.Insert(dataDictEntity);
                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.ToString();
                return(Ok(resultModel));
            }
        }
示例#15
0
        public async Task <TData <string> > SaveFormJson([FromForm] DataDictEntity entity)
        {
            var obj = await _dataDictBLL.SaveForm(entity);

            return(obj);
        }