public async Task <IActionResult> RemoveItemFromShoppingList(
            [FromBody] RemoveItemFromShoppingListContract contract)
        {
            OfflineTolerantItemId itemId;

            try
            {
                itemId = offlineTolerantItemIdConverter.ToDomain(contract.ItemId);
            }
            catch (ArgumentException)
            {
                return(BadRequest("No item id was specified."));
            }

            var command = new RemoveItemFromShoppingListCommand(new ShoppingListId(contract.ShoppingListId), itemId);

            try
            {
                await commandDispatcher.DispatchAsync(command, default);
            }
            catch (DomainException e)
            {
                return(BadRequest(e.Reason));
            }

            return(Ok());
        }
예제 #2
0
        public async Task <IEnumerable <IItemCategory> > FindByAsync(string searchInput,
                                                                     CancellationToken cancellationToken)
        {
            var itemCategoryEntities = await dbContext.ItemCategories.AsNoTracking()
                                       .Where(category => category.Name.Contains(searchInput))
                                       .ToListAsync();

            cancellationToken.ThrowIfCancellationRequested();

            return(toModelConverter.ToDomain(itemCategoryEntities));
        }
예제 #3
0
        public IShoppingList ToDomain(Entities.ShoppingList source)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var itemMapsPerSection = source.ItemsOnList.GroupBy(
                map => map.SectionId.Value,
                map => map,
                (sectionId, maps) => new
            {
                SectionId = sectionId,
                Maps      = maps
            })
                                     .ToDictionary(t => t.SectionId, t => t.Maps);

            List <IShoppingListSection> sectionModels = new List <IShoppingListSection>();

            foreach (var sectionId in itemMapsPerSection.Keys)
            {
                var maps         = itemMapsPerSection[sectionId];
                var items        = maps.Select(map => shoppingListItemConverter.ToDomain(map)).ToList();
                var sectionModel = CreateSection(sectionId, items);
                sectionModels.Add(sectionModel);
            }

            return(shoppingListFactory.Create(
                       new ShoppingListId(source.Id),
                       new StoreId(source.StoreId),
                       source.CompletionDate,
                       sectionModels));
        }
예제 #4
0
        public async Task <IActionResult> CreateItem([FromBody] CreateItemContract createItemContract)
        {
            var model   = itemCreationConverter.ToDomain(createItemContract);
            var command = new CreateItemCommand(model);

            await commandDispatcher.DispatchAsync(command, default);

            return(Ok());
        }
        public async Task <IShoppingList> FindByAsync(ShoppingListId id, CancellationToken cancellationToken)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var entity = await GetShoppingListQuery()
                         .FirstOrDefaultAsync(list => list.Id == id.Value);

            cancellationToken.ThrowIfCancellationRequested();

            if (entity == null)
            {
                return(null);
            }

            return(toModelConverter.ToDomain(entity));
        }
예제 #6
0
        public StoreCreationInfo ToDomain(CreateStoreContract source)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(new StoreCreationInfo(
                       new StoreId(0),
                       source.Name,
                       storeSectionConverter.ToDomain(source.Sections)));
        }
        public TemporaryItemCreation ToDomain(CreateTemporaryItemContract source)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(new TemporaryItemCreation(
                       source.ClientSideId,
                       source.Name,
                       storeItemAvailabilityConverter.ToDomain(source.Availability)));
        }
        public StoreUpdate ToDomain(UpdateStoreContract source)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(new StoreUpdate(
                       new StoreId(source.Id),
                       source.Name,
                       storeSectionConverter.ToDomain(source.Sections)));
        }
예제 #9
0
        public IStore ToDomain(Entities.Store source)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            List <IStoreSection> sections = storeSectionConverter.ToDomain(source.Sections).ToList();

            return(storeFactory.Create(
                       new StoreId(source.Id),
                       source.Name,
                       source.Deleted,
                       sections));
        }
        public async Task <IEnumerable <IStore> > GetAsync(CancellationToken cancellationToken)
        {
            var storeEntities = await GetStoreQuery()
                                .Where(store => !store.Deleted)
                                .ToListAsync();

            cancellationToken.ThrowIfCancellationRequested();

            return(toDomainConverter.ToDomain(storeEntities));
        }
