public Charge GetCharge(int chargeId)
        {
            AuthorizationCheck();

            var repo = new ExpensesRepository();
            return new Charge(repo.GetCharge(chargeId));
        }
        public void DeleteExpenseReport(int expenseReportId)
        {
            AuthorizationCheck();

            var repo = new ExpensesRepository();
            repo.DeleteExpenseReport(expenseReportId);
        }
        public Employee GetEmployee(string employeeAlias)
        {
            AuthorizationCheck();

            //Claim subject = ClaimsPrincipal.Current.FindFirst(ClaimTypes.Name);

            var repo = new ExpensesRepository();
            return new Employee(repo.GetEmployee(employeeAlias));
        }
        public int CreateNewExpenseReport(ExpenseReport expenseReport)
        {
            AuthorizationCheck();

            var repo = new ExpensesRepository();
            expenseReport.ExpenseReportId = 0;
            var dbExpenseReport = repo.SaveExpenseReport(new DbExpenseReport(expenseReport));

            return dbExpenseReport.ExpenseReportId;
        }
        public int CreateNewCharge(Charge charge)
        {
            AuthorizationCheck();

            var repo = new ExpensesRepository();
            charge.ChargeId = 0;
            var dbCharge = repo.SaveCharge(new DbCharge(charge));

            return dbCharge.ChargeId;
        }
        public ICollection<Charge> GetChargesForExpenseReport(int expenseReportId)
        {
            AuthorizationCheck();

            var repo = new ExpensesRepository();
            var expenseReport = repo.GetExpenseReport(expenseReportId);
            if (expenseReport == null)
            {
                throw new KeyNotFoundException("Unknown expenseReportId.");
            }
            var dbChargeCollection = expenseReport.Charges;
            return dbChargeCollection
                .Select((dbCharge) => new Charge(dbCharge))
                .ToList();
        }
        public static DbEmployee CreateNewDemoEmployee(string alias)
        {
            var repository = new ExpensesRepository();
            string managerAlias = "manager";

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

            DbEmployee employee =
                new DbEmployee()
                {
                    Alias = alias,
                    Manager = managerAlias,
                    Name = "New Employee"
                };

            employee = repository.SaveEmployee(employee);

            List<DbCharge> charges = new List<DbCharge>();

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId = employee.EmployeeId,
                BilledAmount = 200M,
                Description = "REF# 27438948",
                ExpenseDate = DateTime.Today.AddDays(-45),
                Location = "San Francisco, CA",
                Merchant = "Northwind Inn",
                Notes = string.Empty,
                TransactionAmount = 200M
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId = employee.EmployeeId,
                BilledAmount = 40,
                Description = "REF# 77384751",
                ExpenseDate = DateTime.Today.AddDays(-20),
                Location = "Seattle, WA",
                Merchant = "Contoso Taxi",
                Notes = string.Empty,
                TransactionAmount = 40
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId = employee.EmployeeId,
                BilledAmount = 67,
                Description = "REF# 33748563",
                ExpenseDate = DateTime.Today.AddDays(-8),
                Location = "Seattle, WA",
                Merchant = "Fourth Coffee",
                Notes = string.Empty,
                TransactionAmount = 12
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId = employee.EmployeeId,
                BilledAmount = 17,
                Description = "REF# 33748876",
                ExpenseDate = DateTime.Today.AddDays(-4),
                Location = "Seattle, WA",
                Merchant = "Fourth Coffee",
                Notes = string.Empty,
                TransactionAmount = 15
            });

            repository.SaveExpenseReport(new DbExpenseReport()
            {
                EmployeeId = employee.EmployeeId,
                Amount = 640M,
                Approver = managerAlias,
                CostCenter = 50992,
                DateSubmitted = DateTime.Today.AddDays(-7),
                Notes = (managerAlias == "rogreen") ? "Kim Akers" : "Visit to Blue Yonder Airlines",
                Status = DbExpenseReportStatus.Saved
            });

            DbExpenseReport report = new DbExpenseReport()
            {
                EmployeeId = employee.EmployeeId,
                Amount = 450M,
                Approver = managerAlias,
                CostCenter = 50992,
                DateSubmitted = DateTime.Today.AddDays(-7),
                Notes = (managerAlias == "rogreen") ? "Kim Akers" : "Visit to Tailspin Toys",
                Status = DbExpenseReportStatus.Saved
            };
            report = repository.SaveExpenseReport(report);

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId = employee.EmployeeId,
                ExpenseReportId = report.ExpenseReportId,
                BilledAmount = 350M,
                Description = "Airfare to San Francisco",
                ExpenseDate = DateTime.Today.AddDays(-60),
                Location = "Chicago, IL",
                Merchant = "Blue Yonder Airlines",
                Notes = string.Empty,
                TransactionAmount = 350M
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId = employee.EmployeeId,
                ExpenseReportId = report.ExpenseReportId,
                BilledAmount = 50,
                Description = "Cab from airport",
                ExpenseDate = DateTime.Today.AddDays(-45),
                Location = "San Francisco, CA",
                Merchant = "Contoso Taxi",
                Notes = string.Empty,
                TransactionAmount = 50
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId = employee.EmployeeId,
                ExpenseReportId = report.ExpenseReportId,
                BilledAmount = 50,
                Description = "Cab to airport",
                ExpenseDate = DateTime.Today.AddDays(-45),
                Location = "San Francisco, CA",
                Merchant = "Contoso Taxi",
                Notes = string.Empty,
                TransactionAmount = 50
            });

            // Add a year of every other month customer visits
            int x = -75;
            for (int i = 1; i <= 6; i++)
            {
                report = new DbExpenseReport()
                {
                    EmployeeId = employee.EmployeeId,
                    Amount = 850M,
                    Approver = managerAlias,
                    CostCenter = 50992,
                    DateSubmitted = DateTime.Today.AddDays(x - 5),
                    DateResolved = DateTime.Today.AddDays(x),
                    Notes = "Visit to Tailspin Toys",
                    Status = DbExpenseReportStatus.Approved,
                };
                repository.SaveExpenseReport(report);

                repository.SaveCharge(new DbCharge()
                {
                    EmployeeId = employee.EmployeeId,
                    ExpenseReportId = report.ExpenseReportId,
                    BilledAmount = 350M,
                    Description = "Airfare to Chicago",
                    ExpenseDate = DateTime.Today.AddDays(x - 15),
                    Location = "Chicago, IL",
                    Merchant = "Blue Yonder Airlines",
                    Notes = string.Empty,
                    TransactionAmount = 350M
                });

                repository.SaveCharge(new DbCharge()
                {
                    EmployeeId = employee.EmployeeId,
                    ExpenseReportId = report.ExpenseReportId,
                    BilledAmount = 50M,
                    Description = "Cab from airport",
                    ExpenseDate = DateTime.Today.AddDays(x - 5),
                    Location = "Chicago, IL",
                    Merchant = "Contoso Taxi",
                    Notes = string.Empty,
                    TransactionAmount = 50M
                });

                repository.SaveCharge(new DbCharge()
                {
                    EmployeeId = employee.EmployeeId,
                    ExpenseReportId = report.ExpenseReportId,
                    BilledAmount = 50M,
                    Description = "Cab to airport",
                    ExpenseDate = DateTime.Today.AddDays(x - 3),
                    Location = "Chicago, IL",
                    Merchant = "Contoso Taxi",
                    Notes = string.Empty,
                    TransactionAmount = 50M
                });

                repository.SaveCharge(new DbCharge()
                {
                    EmployeeId = employee.EmployeeId,
                    ExpenseReportId = report.ExpenseReportId,
                    BilledAmount = 400M,
                    Description = "2 nights hotel",
                    ExpenseDate = DateTime.Today.AddDays(x - 3),
                    Location = "Chicago, IL",
                    Merchant = "Northwind Inn",
                    Notes = string.Empty,
                    TransactionAmount = 400M
                });

                x -= 60;
            }

            // Add 18 months of cell phone charges
            x = -30;
            for (int i = 1; i <= 18; i++)
            {
                report = new DbExpenseReport()
                {
                    EmployeeId = employee.EmployeeId,
                    Amount = 850M,
                    Approver = managerAlias,
                    CostCenter = 50992,
                    DateSubmitted = DateTime.Today.AddDays(x - 5),
                    DateResolved = DateTime.Today.AddDays(x),
                    Notes = "Last month's cell phone",
                    Status = DbExpenseReportStatus.Approved,
                };
                repository.SaveExpenseReport(report);

                repository.SaveCharge(new DbCharge()
                {
                    EmployeeId = employee.EmployeeId,
                    ExpenseReportId = report.ExpenseReportId,
                    BilledAmount = 50M,
                    Description = "Cell phone bill",
                    ExpenseDate = DateTime.Today.AddDays(x - 10),
                    Location = "Seattle, WA",
                    Merchant = "The Phone Company",
                    Notes = string.Empty,
                    TransactionAmount = 50M
                });

                x -= 30;
            }

            return repository.GetEmployee(employee.EmployeeId);
        }
 /// <summary>
 /// Cleans up database by removing all records.
 /// </summary>
 public static void CleanRepository()
 {
     var repository = new ExpensesRepository();
     repository.CleanRepository();
 }
        public ICollection<ExpenseReport> GetExpenseReportsForEmployee(int employeeId)
        {
            AuthorizationCheck();

            var repo = new ExpensesRepository();
            var employee = repo.GetEmployee(employeeId);
            if (employee == null)
            {
                throw new KeyNotFoundException("Unknown employeeId.");
            }

            var dbExpenseReportCollection = employee.ExpenseReports;
            return dbExpenseReportCollection
                .Select((dbExpenseReport) => new ExpenseReport(dbExpenseReport))
                .ToList();
        }
        public ExpenseReport GetExpenseReport(int expenseReportId)
        {
            AuthorizationCheck();

            var repo = new ExpensesRepository();
            return new ExpenseReport(repo.GetExpenseReport(expenseReportId));
        }
        public ICollection<Charge> GetOutstandingChargesForEmployee(int employeeId)
        {
            AuthorizationCheck();

            var repo = new ExpensesRepository();
            var employee = repo.GetEmployee(employeeId);
            if (employee == null)
            {
                throw new KeyNotFoundException("Unknown employeeId.");
            }

            var dbChargeCollection = employee.Charges;
            return dbChargeCollection
                .Where((c) => !c.ExpenseReportId.HasValue)
                .Select((dbCharge) => new Charge(dbCharge))
                .ToList();
        }
