Exemple #1
0
        public JsonResult AddPostion(string postName)
        {
            postName = postName.Trim();

            if (string.IsNullOrEmpty(postName))
            {
                return(Json(ErrorModel.InputError));
            }

            var posts = new Posts
            {
                PostName = postName
            };

            var postBll   = new PostsBll();
            var condition = string.Format("IsDelete=0 AND PostName='{0}'", postName);

            if (postBll.Exists(condition))
            {
                return(Json(ErrorModel.ExistSameItem));
            }

            postBll.Insert(posts);

            if (posts.Id > 0)
            {
                DataUpdateLog.SingleUpdate(typeof(Posts).Name, posts.Id, DataUpdateType.Insert);

                return(Json(ErrorModel.OperateSuccess));
            }

            return(Json(ErrorModel.OperateFailed));
        }
Exemple #2
0
        public JsonResult AddOrUpdatePost(Posts model)
        {
            if (model != null)
            {
                var bll = new PostsBll();
                if (bll.Exists($"PostName='{model.PostName}' AND IsDelete=0"))
                {
                    return(Json(ErrorModel.ExistSameItem));
                }

                var isUpdate   = model.Id > 0;
                var updateType = isUpdate ? DataUpdateType.Update : DataUpdateType.Insert;
                var success    = bll.ExecuteTransation(
                    () => isUpdate ? bll.Update(model) : bll.Insert(model).Id > 0,
                    () => DataUpdateLog.SingleUpdate(nameof(Posts), model.Id, updateType)
                    );

                return(Json(success ? ErrorModel.OperateSuccess : ErrorModel.OperateFailed));
            }

            return(Json(ErrorModel.InputError));
        }