Ejemplo n.º 1
0
        private Employee AddRandomEmployee()
        {
            Employee employee =
                new Employee()
                {
                    Alias = this._random.Next().ToString(),
                    Manager = this._random.Next().ToString(),
                    Name = this._random.Next().ToString(),
                };

            ExpenseService service = new ExpenseService();
            service.SaveEmployee(employee);
            return employee;
        }
Ejemplo n.º 2
0
 public int SaveEmployee(Employee employee)
 {
     using (DbDataContext db = new DbDataContext())
     {
         Employee dbEmployee;
         if (employee.EmployeeId == 0)
         {
             dbEmployee = employee;
             db.Employees.InsertOnSubmit(dbEmployee);
         }
         else
         {
             dbEmployee = db.Employees.Single(item => item.EmployeeId == employee.EmployeeId);
             dbEmployee.Alias = employee.Alias;
             dbEmployee.Manager = employee.Manager;
             dbEmployee.Name = employee.Name;
         }
         db.SubmitChanges();
         return dbEmployee.EmployeeId;
     }            
 }
Ejemplo n.º 3
0
        private Employee CreateNewEmployee(string alias)
        {
            string managerAlias = "manager";

            if (string.Compare(alias, "rogreen", true) != 0)
            {
                managerAlias = "rogreen";
            }

            Employee employee =
                new Employee()
                {
                    Alias = alias,
                    Charges = new EntitySet<Charge>(),
                    ExpenseReports = new EntitySet<ExpenseReport>(),
                    Manager = managerAlias,
                    Name = "New Employee",
                };

            employee.Charges.Add(
                new Charge()
                {
                    AccountNumber = 723000,
                    BilledAmount = 200M,
                    Category = (int)CategoryType.Hotel,
                    Description = "REF# 27438948",
                    ExpenseDate = DateTime.Today.AddDays(-45),
                    ExpenseType = (int)ChargeType.Business,
                    Location = "San Francisco, CA",
                    Merchant = "Northwind Inn",
                    Notes = string.Empty,
                    ReceiptRequired = true,
                    TransactionAmount = 200M,
                });

            employee.Charges.Add(
                new Charge()
                {
                    AccountNumber = 723000,
                    BilledAmount = 40,
                    Category = (int)CategoryType.OtherTravelAndLodging,
                    Description = "REF# 77384751",
                    ExpenseDate = DateTime.Today.AddDays(-20),
                    ExpenseType = (int)ChargeType.Business,
                    Location = "Seattle, WA",
                    Merchant = "Contoso Taxi",
                    Notes = string.Empty,
                    ReceiptRequired = false,
                    TransactionAmount = 40,
                });

            employee.Charges.Add(
                new Charge()
                {
                    AccountNumber = 723000,
                    BilledAmount = 67,
                    Category = (int)CategoryType.TEMeals,
                    Description = "REF# 33748563",
                    ExpenseDate = DateTime.Today.AddDays(-8),
                    ExpenseType = (int)ChargeType.Business,
                    Location = "Seattle, WA",
                    Merchant = "Fourth Coffee",
                    Notes = string.Empty,
                    ReceiptRequired = false,
                    TransactionAmount = 12,
                });

            employee.Charges.Add(
                new Charge()
                {
                    AccountNumber = 723000,
                    BilledAmount = 17,
                    Category = (int)CategoryType.TEMeals,
                    Description = "REF# 33748876",
                    ExpenseDate = DateTime.Today.AddDays(-4),
                    ExpenseType = (int)ChargeType.Business,
                    Location = "Seattle, WA",
                    Merchant = "Fourth Coffee",
                    Notes = string.Empty,
                    ReceiptRequired = false,
                    TransactionAmount = 15,
                });

            ExpenseReport expenseReport = 
                new ExpenseReport()
                {
                    Amount = 640M,
                    Approver = managerAlias,
                    CostCenter = 50992,
                    DateSubmitted = DateTime.Today.AddDays(-7),
                    Notes = (managerAlias == "rogreen") ? "Kim Akers" : "Visit to Blue Yonder Airlines",
                    OwedToCreditCard = 450M,
                    OwedToEmployee = 0M,
                    Purpose = "Visit to Blue Yonder Airlines",
                    Status = (int)ExpenseReportStatus.Pending,
                };
            employee.ExpenseReports.Add(expenseReport);

            expenseReport =
                new ExpenseReport()
                {
                    Amount = 450M,
                    Approver = managerAlias,
                    CostCenter = 50992,
                    DateSubmitted = DateTime.Today.AddDays(-7),
                    Notes = (managerAlias == "rogreen") ? "Kim Akers" : "Visit to Tailspin Toys",
                    OwedToCreditCard = 450M,
                    OwedToEmployee = 0M,
                    Purpose = "Visit to Tailspin Toys",
                    Status = (int)ExpenseReportStatus.Pending,
                };
            employee.ExpenseReports.Add(expenseReport);
            
            expenseReport.Charges.Add(
                new Charge()
                {
                    AccountNumber = 723000,
                    BilledAmount = 350M,
                    Category = (int)CategoryType.AirFare,
                    Description = "Airfare to San Francisco",    
                    Employee = employee,
                    ExpenseDate = DateTime.Today.AddDays(-60),
                    ExpenseType = (int)ChargeType.Business,
                    Location = "Chicago, IL",
                    Merchant = "Blue Yonder Airlines",
                    Notes = string.Empty,
                    ReceiptRequired = true,
                    TransactionAmount = 350M,
                });

            expenseReport.Charges.Add(
                new Charge()
                {
                    AccountNumber = 723000,
                    BilledAmount = 50,
                    Category = (int)CategoryType.OtherTravelAndLodging,
                    Description = "Cab from airport",
                    Employee = employee,
                    ExpenseDate = DateTime.Today.AddDays(-45),
                    ExpenseType = (int)ChargeType.Business,
                    Location = "San Francisco, CA",
                    Merchant = "Contoso Taxi",
                    Notes = string.Empty,
                    ReceiptRequired = false,
                    TransactionAmount = 50,
                });

            expenseReport.Charges.Add(
                new Charge()
                {
                    AccountNumber = 723000,
                    BilledAmount = 50,
                    Category = (int)CategoryType.OtherTravelAndLodging,
                    Description = "Cab to airport",
                    Employee = employee,
                    ExpenseDate = DateTime.Today.AddDays(-45),
                    ExpenseType = (int)ChargeType.Business,
                    Location = "San Francisco, CA",
                    Merchant = "Contoso Taxi",
                    Notes = string.Empty,
                    ReceiptRequired = false,
                    TransactionAmount = 50,
                });
                        
            // Add a year of every other month customer visits
            int x = -75;
            for (int i = 1; i <= 6; i++)
            {
                expenseReport = 
                    new ExpenseReport()
                    {
                        Amount = 850M,
                        Approver = managerAlias,
                        CostCenter = 50992,
                        DateSubmitted = DateTime.Today.AddDays(x - 5),
                        DateResolved = DateTime.Today.AddDays(x),
                        Notes = "Visit to Tailspin Toys",
                        OwedToCreditCard = 850M,
                        OwedToEmployee = 0M,
                        Purpose = "Customer visit",
                        Status = (int)ExpenseReportStatus.Approved,
                    };
                employee.ExpenseReports.Add(expenseReport);

                expenseReport.Charges.Add(
                    new Charge()
                    {
                        AccountNumber = 723000,
                        BilledAmount = 350M,
                        Category = (int)CategoryType.AirFare,
                        Description = "Airfare to Chicago",
                        Employee = employee,
                        ExpenseDate = DateTime.Today.AddDays(x - 15),
                        ExpenseType = (int)ChargeType.Business,
                        Location = "Chicago, IL",
                        Merchant = "Blue Yonder Airlines",
                        Notes = string.Empty,
                        ReceiptRequired = true,
                        TransactionAmount = 350M,
                    });

                expenseReport.Charges.Add(
                    new Charge()
                    {
                        AccountNumber = 723000,
                        BilledAmount = 50M,
                        Category = (int)CategoryType.OtherTravelAndLodging,
                        Description = "Cab from airport",
                        Employee = employee,
                        ExpenseDate = DateTime.Today.AddDays(x - 5),
                        ExpenseType = (int)ChargeType.Business,
                        Location = "Chicago, IL",
                        Merchant = "Contoso Taxi",
                        Notes = string.Empty,
                        ReceiptRequired = false,
                        TransactionAmount = 50M,
                    });

                expenseReport.Charges.Add(
                    new Charge()
                    {
                        AccountNumber = 723000,
                        BilledAmount = 50M,
                        Category = (int)CategoryType.OtherTravelAndLodging,
                        Description = "Cab to airport",
                        Employee = employee,
                        ExpenseDate = DateTime.Today.AddDays(x - 3),
                        ExpenseType = (int)ChargeType.Business,
                        Location = "Chicago, IL",
                        Merchant = "Contoso Taxi",
                        Notes = string.Empty,
                        ReceiptRequired = false,
                        TransactionAmount = 50M,
                    });

                expenseReport.Charges.Add(
                    new Charge()
                    {
                        AccountNumber = 723000,
                        BilledAmount = 400M,
                        Category = (int)CategoryType.Hotel,
                        Description = "2 nights hotel",
                        Employee = employee,
                        ExpenseDate = DateTime.Today.AddDays(x - 3),
                        ExpenseType = (int)ChargeType.Business,
                        Location = "Chicago, IL",
                        Merchant = "Northwind Inn",
                        Notes = string.Empty,
                        ReceiptRequired = true,
                        TransactionAmount = 400M,
                    });

                x -= 60;
            }

            // Add 18 months of cell phone charges
            x = -30;
            for (int i = 1; i <= 18; i++)
            {
                expenseReport =
                    new ExpenseReport()
                    {
                        Amount = 850M,
                        Approver = managerAlias,
                        CostCenter = 50992,
                        DateSubmitted = DateTime.Today.AddDays(x - 5),
                        DateResolved = DateTime.Today.AddDays(x),
                        Notes = "",
                        OwedToCreditCard = 0,
                        OwedToEmployee = 50M,
                        Purpose = "Last month's cell phone",
                        Status = (int)ExpenseReportStatus.Approved,
                    };
                employee.ExpenseReports.Add(expenseReport);

                expenseReport.Charges.Add(
                    new Charge()
                    {
                        AccountNumber = 742000,
                        BilledAmount = 50M,
                        Category = (int)CategoryType.OtherTravelAndLodging,
                        Description = "Cell phone bill",
                        Employee = employee,
                        ExpenseDate = DateTime.Today.AddDays(x - 10),
                        ExpenseType = (int)ChargeType.Personal,
                        Location = "Seattle, WA",
                        Merchant = "The Phone Company",
                        Notes = string.Empty,
                        ReceiptRequired = true,
                        TransactionAmount = 50M,
                    });

                x -= 30;
            }

            using (DbDataContext db = new DbDataContext())
            {
                db.Employees.InsertOnSubmit(employee);
                db.SubmitChanges();
            }

            this.GetEmployee("kimakers");

            return employee;
        }
Ejemplo n.º 4
0
 partial void DeleteEmployee(Employee instance);
Ejemplo n.º 5
0
 partial void UpdateEmployee(Employee instance);
Ejemplo n.º 6
0
 partial void InsertEmployee(Employee instance);
Ejemplo n.º 7
0
        public void Create_Employee()
        {
            string alias = "rogreen";

            Employee employee =
                new Employee()
                {
                    Alias = alias,
                    Manager = "notrogreen",
                    Name = "Robert Green",
                };

            ExpenseService service = new ExpenseService();

            int employeeId = service.SaveEmployee(employee);
            Assert.AreNotEqual(0, employeeId);
            Assert.AreEqual(employeeId, employee.EmployeeId);

            Employee dbData = service.GetEmployee(alias);
            Assert.AreEqual(alias, dbData.Alias);

            alias = "rogreen2";
            employee.Alias = alias;
            service.SaveEmployee(employee);

            dbData = service.GetEmployee(alias);
            Assert.AreEqual(alias, dbData.Alias);
        }