Пример #12
0
        public static DbEmployee CreateNewDemoEmployee(string alias)
        {
            var    repository   = new ExpensesRepository();
            string managerAlias = "manager";

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

            DbEmployee employee =
                new DbEmployee()
            {
                Alias   = alias,
                Manager = managerAlias,
                Name    = "Kim Akers"
            };

            employee = repository.SaveEmployee(employee);

            List <DbCharge> charges = new List <DbCharge>();

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId        = employee.EmployeeId,
                BilledAmount      = 200M,
                Description       = "REF# 27438948",
                ExpenseDate       = DateTime.Today.AddDays(-45),
                Location          = "San Francisco, CA",
                Merchant          = "Northwind Inn",
                Notes             = string.Empty,
                TransactionAmount = 200M
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId        = employee.EmployeeId,
                BilledAmount      = 40,
                Description       = "REF# 77384751",
                ExpenseDate       = DateTime.Today.AddDays(-20),
                Location          = "Seattle, WA",
                Merchant          = "Contoso Taxi",
                Notes             = string.Empty,
                TransactionAmount = 40
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId        = employee.EmployeeId,
                BilledAmount      = 67,
                Description       = "REF# 33748563",
                ExpenseDate       = DateTime.Today.AddDays(-8),
                Location          = "Seattle, WA",
                Merchant          = "Fourth Coffee",
                Notes             = string.Empty,
                TransactionAmount = 12
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId        = employee.EmployeeId,
                BilledAmount      = 17,
                Description       = "REF# 33748876",
                ExpenseDate       = DateTime.Today.AddDays(-4),
                Location          = "Seattle, WA",
                Merchant          = "Fourth Coffee",
                Notes             = string.Empty,
                TransactionAmount = 15
            });

            DbExpenseReport reportBlueYonder = repository.SaveExpenseReport(new DbExpenseReport()
            {
                EmployeeId    = employee.EmployeeId,
                Amount        = 440M,
                Approver      = managerAlias,
                CostCenter    = 50992,
                DateSubmitted = DateTime.Today.AddDays(-7),
                Notes         = "Visit to Blue Yonder Airlines",
                Status        = DbExpenseReportStatus.Saved
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = reportBlueYonder.ExpenseReportId,
                BilledAmount      = 277M,
                Description       = "Lodging for 1 night",
                ExpenseDate       = DateTime.Today.AddDays(-10),
                Location          = "Baldwin City, KS",
                Merchant          = "Baldwin Inn",
                Notes             = string.Empty,
                TransactionAmount = 277M
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = reportBlueYonder.ExpenseReportId,
                BilledAmount      = 55M,
                Description       = "Business meal",
                ExpenseDate       = DateTime.Today.AddDays(-10),
                Location          = "Baldwin City, KS",
                Merchant          = "Parkside Bar and Grill",
                Notes             = string.Empty,
                TransactionAmount = 55M
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = reportBlueYonder.ExpenseReportId,
                BilledAmount      = 108M,
                Description       = "Supplies",
                ExpenseDate       = DateTime.Today.AddDays(-10),
                Location          = "Baldwin City, KS",
                Merchant          = "Office Depot",
                Notes             = string.Empty,
                TransactionAmount = 108M
            });

            DbExpenseReport reportTailspinToys = new DbExpenseReport()
            {
                EmployeeId    = employee.EmployeeId,
                Amount        = 450M,
                Approver      = managerAlias,
                CostCenter    = 50992,
                DateSubmitted = DateTime.Today.AddDays(-7),
                Notes         = "Visit to Tailspin Toys",
                Status        = DbExpenseReportStatus.Saved
            };

            reportTailspinToys = repository.SaveExpenseReport(reportTailspinToys);

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = reportTailspinToys.ExpenseReportId,
                BilledAmount      = 350M,
                Description       = "Airfare to San Francisco",
                ExpenseDate       = DateTime.Today.AddDays(-60),
                Location          = "Chicago, IL",
                Merchant          = "Blue Yonder Airlines",
                Notes             = string.Empty,
                TransactionAmount = 350M
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = reportTailspinToys.ExpenseReportId,
                BilledAmount      = 50,
                Description       = "Cab from airport",
                ExpenseDate       = DateTime.Today.AddDays(-45),
                Location          = "San Francisco, CA",
                Merchant          = "Contoso Taxi",
                Notes             = string.Empty,
                TransactionAmount = 50
            });

            repository.SaveCharge(new DbCharge()
            {
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = reportTailspinToys.ExpenseReportId,
                BilledAmount      = 50,
                Description       = "Cab to airport",
                ExpenseDate       = DateTime.Today.AddDays(-45),
                Location          = "San Francisco, CA",
                Merchant          = "Contoso Taxi",
                Notes             = string.Empty,
                TransactionAmount = 50
            });

            // Add a year of every other month customer visits
            int x = -75;

            for (int i = 1; i <= 6; i++)
            {
                reportTailspinToys = new DbExpenseReport()
                {
                    EmployeeId    = employee.EmployeeId,
                    Amount        = 850M,
                    Approver      = managerAlias,
                    CostCenter    = 50992,
                    DateSubmitted = DateTime.Today.AddDays(x - 5),
                    DateResolved  = DateTime.Today.AddDays(x),
                    Notes         = "Visit to Tailspin Toys",
                    Status        = DbExpenseReportStatus.Approved,
                };
                repository.SaveExpenseReport(reportTailspinToys);

                repository.SaveCharge(new DbCharge()
                {
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = reportTailspinToys.ExpenseReportId,
                    BilledAmount      = 350M,
                    Description       = "Airfare to Chicago",
                    ExpenseDate       = DateTime.Today.AddDays(x - 15),
                    Location          = "Chicago, IL",
                    Merchant          = "Blue Yonder Airlines",
                    Notes             = string.Empty,
                    TransactionAmount = 350M
                });

                repository.SaveCharge(new DbCharge()
                {
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = reportTailspinToys.ExpenseReportId,
                    BilledAmount      = 50M,
                    Description       = "Cab from airport",
                    ExpenseDate       = DateTime.Today.AddDays(x - 5),
                    Location          = "Chicago, IL",
                    Merchant          = "Contoso Taxi",
                    Notes             = string.Empty,
                    TransactionAmount = 50M
                });

                repository.SaveCharge(new DbCharge()
                {
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = reportTailspinToys.ExpenseReportId,
                    BilledAmount      = 50M,
                    Description       = "Cab to airport",
                    ExpenseDate       = DateTime.Today.AddDays(x - 3),
                    Location          = "Chicago, IL",
                    Merchant          = "Contoso Taxi",
                    Notes             = string.Empty,
                    TransactionAmount = 50M
                });

                repository.SaveCharge(new DbCharge()
                {
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = reportTailspinToys.ExpenseReportId,
                    BilledAmount      = 400M,
                    Description       = "2 nights hotel",
                    ExpenseDate       = DateTime.Today.AddDays(x - 3),
                    Location          = "Chicago, IL",
                    Merchant          = "Northwind Inn",
                    Notes             = string.Empty,
                    TransactionAmount = 400M
                });

                x -= 60;
            }

            // Add 18 months of cell phone charges
            x = -30;
            for (int i = 1; i <= 18; i++)
            {
                reportTailspinToys = new DbExpenseReport()
                {
                    EmployeeId    = employee.EmployeeId,
                    Amount        = 850M,
                    Approver      = managerAlias,
                    CostCenter    = 50992,
                    DateSubmitted = DateTime.Today.AddDays(x - 5),
                    DateResolved  = DateTime.Today.AddDays(x),
                    Notes         = "Last month's cell phone",
                    Status        = DbExpenseReportStatus.Approved,
                };
                repository.SaveExpenseReport(reportTailspinToys);

                repository.SaveCharge(new DbCharge()
                {
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = reportTailspinToys.ExpenseReportId,
                    BilledAmount      = 50M,
                    Description       = "Cell phone bill",
                    ExpenseDate       = DateTime.Today.AddDays(x - 10),
                    Location          = "Seattle, WA",
                    Merchant          = "The Phone Company",
                    Notes             = string.Empty,
                    TransactionAmount = 50M
                });

                x -= 30;
            }

            return(repository.GetEmployee(employee.EmployeeId));
        }
