Ejemplo n.º 1
0
        public JsonResult AddDepart()
        {
            var departJson = Request["depart"];
            var depart     = JsonHelper.Deserialize <DepartInfo>(departJson);

            var departBll = new DepartInfoBll();
            var success   = departBll.Insert(depart).Id > 0;

            if (success)
            {
                DataUpdateLog.SingleUpdate(typeof(DepartInfo).Name, depart.Id, DataUpdateType.Insert);

                return(Json(ErrorModel.AddDataSuccess(depart.Id)));
            }

            return(Json(ErrorModel.OperateFailed));
        }
Ejemplo n.º 2
0
        public JsonResult AddDirectory(string directory)
        {
            var model = JsonHelper.Deserialize <TraficFileType>(directory);

            if (model == null)
            {
                return(Json(ErrorModel.InputError));
            }

            var dirBll = new TraficFileTypeBll();
            // 验证目录是否重名
            var condition = $"ParentId={model.ParentId} AND TypeName='{model.TypeName}' AND IsDelete=0";

            if (dirBll.Exists(condition))
            {
                return(Json(ErrorModel.DirectoryExists));
            }

            // 准备数据库操作事务
            var         updateType    = model.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert;
            var         log           = $"添加了目录[{model.TypeName}]";
            Func <bool> doAddOrUpdate = () => dirBll.Insert(model).Id > 0;

            if (model.Id > 0)
            {
                var viewDirBll    = new ViewTraficFileTypeBll();
                var origin        = viewDirBll.QuerySingle(model.Id);
                var newDepartName = new DepartInfoBll().QuerySingle(model.DepartmentId, new[] { nameof(DepartInfo.DepartmentName) }).DepartmentName;
                log           = $"将目录由[{origin.TypeName}-{origin.DepartmentName}-{(origin.IsPublic ? "公共文件夹" : "私有文件夹")}]更新为[{model.TypeName}-{newDepartName}-{(model.IsPublic ? "公共文件夹" : "私有文件夹")}]";
                doAddOrUpdate = () => dirBll.Update(model);
            }

            // 执行事务
            var loginUser = LoginStatus.GetLoginId();
            var logBll    = new OperateLogBll();
            var success   = dirBll.ExecuteTransation(
                doAddOrUpdate,
                () => DataUpdateLog.SingleUpdate(nameof(TraficFileType), model.Id, updateType),
                () => logBll.Add(nameof(TraficFileType), model.Id, updateType, loginUser, log)
                );

            return(Json(success ? ErrorModel.AddDataSuccess(model.Id) : ErrorModel.OperateFailed));
        }