public void GetNetPayableAmountForEmployeeTest3()
 {
     Billing target = new Billing();
     User user = new User();
     double nonGroceryBill = 0;
     double groceryBill = 0; 
     UserType userType = UserType.Employee;
     double expected = 0; 
     double actual;
     actual = target.GetNetPayableAmount(user, nonGroceryBill, groceryBill, userType);
     Assert.AreEqual(expected, actual);
 }
        /// <summary>
        /// To test the billing system.
        /// </summary>
        /// <param name="args">string argument</param>
        public static void Main(string[] args)
        {
            try
            {
                User user = new User();

                // Read the type of the user
                Console.WriteLine("\n----------------");
                Console.WriteLine("User Type:");
                Console.WriteLine("----------------\n");

                Console.Write(@"
1 - Employee
2 - Affiliate
3 - Customer

Please select one (1, 2, or 3): ");

                int userType = Int32.Parse(Console.ReadLine());
                while (true)
                {
                    if (userType < 1 || userType > 3)
                    {
                        Console.WriteLine("Invalid input");
                        Console.ReadKey();
                        break;
                    }

                    // Perform explicit cast from int to UserType enum type
                    UserType myUserType = (UserType)userType;

                    if (myUserType == UserType.Customer)
                    {
                        // Read membership date of the user
                        Console.Write("Enter Membership Date: ");
                        user.MembershipDate = DateTime.Parse(Console.ReadLine());
                    }

                    // Read Non Grocery Bill of the user
                    Console.Write("Enter Non Grocery Bill: ");
                    user.NonGroceryBill = Double.Parse(Console.ReadLine());

                    // Read Grocery Bill of the user
                    Console.Write("Enter Grocery Bill: ");
                    user.GroceryBill = Double.Parse(Console.ReadLine());

                    Billing billingObj = new Billing();
                    double netPayableAmount = billingObj.GetNetPayableAmount(user, user.NonGroceryBill, user.GroceryBill, myUserType);
                    Console.WriteLine("Net payable amount is: {0}", netPayableAmount);
                    Console.ReadLine();

                    System.Environment.Exit(0);
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                Console.Read();

            }
        }
        public void GetNetPayableAmountForNewCustomerTest7()
        {
            Billing target = new Billing();
            User user = new User();    
            user.MembershipDate = Convert.ToDateTime("2012-01-01");

            double nonGroceryBill = 50;
            double groceryBill = 50;
            UserType userType = UserType.Customer;
            double expected = 100;
            double actual;
            actual = target.GetNetPayableAmount(user, nonGroceryBill, groceryBill, userType);
            Assert.AreEqual(expected, actual);
        }
 public void GetNetPayableAmountForAffiliateTest7()
 {
     Billing target = new Billing();
     User user = new User();
     double nonGroceryBill = 50;
     double groceryBill = 50;
     UserType userType = UserType.Affiliate;
     double expected = 95;
     double actual;
     actual = target.GetNetPayableAmount(user, nonGroceryBill, groceryBill, userType);
     Assert.AreEqual(expected, actual);
 }
 /// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="login">Initial value of the Login property.</param>
 /// <param name="password">Initial value of the Password property.</param>
 /// <param name="connectionDate">Initial value of the ConnectionDate property.</param>
 /// <param name="tariffId">Initial value of the TariffId property.</param>
 /// <param name="isAllow">Initial value of the IsAllow property.</param>
 /// <param name="isAdmin">Initial value of the IsAdmin property.</param>
 /// <param name="balance">Initial value of the Balance property.</param>
 public static User CreateUser(global::System.Int32 id, global::System.String login, global::System.String password, global::System.DateTime connectionDate, global::System.Int32 tariffId, global::System.Boolean isAllow, global::System.Boolean isAdmin, global::System.Decimal balance)
 {
     User user = new User();
     user.Id = id;
     user.Login = login;
     user.Password = password;
     user.ConnectionDate = connectionDate;
     user.TariffId = tariffId;
     user.IsAllow = isAllow;
     user.IsAdmin = isAdmin;
     user.Balance = balance;
     return user;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUsers(User user)
 {
     base.AddObject("Users", user);
 }
        /// <summary>
        /// Gets the net payable amount for the user.
        /// </summary>
        /// <param name="user">User object</param>
        /// <param name="nonGroceryBill">Non-grocery bill before discount</param>
        /// <param name="GroceryBill">Grocery bill before discount</param>
        /// <param name="userType">Type of user</param>
        /// <returns>Net payable amount</returns>
        public double GetNetPayableAmount(User user, double nonGroceryBill, double groceryBill, UserType userType)
        {
            try
            {
                switch (userType)
                {
                    case UserType.Employee:
                        {
                            // If purchased items are non-groceries, 
                            // then calculate payable amount based on both Percentage and 
                            // cash discount of $5 discount per 100$ 
                            if (nonGroceryBill > 0)
                            {
                                this.discountedNonGroceryBill = this.GetPercentageBasedPayableAmount(nonGroceryBill, Constants.EmployeeDiscount);
                                this.discountedNonGroceryBill = this.GetCashBasedPayableAmount(this.discountedNonGroceryBill);
                            }
                            
                            // If purchased items are groceries, then calculate payable amount based on 
                            // cash discount of $5 discount per 100$ 
                            if (groceryBill > 0)
                            {
                                this.discountedGroceryBill = this.GetCashBasedPayableAmount(groceryBill);
                            }

                            // Net Payable Amount is sum of discountedNonGroceryBill and discountedGroceryBill
                            this.netPayableAmount = this.discountedNonGroceryBill + this.discountedGroceryBill;

                            break;
                         }

                    case UserType.Affiliate:
                        {
                            // If purchased items are non-groceries, 
                            // then calculate payable amount based on both Percentage and 
                            // cash discount of $5 discount per 100$ 
                            if (nonGroceryBill > 0)
                            {
                                this.discountedNonGroceryBill = this.GetPercentageBasedPayableAmount(nonGroceryBill, Constants.AffiliateDiscount);
                                this.discountedNonGroceryBill = this.GetCashBasedPayableAmount(this.discountedNonGroceryBill);
                            }

                            // If purchased items are groceries, then calculate payable amount based on 
                            // cash discount of $5 discount per 100$ 
                            if (groceryBill > 0)
                            {
                                this.discountedGroceryBill = this.GetCashBasedPayableAmount(groceryBill);
                            }

                            // Net Payable Amount is sum of discountedNonGroceryBill and discountedGroceryBill
                            this.netPayableAmount = this.discountedNonGroceryBill + this.discountedGroceryBill;

                            break;
                        }

                    case UserType.Customer:
                        {
                            // Check the span of customer membership
                            TimeSpan span = DateTime.Now.Subtract(user.MembershipDate);
                            double years = span.Days / 365.25; // leap years included    

                            if (years >= 2)
                            {
                                // If purchased items are non-groceries, 
                                // then calculate payable amount based on both Percentage and 
                                // cash discount of $5 discount per 100$ 
                                if (nonGroceryBill > 0)
                                {
                                    this.discountedNonGroceryBill = this.GetPercentageBasedPayableAmount(nonGroceryBill, Constants.CustomerDiscount);
                                    this.discountedNonGroceryBill = this.GetCashBasedPayableAmount(this.discountedNonGroceryBill);
                                }

                                // If purchased items are groceries, then calculate payable amount based on 
                                // cash discount of $5 discount per 100$ 
                                if (groceryBill > 0)
                                {
                                    this.discountedGroceryBill = this.GetCashBasedPayableAmount(groceryBill);
                                }

                                // Net Payable Amount is sum of discountedNonGroceryBill and discountedGroceryBill
                                this.netPayableAmount = this.discountedNonGroceryBill + this.discountedGroceryBill;
                            }
                            else
                            {
                                // If purchased items are non-groceries, 
                                // then calculate payable amount based on both Percentage and 
                                // cash discount of $5 discount per 100$ 
                                if (nonGroceryBill > 0)
                                {
                                    this.discountedNonGroceryBill = this.GetCashBasedPayableAmount(nonGroceryBill);
                                }

                                // If purchased items are groceries, then calculate payable amount based on 
                                // cash discount of $5 discount per 100$ 
                                if (groceryBill > 0)
                                {
                                    this.discountedGroceryBill = this.GetCashBasedPayableAmount(groceryBill);
                                }

                                // Net Payable Amount is sum of discountedNonGroceryBill and discountedGroceryBill
                                this.netPayableAmount = this.discountedNonGroceryBill + this.discountedGroceryBill;

                                break;
                            }

                            break;
                        }

                    default:
                        {
                            if (nonGroceryBill + groceryBill > 0)
                            {
                                this.netPayableAmount = this.GetCashBasedPayableAmount(nonGroceryBill + groceryBill);
                            }

                            break;
                        }
                }

                return this.netPayableAmount;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                return 0;
            }
        }