public async Task SeedCategories(CancellationToken cancellationToken) { if (!_context.Categories.Any()) { var categories = new Category[] { new Category() { Id = Guid.NewGuid(), Name = "Hats", Description = null, ImageUrl = null }, new Category() { Id = Guid.NewGuid(), Name = "Jackets", Description = null, ImageUrl = null }, new Category() { Id = Guid.NewGuid(), Name = "Trousers", Description = null, ImageUrl = null }, new Category() { Id = Guid.NewGuid(), Name = "TShirt", Description = null, ImageUrl = null }, new Category() { Id = Guid.NewGuid(), Name = "Shoes", Description = null, ImageUrl = null } }; _context.Categories.AddRange(categories); await _context.SaveChangesAsync(cancellationToken); } }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var product = new Item { }; try { _context.Items.Add(product); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); } catch (Exception ex) { throw new CreateFailureException(nameof(Item), product.Id, ex.Message); } }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var product = await _context.Items.FindAsync(request.Id); if (product == null) { throw new NotFoundException(nameof(product), product.Id); } try { await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); } catch (Exception ex) { throw new UpdateFailureException(nameof(product), product.Id, ex.Message); } }