コード例 #1
0
ファイル: CustomerService.cs プロジェクト: yubowave/bongstore
        public virtual void DeleteCustomer(Customer customer)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            if (customer.UserType == UserType.Admin)
                throw new BongException(string.Format("Admin account ({0}) could not be deleted", customer.Username));

            customer.Deleted = true;
            UpdateCustomer(customer);
        }
コード例 #2
0
        public virtual void AddToCart(Customer customer, Product product, ShoppingCartType shoppingCartType, int quantity)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            if (product == null)
                throw new ArgumentNullException("product");

            var cart = customer.ShoppingCartItems
                .Where(sci => sci.ShoppingCartType == shoppingCartType)
                .ToList();

            var shoppingCartItem = FindShoppingCartItemInTheCart(cart, shoppingCartType, product);

            if (shoppingCartItem != null)
            {
                //update existing shopping cart item
                shoppingCartItem.Quantity = shoppingCartItem.Quantity + quantity;
                shoppingCartItem.UpdatedOnUtc = DateTime.UtcNow;
                _customerService.UpdateCustomer(customer);
            }
            else
            {
                //new shopping cart item
                DateTime now = DateTime.UtcNow;
                shoppingCartItem = new ShoppingCartItem()
                {
                    ShoppingCartType = shoppingCartType,
                    Product = product,
                    ItemPrice = product.Price,
                    Quantity = quantity,
                    CreatedOnUtc = now,
                    UpdatedOnUtc = now
                };
                customer.ShoppingCartItems.Add(shoppingCartItem);
                _customerService.UpdateCustomer(customer);

                //updated "HasShoppingCartItems" property used for performance optimization
                customer.HasShoppingCartItems = customer.ShoppingCartItems.Count > 0;
                _customerService.UpdateCustomer(customer);
            }
        }
コード例 #3
0
        public Customer GetAuthenticatedCustomer()
        {
            if (_loadedCustomer != null)
                return _loadedCustomer;

            if (_httpContext == null || _httpContext.Request == null ||
                !_httpContext.Request.IsAuthenticated || !(_httpContext.User.Identity is FormsIdentity))
            {
                return null;
            }

            var identity = (FormsIdentity)_httpContext.User.Identity;
            if (identity == null || identity.Ticket == null)
                throw new ArgumentException("identity ticket");

            var email = identity.Ticket.UserData;
            var customer = _customerService.GetCustomerByEmail(email);

            if (customer != null && customer.Active && !customer.Deleted && customer.UserType != UserType.Guest)
                _loadedCustomer = customer;
            return _loadedCustomer;
        }
コード例 #4
0
ファイル: InstallService.cs プロジェクト: yubowave/bongstore
 protected virtual void InstallCustomers(string adminEmail, string adminPassword)
 {
     var adminUser = new Customer()
     {
         CustomerGuid = Guid.NewGuid(),
         Email = adminEmail,
         Username = adminEmail,
         PasswordHashCode = adminPassword.GetHashCode(),
         Active = true,
         UserType = UserType.Admin,
         CreatedOnUtc = DateTime.UtcNow,
     };
     _customerRepository.Insert(adminUser);
 }
コード例 #5
0
 public void SignIn(Customer customer, bool persistentCookie)
 {
 }
コード例 #6
0
ファイル: CustomerService.cs プロジェクト: yubowave/bongstore
        public virtual void UpdateCustomer(Customer customer)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            _customerRepository.Update(customer);
        }
コード例 #7
0
ファイル: CustomerService.cs プロジェクト: yubowave/bongstore
        public virtual Customer InsertGuestCustomer()
        {
            var customer = new Customer()
            {
                CustomerGuid = Guid.NewGuid(),
                Active = true,
                CreatedOnUtc = DateTime.UtcNow,
                UserType = UserType.Guest,
            };
            _customerRepository.Insert(customer);

            return customer;
        }
コード例 #8
0
ファイル: CustomerService.cs プロジェクト: yubowave/bongstore
        public virtual void InsertCustomer(Customer customer)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            _customerRepository.Insert(customer);
        }
コード例 #9
0
        public virtual void UpdateShoppingCartItem(Customer customer, int shoppingCartItemId, int quantity)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            var shoppingCartItem = customer.ShoppingCartItems.FirstOrDefault(sci => sci.Id == shoppingCartItemId);
            if (shoppingCartItem != null)
            {
                if (quantity > 0)
                {
                    shoppingCartItem.Quantity = quantity;
                    shoppingCartItem.UpdatedOnUtc = DateTime.UtcNow;
                    _customerService.UpdateCustomer(customer);
                }
                else
                {
                    DeleteShoppingCartItem(shoppingCartItem);
                }
            }
        }