private ShoppingCart CreateUserCart(User user)
 {
     var cart = new ShoppingCart
     {
         User = user
     };
     _db.ShoppingCarts.Add(cart);
     _db.SaveChanges();
     return cart;
 }
        private ShoppingCart MigrateCart(int? shoppingCartId, User user)
        {
            if (!shoppingCartId.HasValue)
            {
                return null;
            }

            var cart = _db.ShoppingCarts.FirstOrDefault(c=>c.Id == shoppingCartId);

            if (cart == null)
            {
                return null;
            }
            var newCart = new ShoppingCart
            {
                User = user
            };
            newCart.ReplaceItems(cart.Items);

            return newCart;
        }
 public GetShoppingCartCommand(StoreDbContext db, User user, IDictionary<string, object> session = null)
 {
     _db = db;
     _user = user;
     _session = session;
 }
        private static User CreateUser(RegistrationRequest request, string password)
        {
            string passwordHash;
            using (var sha1 = new SHA1CryptoServiceProvider())
            {
                // TODO: использовать соль!
                passwordHash = Encoding.UTF8.GetString(sha1.ComputeHash(Encoding.UTF8.GetBytes(password)));
            }

            var user = new User
            {
                Email = request.Email,
                PasswordHash = passwordHash
            };

            return user;
        }