Beispiel #1
0
        public static void dataSeed()
        {
            Item Sugar = new Item("sugar", "White Sugar", "A White Sugar", 10, 10);
            Item Flour = new Item("flour", "White Flour", "A White Flour", 20, 5);

            Warehouse.AddItem(Sugar);
            Warehouse.AddItem(Flour);

            OnlineCustomer Jason = new OnlineCustomer("Jason", "Hawthorn East", "0477123456");
            Person         Rifky = new OfflineCustomer("Rifky", "Hawthorn East", "0477123456");

            Customers.AddCustomer(Jason);
            Customers.AddCustomer(Rifky);



            Payment cash = new Cash(10000, 10000);

            ShoppingCart cart = new ShoppingCart();

            cart.AddToCart("sugar");
            cart.AddToCart("flour");
            Jason.ShoppingCart = cart;


            Transaction newTransaction = new Transaction("ABC123", DateTime.Now, cash, Jason);

            AllTransactions.AddTransactions(newTransaction);

            foreach (Transaction transaction in AllTransactions.GetTransactions)
            {
                Console.WriteLine(transaction);
            }
        }
 // C# 8
 public double GetDiscount(Customer customer)
 {
     return(customer switch
     {
         WalkinCustomer _ => 0.1,
         OnlineCustomer onlineCustomer when onlineCustomer.Age >= 70 => 0.4,
         OnlineCustomer onlineCustomer when onlineCustomer.Age >= 60 => 0.3,
         OnlineCustomer _ => 0.2,
         null => throw new ArgumentNullException(),
         _ => throw new ArgumentException()
     });
Beispiel #3
0
        public int AddOnlineCustomer(OnlineCustomer item)
        {
            using (var context = new eToolsContext())
            {
                var added = context.OnlineCustomers.Add(item);

                context.SaveChanges();

                return(added.OnlineCustomerID);
            }
        }
Beispiel #4
0
        public bool ShouldUpdateCustomer(int customerId)
        {
            var customer = new OnlineCustomer
            {
                CustomerName = "VikramH",
                Email        = "*****@*****.**",
                PhoneNo      = "9879873333",
                Category     = "Standard",
                Address      = "Bangaluru",
                Pincode      = "570004"
            };
            var res = repository.Update(customerId, customer);

            return(res);
        }
Beispiel #5
0
        public void Add_OnlineCustomer(string username)
        {
            using (var context = new eBikeContext())
            {
                var customer = new OnlineCustomer();

                customer.UserName  = username;
                customer.CreatedOn = DateTime.Now;


                context.OnlineCustomers.Add(customer);

                context.SaveChanges();
            }
        }
Beispiel #6
0
        public void ShouldReturnCustomerIdOnAddNewCustomer()
        {
            var customer = new OnlineCustomer
            {
                CustomerName = "VikramHH",
                Email        = "*****@*****.**",
                PhoneNo      = "9879879878",
                Category     = "Standard",
                Address      = "Bangaluru",
                Pincode      = "570006"
            };
            var actualId   = repository.Add(customer);
            var expectedId = 105;

            Assert.AreEqual(expectedId, actualId);
        }
 public void AddToOnlineCustomer(Guid TrC, string Name)
 {
     using (var context = new eToolDBContext())
     {
         var Customer = context.OnlineCustomers.SingleOrDefault(x => x.TrackingCookie == TrC);
         if (Customer == null)
         {
             Customer = new OnlineCustomer
             {
                 //OnlineCustomerID = ID,
                 UserName  = Name,
                 CreatedOn = DateTime.Now,
             };
             context.OnlineCustomers.Add(Customer);
             context.SaveChanges();
         }
     }
 }
Beispiel #8
0
        public void Add_New_OnlineCustomer(string username)
        {
            using (var context = new eBikesContext())
            {
                var exsists = (from x in context.OnlineCustomer where x.UserName.Equals(username) select x).FirstOrDefault();

                if (exsists == null)
                {
                    Guid trackingCookie;
                    trackingCookie         = Guid.NewGuid();
                    exsists                = new OnlineCustomer();
                    exsists.UserName       = username;
                    exsists.CreatedOn      = DateTime.Now;
                    exsists.TrackingCookie = trackingCookie;
                    context.OnlineCustomer.Add(exsists);
                    context.SaveChanges();
                }
            }
        }
        // BUSINESS LOGIC TO ADD NEW ONLINECUSTOMER

        public void AddOnlineCustomer(string username)
        {
            using (var context = new EBContext())
            {
                var customer = (from data in context.OnlineCustomers
                                where data.UserName.Equals(username)
                                select data).FirstOrDefault();

                if (customer == null)
                {
                    Guid trackingCookie;
                    trackingCookie          = Guid.NewGuid();
                    customer                = new OnlineCustomer();
                    customer.UserName       = username;
                    customer.CreatedOn      = DateTime.Now;
                    customer.TrackingCookie = trackingCookie;
                    context.OnlineCustomers.Add(customer);
                    context.SaveChanges();
                }
            }
        }
Beispiel #10
0
    protected void ItemReapter_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Add")
        {
            //int i;

            int      itemCode = Convert.ToInt32(e.CommandArgument.ToString());
            string   username = User.Identity.GetUserName();
            DateTime Today    = DateTime.Today;

            TextBox quantity = e.Item.FindControl("Quantity") as TextBox;
            int     counts   = Convert.ToInt32(quantity.Text);

            OnlineCustomer newCustomer = new OnlineCustomer();

            SalesController sysmgr = new SalesController();

            if (sysmgr.GetOnlineCustomerIDByUserName(username) == 0)
            {
                newCustomer.UserName  = username;
                newCustomer.CreatedOn = Today;
                int onlineCustomerId = sysmgr.AddOnlineCustomer(newCustomer);
            }

            if (sysmgr.GetShoppingCartByUserName(username) == 0)
            {
                ShoppingCart newShoppingCart = new ShoppingCart();
                newShoppingCart.OnlineCustomerID = sysmgr.FindCustomerID(username);
                newShoppingCart.CreatedOn        = Today;
                sysmgr.AddShoppingCart(newShoppingCart);
            }

            MessageUserControl.TryRun(() =>
            {
                sysmgr.AddToShoppingCart(itemCode, username, counts);
                Button add        = e.Item.FindControl("Add") as Button;
                LinkButton update = e.Item.FindControl("Update") as LinkButton;
                Label itemCount   = e.Item.FindControl("itemCount") as Label;

                add.Visible    = false;
                update.Visible = true;
                itemCount.Text = quantity.Text;
            }, "Success", "New Item has been added to your shopping cart.");
        }

        if (e.CommandName == "Update")
        {
            if (int.Parse((e.Item.FindControl("Quantity") as TextBox).Text) < 1)
            {
                MessageUserControl.ShowInfo("Quantity should greater than 0.");
            }
            else
            {
                SalesController sysmgr = new SalesController();

                string username           = User.Identity.GetUserName();
                int    quantity           = int.Parse((e.Item.FindControl("Quantity") as TextBox).Text);
                int    itemCode           = Convert.ToInt32(e.CommandArgument.ToString());
                int    OnlineCustomerID   = sysmgr.FindCustomerID(username);
                int    shoppingCartItemID = sysmgr.GetShoppingCartItemID(OnlineCustomerID);

                MessageUserControl.TryRun(() =>
                {
                    sysmgr.UpdateToShoppingCart(itemCode, shoppingCartItemID, username, quantity);
                    Label itemCount = e.Item.FindControl("itemCount") as Label;

                    itemCount.Text = (int.Parse(itemCount.Text) + quantity).ToString();
                }, "Success", "Item quantity was updated");
            }
        }
    }
