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)); } }
public async Task Add(PostCategoryRecord record) { if (await _routeService.ExistByPath(record.Route.Path)) { throw new ValidationException($"路由路径 '{record.Route.Path}' 已经存在!"); } _repository.Value.Create(record); }
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); }