public async Task AddITemToCatalogAsync(CatalogItemDto catalogItem) { var itemToAdd = _mapper.Map <CatalogItem>(catalogItem); var result = _catalogContext.CatalogItems.Add(itemToAdd); await _catalogContext.SaveChangesAsync(new CancellationToken()); return; }
public async Task <Result> Handle(DeleteCatalogItemCommand request, CancellationToken cancellationToken) { var itemToBeDeleted = await _catalogContext.CatalogItems.FindAsync(request.Id); Throw.Exception.IfEntityNotFound(request.Id, itemToBeDeleted, "Catalog Item"); _catalogContext.CatalogItems.Remove(itemToBeDeleted); await _catalogContext.SaveChangesAsync(cancellationToken); return(Result.EntityDeleted(itemToBeDeleted.Id, "Catalog Item")); }
public async Task <Result> Handle(UpdateCatalogItemCommand request, CancellationToken cancellationToken) { var item = await _catalogContext.CatalogItems.FindAsync(request.Id); Throw.Exception.IfEntityNotFound(request.Id, item, "Catalog Item"); _catalogContext.Entry(item).CurrentValues.SetValues(request); await _catalogContext.SaveChangesAsync(cancellationToken); return(Result.EntityUpdated(item.Id, "Catalog Item")); }
public async Task <Result <string> > Handle(CreateCatalogItemCommand request, CancellationToken cancellationToken) { var item = new CatalogItem( request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri); _catalogContext.CatalogItems.Add(item); await _catalogContext.SaveChangesAsync(cancellationToken); return(Result <string> .Success($"Catalog Item with Id {item.Id} Created.")); }