Пример #1
0
        public int Register(User user, DateTime cartDate)
        {
            if (user == null)
            {
                throw new ArgumentNullException("User info not supplied");
            }

            using (EF.APShopContext context = new EF.APShopContext())
            {
                UnitOfWork uow     = new UnitOfWork(context);
                EF.User    dboUser = _mapper.Map <EF.User>(user);
                uow.Users.CreateUser(dboUser);

                EF.Cart dbCart = new EF.Cart()
                {
                    DateLastUpdated = cartDate
                };
                dboUser.Cart.Add(dbCart); //virtuelni clan
                uow.Commit();
                return(dboUser.Id);
            }
        }
Пример #2
0
        public Cart GetCartByUserId(int userId)
        {
            using (EF.APShopContext context = new EF.APShopContext())
            {
                UnitOfWork uow = new UnitOfWork(context);

                EF.Cart efUserCart = uow.Carts.GetByUserId(userId);

                if (efUserCart is null)
                {
                    return(null);
                }

                Cart cart = new Cart()
                {
                    Id              = efUserCart.Id,
                    UserId          = efUserCart.UserId,
                    DateLastUpdated = efUserCart.DateLastUpdated
                };

                return(cart);
            }
        }