示例#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));
        }