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); }
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); } }
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; }
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); }
public void SignIn(Customer customer, bool persistentCookie) { }
public virtual void UpdateCustomer(Customer customer) { if (customer == null) throw new ArgumentNullException("customer"); _customerRepository.Update(customer); }
public virtual Customer InsertGuestCustomer() { var customer = new Customer() { CustomerGuid = Guid.NewGuid(), Active = true, CreatedOnUtc = DateTime.UtcNow, UserType = UserType.Guest, }; _customerRepository.Insert(customer); return customer; }
public virtual void InsertCustomer(Customer customer) { if (customer == null) throw new ArgumentNullException("customer"); _customerRepository.Insert(customer); }
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); } } }