by sunil ravulapalli
/12. July 2013 22:49
/software-design
/Comments (0)
Add the Core, the Data project references to the Service project
Add interface IWishlistService to the Core project
public interface IWishlistService
{
void AddWishlistItem(string description, int quantity);
IList<WishListItem> GetAllWishlistItems();
}
Add class WishlistService to to the Service project
public class WishlistService : IWishlistService
{
readonly IUnitOfWork _unitOfWork;
public WishlistService(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public void AddWishlistItem(string description, int quantity)
{
var wishListItem = new WishListItem
{
Description = description, Quantity = quantity
};
using (_unitOfWork)
{
_unitOfWork.WishListItemRepository.Insert(wishListItem);
_unitOfWork.Save();
}
}
public IList<WishListItem> GetAllWishlistItems()
{
using (_unitOfWork)
{
return (List<WishListItem>)_unitOfWork.WishListItemRepository.GetAll();
}
}
}
You can find the solution on GitHub.
https://github.com/sunilrav/Wishlist.5.SolutionWithService