public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var pageItemCategory = new PageItemCategory { Id = request.Id, ParentId = request.ParentId, Name = request.Name, Description = request.Description }; _context.PageItemCategorys.Add(pageItemCategory); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving changes"); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { if (await _context.Pages.Where(x => x.URLTitle == request.URLTitle).AnyAsync()) { throw new RestException(HttpStatusCode.BadRequest, new { Email = "URLTitle already exists" }); } PageItemCategory category = await _context.PageItemCategorys.FindAsync(request.CategoryId); if (category == null) { throw new Exception("Could not find category"); } var page = new Page { //Id = request.Id, Title = request.Title, Description = request.Description, //CategoryId = request.CategoryId, URLTitle = request.URLTitle, PageHtml = request.PageHtml, Category = category }; _context.Pages.Add(page); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving changes"); }