コード例 #1
0
        public async Task <ActionResult> AddOrEdit(CategoryEditViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(this.Error("数据非法!"));
                }

                var record = await _categoryService.Get(model.Id);

                var isAdd = record == null;

                if (record == null)
                {
                    record = PostCategoryRecord.Create(model.Id);
                }

                model.UpdateRecord(record);

                if (isAdd)
                {
                    await _categoryService.Add(record);
                }

                return(this.Success());
            }
            catch (ValidationException validationException)
            {
                return(this.Error(validationException.Message));
            }
        }
コード例 #2
0
        public async Task Add(PostCategoryRecord record)
        {
            if (await _routeService.ExistByPath(record.Route.Path))
            {
                throw new ValidationException($"路由路径 '{record.Route.Path}' 已经存在!");
            }

            _repository.Value.Create(record);
        }
コード例 #3
0
        public PostCategoryRecord UpdateRecord(PostCategoryRecord record)
        {
            record.Title       = Title;
            record.Visible     = Visible;
            record.Description = Description;
            record.Seo         = Seo;
            if (record.Route == null)
            {
                record.Route = RouteRecord.Create();
            }
            record.Route.Path = RoutePath;

            return(record);
        }