Пример #13
0
        /// <summary>
        /// Cleans up database by removing all records.
        /// </summary>
        public static void CleanRepository()
        {
            var repository = new ExpensesRepository();

            repository.CleanRepository();
        }
Пример #14
0
        public static IEnumerable<DbExpense> CreateDefaultExpenses()
        {
            var repository = new ExpensesRepository();
            DbExpense expense = new DbExpense()
                {
                    Category = "Hardware",
                    Description = "Hardware Expenses",
                    ExpenseAmount = 12.20M,
                    ExpenseDate = DateTime.Now,
                    DateModified = DateTime.Now,
                    DateCreated = DateTime.Now,
                    SubCategory = "RAM",
                    UserCreated = "sthunga",
                    UserModified = "sthunga"

                };
            expense = repository.SaveExpense(expense);

            DbExpense expense1 = new DbExpense()
            {
                Category = "Hardware",
                Description = "Hardware Expenses",
                ExpenseAmount = 20.00M,
                ExpenseDate = DateTime.Now,
                DateModified = DateTime.Now,
                DateCreated = DateTime.Now,
                SubCategory = "Monitor",
                UserCreated = "User55",
                UserModified = "User55"

            };
            repository.SaveExpense(expense1);

            DbExpense expense2 = new DbExpense()
            {
                Category = "Software",
                Description = "Software Expenses",
                ExpenseAmount = 100.20M,
                ExpenseDate = DateTime.Now,
                DateModified = DateTime.Now,
                DateCreated = DateTime.Now,
                SubCategory = "OS",
                UserCreated = "sthunga",
                UserModified = "sthunga"

            };
            repository.SaveExpense(expense2);

            DbExpense expense3 = new DbExpense()
            {
                Category = "Software",
                Description = "Software Expenses",
                ExpenseAmount = 302.0M,
                ExpenseDate = DateTime.Now,
                DateModified = DateTime.Now,
                DateCreated = DateTime.Now,
                SubCategory = "Maya",
                UserCreated = "sthunga",
                UserModified = "sthunga"

            };
            repository.SaveExpense(expense3);

            DbExpense expense4 = new DbExpense()
            {
                Category = "Food",
                Description = "Miscellaneous Expenses",
                ExpenseAmount = 30.02M,
                ExpenseDate = DateTime.Now,
                DateModified = DateTime.Now,
                DateCreated = DateTime.Now,
                SubCategory = "Lunch",
                UserCreated = "User2",
                UserModified = "User2"

            };
            repository.SaveExpense(expense4);

            return repository.GetExpenses();
        }