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); }
public int SaveExpenseReport(ExpenseReport expenseReport) { using (DbDataContext db = new DbDataContext()) { ExpenseReport dbExpenseReport; if (expenseReport.ExpenseReportId == 0) { dbExpenseReport = expenseReport; db.ExpenseReports.InsertOnSubmit(dbExpenseReport); } else { dbExpenseReport = db.ExpenseReports.Single(item => item.ExpenseReportId == expenseReport.ExpenseReportId); dbExpenseReport.Amount = expenseReport.Amount; dbExpenseReport.Approver = expenseReport.Approver; dbExpenseReport.CostCenter = expenseReport.CostCenter; dbExpenseReport.DateResolved = expenseReport.DateResolved; dbExpenseReport.DateSaved = expenseReport.DateSaved; dbExpenseReport.DateSubmitted = expenseReport.DateSubmitted; dbExpenseReport.EmployeeId = expenseReport.EmployeeId; dbExpenseReport.Notes = expenseReport.Notes; dbExpenseReport.OwedToCreditCard = expenseReport.OwedToCreditCard; dbExpenseReport.OwedToEmployee = expenseReport.OwedToEmployee; dbExpenseReport.Purpose = expenseReport.Purpose; dbExpenseReport.Status = expenseReport.Status; } db.SubmitChanges(); return dbExpenseReport.ExpenseReportId; } }
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; }
partial void UpdateExpenseReport(ExpenseReport instance);
partial void DeleteExpenseReport(ExpenseReport instance);
private void detach_ExpenseReports(ExpenseReport entity) { this.SendPropertyChanging(); entity.Employee = null; }
partial void InsertExpenseReport(ExpenseReport instance);
public void Create_ExpenseReport() { Employee employee = this.AddRandomEmployee(); Charge charge1 = this.AddRandomCharge(employee.EmployeeId); Charge charge2 = this.AddRandomCharge(employee.EmployeeId); Charge charge3 = this.AddRandomCharge(employee.EmployeeId); ExpenseReport expenseReport = new ExpenseReport() { Amount = 1, Approver = "2", CostCenter = 3, EmployeeId = employee.EmployeeId, Notes = "4", Purpose = "5", Status = 6, }; ExpenseService service = new ExpenseService(); service.SaveExpenseReport(expenseReport); Assert.AreNotEqual(0, expenseReport.ExpenseReportId); charge1.ExpenseReportId = expenseReport.ExpenseReportId; service.SaveCharge(charge1); charge2.ExpenseReportId = expenseReport.ExpenseReportId; service.SaveCharge(charge2); charge3.ExpenseReportId = expenseReport.ExpenseReportId; service.SaveCharge(charge3); List<Charge> charges = service.GetCharges(expenseReport.ExpenseReportId); Assert.AreEqual(3, charges.Count); Assert.AreEqual(charge1.ChargeId, charges[0].ChargeId); Assert.AreEqual(charge2.ChargeId, charges[1].ChargeId); Assert.AreEqual(charge3.ChargeId, charges[2].ChargeId); }