Exemple #1
0
        public async Task <IActionResult> ArticleDetail(int id, Article model)
        {
            var now = DateTime.Now;

            var result = new Result();

            if (model.Name.IsNullOrEmpty())
            {
                result.Error("请输入名称");
                return(Json(result));
            }

            if (id > 0)
            {
                var old = DefaultStorage.ArticleGet(id);
                if (old == null)
                {
                    result.Message = "数据不存在";
                    return(Json(result));
                }

                var status = await TryUpdateModelAsync(old);

                if (status)
                {
                    result.Status = DefaultStorage.ArticleUpdate(old);
                    if (!result.Status)
                    {
                        result.Message = "更新失败";
                    }
                }
                else
                {
                    result.Message = "参数有误";
                }
                return(Json(result));
            }

            model.Extra      = string.Empty;
            model.UserId     = User.Id;
            model.CreatedBy  = User.Name;
            model.CreatedOn  = now;
            model.ModifiedBy = User.Name;
            model.ModifiedOn = now;

            var newId = DefaultStorage.ArticleCreate(model);

            if (result.Status = newId > 0)
            {
                result.Success();
            }

            return(Json(result));
        }