예제 #1
0
        public ActionResult <ShoppingListDto> CreateShoppingList(ShoppingListForCreationDto shoppingList)
        {
            var shoppingListEntity = _mapper.Map <Entities.ShoppingList>(shoppingList);

            _shopListingRepository.AddShoppingList(shoppingListEntity);
            _shopListingRepository.Save();

            var shoppingListToReturn = _mapper.Map <ShoppingListDto>(shoppingListEntity);

            return(CreatedAtRoute("GetShoppingList",
                                  new { shoppingListId = shoppingListToReturn.Id },
                                  shoppingListToReturn));
        }
        public ActionResult <IEnumerable <ShoppingListDto> > CreateShoppingListCollection(
            IEnumerable <ShoppingListForCreationDto> shoppingListCollection)
        {
            var shoppingListEntities = _mapper.Map <IEnumerable <Entities.ShoppingList> >(shoppingListCollection);

            foreach (var shoppingList in shoppingListEntities)
            {
                _shopListingRepository.AddShoppingList(shoppingList);
            }

            _shopListingRepository.Save();

            var shoppingListCollectionToReturn = _mapper.Map <IEnumerable <ShoppingListDto> >(shoppingListEntities);
            var idsAsString = string.Join(",", shoppingListCollectionToReturn.Select(sl => sl.Id));

            return(CreatedAtRoute("GetShoppingListCollection",
                                  new { ids = idsAsString },
                                  shoppingListCollectionToReturn));
        }
        public ActionResult <ShoppingItemDto> CreateShoppingItemForShoppingList(
            Guid shoppingListId, ShoppingItemForCreationDto shoppingItem)
        {
            if (!_shopListingRepository.ShoppingListExists(shoppingListId))
            {
                return(NotFound());
            }

            var shoppingItemEntity = _mapper.Map <Entities.ShoppingItem>(shoppingItem);

            _shopListingRepository.AddShoppingItem(shoppingListId, shoppingItemEntity);

            _shopListingRepository.Save();

            var shoppingItemToReturn = _mapper.Map <ShoppingItemDto>(shoppingItemEntity);

            return(CreatedAtRoute("GetShoppingItemForShoppingList",
                                  new { shoppingListId = shoppingListId, shoppingItemId = shoppingItemToReturn.Id },
                                  shoppingItemToReturn));
        }