public async Task <IActionResult> GetItemCategorySearchResults([FromRoute(Name = "searchInput")] string searchInput) { searchInput = searchInput.Trim(); if (string.IsNullOrEmpty(searchInput)) { return(BadRequest("Search input mustn't be null or empty")); } var query = new ItemCategorySearchQuery(searchInput); var itemCategoryReadModels = await queryDispatcher.DispatchAsync(query, default); var itemCategoryContracts = itemCategoryContractConverter.ToContract(itemCategoryReadModels); return(Ok(itemCategoryContracts)); }
public StoreItemContract ToContract(StoreItemReadModel source) { if (source is null) { throw new ArgumentNullException(nameof(source)); } ItemCategoryContract itemCategoryContract = null; if (source.ItemCategory != null) { itemCategoryContract = itemCategoryContractConverter.ToContract(source.ItemCategory); } ManufacturerContract manufacturerContract = null; if (source.Manufacturer != null) { manufacturerContract = manufacturerContractConverter.ToContract(source.Manufacturer); } return(new StoreItemContract( source.Id.Value, source.Name, source.IsDeleted, source.Comment, source.IsTemporary, quantityTypeContractConverter.ToContract(source.QuantityType), source.QuantityInPacket, quantityTypeInPacketContractConverter.ToContract(source.QuantityTypeInPacket), itemCategoryContract, manufacturerContract, storeItemAvailabilityContractConverter.ToContract(source.Availabilities))); }
public ShoppingListContract ToContract(ShoppingListReadModel source) { return(new ShoppingListContract( source.Id.Value, shoppingListStoreContractConverter.ToContract(source.Store), shoppingListSectionContractConverter.ToContract(source.Sections), source.CompletionDate)); }
public async Task <IActionResult> GetAllQuantityTypesInPacket() { var query = new AllQuantityTypesInPacketQuery(); var readModels = await queryDispatcher.DispatchAsync(query, default); var contracts = quantityTypeInPacketToContractConverter.ToContract(readModels); return(Ok(contracts)); }
public async Task <IActionResult> GetAllActiveStores() { var query = new AllActiveStoresQuery(); var storeReadModels = await queryDispatcher.DispatchAsync(query, default); var storeContracts = activeStoreToContractConverter.ToContract(storeReadModels); return(Ok(storeContracts)); }
public StoreItemAvailabilityContract ToContract(StoreItemAvailabilityReadModel source) { if (source is null) { throw new ArgumentNullException(nameof(source)); } return(new StoreItemAvailabilityContract( storeItemStoreContractConverter.ToContract(source.Store), source.Price, storeSectionContractConverter.ToContract(source.DefaultSection))); }
public StoreItemStoreContract ToContract(StoreItemStoreReadModel source) { if (source is null) { throw new System.ArgumentNullException(nameof(source)); } return(new StoreItemStoreContract( source.Id.Value, source.Name, storeSectionContractConverter.ToContract(source.Sections))); }
public ShoppingListSectionContract ToContract(ShoppingListSectionReadModel source) { if (source is null) { throw new System.ArgumentNullException(nameof(source)); } return(new ShoppingListSectionContract( source.Id.Value, source.Name, source.SortingIndex, source.IsDefaultSection, shoppingListItemContractConverter.ToContract(source.ItemReadModels))); }
public async Task <IActionResult> GetItemFilterResults([FromQuery] IEnumerable <int> storeIds, [FromQuery] IEnumerable <int> itemCategoryIds, [FromQuery] IEnumerable <int> manufacturerIds) { var query = new ItemFilterResultsQuery( storeIds.Select(id => new StoreId(id)), itemCategoryIds.Select(id => new ItemCategoryId(id)), manufacturerIds.Select(id => new ManufacturerId(id))); var readModels = await queryDispatcher.DispatchAsync(query, default); var contracts = itemFilterResultContractConverter.ToContract(readModels); return(Ok(contracts)); }
public ItemSearchContract ToContract(ItemSearchReadModel source) { if (source is null) { throw new ArgumentNullException(nameof(source)); } return(new ItemSearchContract( source.Id.Value, source.Name, source.DefaultQuantity, source.Price, source.ItemCategory.Name, source.Manufacturer?.Name ?? "", storeItemSectionContractConverter.ToContract(source.DefaultSection))); }
public async Task <IActionResult> GetActiveShoppingListByStoreId([FromRoute(Name = "storeId")] int storeId) { var query = new ActiveShoppingListByStoreIdQuery(new StoreId(storeId)); ShoppingListReadModel readModel; try { readModel = await queryDispatcher.DispatchAsync(query, default); } catch (ArgumentException e) { return(BadRequest(e.Message)); } var contract = shoppingListToContractConverter.ToContract(readModel); return(Ok(contract)); }
public async Task <IActionResult> Get([FromRoute(Name = "itemId")] int itemId) { var query = new ItemByIdQuery(new Domain.StoreItems.Models.ItemId(itemId)); StoreItemReadModel result; try { result = await queryDispatcher.DispatchAsync(query, default); } catch (DomainException e) { return(BadRequest(e.Reason)); } var contract = storeItemContractConverter.ToContract(result); return(Ok(contract)); }
public async Task <IActionResult> GetItemSearchResults([FromRoute(Name = "searchInput")] string searchInput, [FromRoute(Name = "storeId")] int storeId) { var query = new ItemSearchQuery(searchInput, new StoreId(storeId)); IEnumerable <ItemSearchReadModel> readModels; try { readModels = await queryDispatcher.DispatchAsync(query, default); } catch (DomainException e) { return(BadRequest(e.Reason)); } var contracts = itemSearchContractConverter.ToContract(readModels); return(Ok(contracts)); }
public ShoppingListItemContract ToContract(ShoppingListItemReadModel source) { if (source is null) { throw new System.ArgumentNullException(nameof(source)); } ItemCategoryContract itemCategoryContract = null; if (source.ItemCategory != null) { itemCategoryContract = itemCategoryContractConverter.ToContract(source.ItemCategory); } ManufacturerContract manufacturerContract = null; if (source.Manufacturer != null) { manufacturerContract = manufacturerContractConverter.ToContract(source.Manufacturer); } QuantityTypeContract quantityTypeContract = quantityTypeContractConverter.ToContract(source.QuantityType); QuantityTypeInPacketContract quantityTypeInPacketContract = quantityTypeInPacketContractConverter.ToContract(source.QuantityTypeInPacket); return(new ShoppingListItemContract( source.Id.Value, source.Name, source.IsDeleted, source.Comment, source.IsTemporary, source.PricePerQuantity, quantityTypeContract, source.QuantityInPacket, quantityTypeInPacketContract, itemCategoryContract, manufacturerContract, source.IsInBasket, source.Quantity)); }