Example #1
0
        public async Task <IActionResult> ActItemDetail(int planId, int id, ActItem model)
        {
            var identity = User;

            var now    = DateTime.Now;
            var result = new Result();

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

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

                var status = await TryUpdateModelAsync(old);

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

            model.SellerId   = identity.Id;
            model.SellerName = identity.Name;
            model.CreatedOn  = now;
            model.ModifiedBy = identity.Name;
            model.ModifiedOn = now;
            var newId = DefaultStorage.ActItemCreate(model);

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

            return(Json(result));
        }