예제 #11
0
        public async Task <IActionResult> ModifyItem([FromBody] ModifyItemContract modifyItemContract)
        {
            var model   = itemModifyConverter.ToDomain(modifyItemContract);
            var command = new ModifyItemCommand(model);

            try
            {
                await commandDispatcher.DispatchAsync(command, default);
            }
            catch (DomainException e)
            {
                return(BadRequest(e.Reason));
            }

            return(Ok());
        }
예제 #12
0
        public async Task <IActionResult> MakeTemporaryItemPermanent([FromBody] MakeTemporaryItemPermanentContract contract)
        {
            var model   = permanentItemConverter.ToDomain(contract);
            var command = new MakeTemporaryItemPermanentCommand(model);

            try
            {
                await commandDispatcher.DispatchAsync(command, default);
            }
            catch (DomainException e)
            {
                return(BadRequest(e.Reason));
            }

            return(Ok());
        }
예제 #13
0
        public async Task <IActionResult> UpdateStore([FromBody] UpdateStoreContract updateStoreContract)
        {
            var model   = storeUpdateConverter.ToDomain(updateStoreContract);
            var command = new UpdateStoreCommand(model);

            try
            {
                await commandDispatcher.DispatchAsync(command, default);
            }
            catch (DomainException e)
            {
                return(BadRequest(e.Reason));
            }

            return(Ok());
        }
        public async Task <IStoreItem> FindByAsync(ItemId storeItemId, CancellationToken cancellationToken)
        {
            if (storeItemId is null)
            {
                throw new ArgumentNullException(nameof(storeItemId));
            }

            cancellationToken.ThrowIfCancellationRequested();

            var itemEntity = await GetItemQuery()
                             .FirstOrDefaultAsync(item => item.Id == storeItemId.Value);

            cancellationToken.ThrowIfCancellationRequested();

            if (itemEntity == null)
            {
                return(null);
            }

            itemEntity.Predecessor = await LoadPredecessorsAsync(itemEntity);

            return(toModelConverter.ToDomain(itemEntity));
        }
예제 #15
0
        public ItemCreation ToDomain(CreateItemContract source)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(new ItemCreation(
                       source.Name,
                       source.Comment,
                       source.QuantityType.ToEnum <QuantityType>(),
                       source.QuantityInPacket,
                       source.QuantityTypeInPacket.ToEnum <QuantityTypeInPacket>(),
                       new ItemCategoryId(source.ItemCategoryId),
                       source.ManufacturerId.HasValue ?
                       new ManufacturerId(source.ManufacturerId.Value) :
                       null,
                       storeItemAvailabilityConverter.ToDomain(source.Availabilities)));
        }
예제 #16
0
        public IStoreItem ToDomain(Item source)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            IStoreItem predecessor = null;

            if (source.PredecessorId != null)
            {
                var converter = new StoreItemConverter(storeItemFactory, storeItemAvailabilityConverter);
                predecessor = converter.ToDomain(source.Predecessor);
            }

            List <IStoreItemAvailability> availabilities = storeItemAvailabilityConverter.ToDomain(source.AvailableAt)
                                                           .ToList();
            var itemCategoryId = source.ItemCategoryId.HasValue ? new ItemCategoryId(source.ItemCategoryId.Value) : null;
            var manufacturerId = source.ManufacturerId.HasValue ? new ManufacturerId(source.ManufacturerId.Value) : null;
            var temporaryId    = source.CreatedFrom.HasValue ? new TemporaryItemId(source.CreatedFrom.Value) : null;

            return(storeItemFactory.Create(
                       new ItemId(source.Id),
                       source.Name,
                       source.Deleted,
                       source.Comment,
                       source.IsTemporary,
                       source.QuantityType.ToEnum <QuantityType>(),
                       source.QuantityInPacket,
                       source.QuantityTypeInPacket.ToEnum <QuantityTypeInPacket>(),
                       itemCategoryId,
                       manufacturerId,
                       predecessor,
                       availabilities,
                       temporaryId));
        }