Beispiel #11
0
        public void AddToCart(string userName, int productId, int quantity)
        {
            //create a new shopping cart with item
            using (var context = new eBikeContext())
            {
                var shoppingCartId = GetShoppingCartId(userName);
                var customerId     = GetCustomerId(userName);
                var qOH            = GetQOH(productId);
                //0 means this customer don't have shoppingCart,
                //-1 means this userName is not a online customer

                //this user is not onlineCustomer
                if (customerId == 0)
                {
                    //create a new onlineCustomer
                    var newOnlineCustomer = new OnlineCustomer();
                    newOnlineCustomer.UserName  = userName;
                    newOnlineCustomer.CreatedOn = DateTime.Today;
                    context.OnlineCustomers.Add(newOnlineCustomer);

                    var newShoppingCart = context.ShoppingCarts.Add(new ShoppingCart());
                    newShoppingCart.OnlineCustomerID = GetCustomerId(userName);
                    newShoppingCart.CreatedOn        = DateTime.Today;
                    newShoppingCart.UpdatedOn        = DateTime.Today;

                    //customer can add as many items as they want
                    //if (qOH >= quantity)
                    //{
                    var newCartItem = new ShoppingCartItem();
                    newCartItem.PartID   = productId;
                    newCartItem.Quantity = quantity;
                    newShoppingCart.ShoppingCartItems.Add(newCartItem);
                    //}
                    //else
                    //{
                    //throw new Exception("We don't have enough quantity on hand");
                    //}
                }
                else
                {
                    //this online customer doesn't have shopping cart
                    if (shoppingCartId == 0)
                    {
                        var newShoppingCart = context.ShoppingCarts.Add(new ShoppingCart());
                        newShoppingCart.OnlineCustomerID = GetCustomerId(userName);
                        newShoppingCart.CreatedOn        = DateTime.Now;
                        newShoppingCart.UpdatedOn        = DateTime.Today;

                        //customer can add as many items as they want
                        //if (qOH >= quantity) {
                        var newCartItem = new ShoppingCartItem();
                        newCartItem.PartID   = productId;
                        newCartItem.Quantity = quantity;
                        newShoppingCart.ShoppingCartItems.Add(newCartItem);
                        //}
                        //else
                        //{
                        //throw new Exception("We don't have enough quantity on hand");
                        //}
                    }
                    else if (shoppingCartId != 0 && shoppingCartId != -1)//this online customer have a shopping cart
                    {
                        var existingShoppingCart = context.ShoppingCarts.Find(GetShoppingCartId(userName));
                        existingShoppingCart.UpdatedOn = DateTime.Today;

                        var cartItemId = GetCartItemId(shoppingCartId, productId);
                        if (cartItemId == 0)//in the shopping cart, customer doesn't have this part
                        {
                            //customer can add as many items as they want
                            //if (qOH >= quantity)
                            //{
                            //create new cartItem
                            var newCartItem = new ShoppingCartItem();
                            newCartItem.PartID   = productId;
                            newCartItem.Quantity = quantity;
                            existingShoppingCart.ShoppingCartItems.Add(newCartItem);
                            //}
                            //else
                            //{
                            //throw new Exception("We don't have enough quantity on hand");
                            //}
                        }
                        else//customer have this part
                        {
                            var exsitingCartItem = context.ShoppingCartItems.Find(cartItemId);
                            //customer can add as many items as they want
                            //if(qOH >= exsitingCartItem.Quantity + quantity)
                            //{
                            exsitingCartItem.Quantity = exsitingCartItem.Quantity + quantity;
                            //}
                            //else
                            //{
                            //throw new Exception("We don't have enough quantity on hand");
                            //}
                        }
                    }
                }
                context.SaveChanges();
            }
        }