示例#1
0
        public static NewCartItemModel Create(
            string dealId,
            string dealOptionId,
            IEnumerable<string> selectedAttributes)
        {
            var model = new NewCartItemModel()
            {
                DealId = dealId,
                DealOptionId = dealOptionId,
                selectedAttributes = selectedAttributes.ToList()
            };

            return model;
        }
示例#2
0
        public void AddCartItem(string emailAddress, NewCartItemModel model)
        {
            var unitOfWork = this.unitOfWorkFactory.CreateUnitOfWork();
            var repository = unitOfWork.CreateUserRepository();
            var dealRepository = unitOfWork.CreateDealRepository();

            var user = repository.FindByEmailAddress(emailAddress);
            var deal = dealRepository.FindByKey(model.DealId);

            var dealOption = deal.Options.First(d => d.Key.ToString().Equals(model.DealOptionId));
            var attributes = dealOption.Attributes.Where(d => model.SelectedAttributes.Contains(d.Key.ToString())).ToList();

            var cartItem = CartItemModel.Create(deal, dealOption, attributes);

            user.AddToCart(cartItem);

            repository.Save();
        }