public ActionResult CreateExpense(ExpenseFormViewModel expenseForm)
        {
            if (ModelState.IsValid)
            {
                ExpenseReport expenseReport = new ExpenseReport();

                expenseForm.ExpenseItem.AudAmount = currencyService.CalcAud(expenseForm.ExpenseItem.Amount, expenseForm.ExpenseItem.Currency);

                expenseForm.ExpenseItem.ReceiptFileName = fileUploader.Upload(expenseForm.ReceiptFile);

                //check if the session is valid if valid add new items to existing session else create a new report session
                if (Session["_expenseReport"] != null)
                {
                    expenseReport = (ExpenseReport)Session["_expenseReport"];
                    expenseReport.ExpenseItems.Add(expenseForm.ExpenseItem);
                    Session["_expenseReport"] = expenseReport;
                }
                else
                {
                    expenseReport.ExpenseItems.Add(expenseForm.ExpenseItem);
                    Session["_expenseReport"] = expenseReport;
                }

                expenseForm.ExpenseReport = expenseReport;
                expenseForm.ExpenseItem = new ExpenseItem();
                ModelState.Clear();

                return View("CreateExpense", expenseForm);
            }
            else
            {
                return PartialView(expenseForm);
            }
        }
        /// <summary>
        /// This controllers initializes the expense form
        /// </summary>
        /// <returns>returns create expense view</returns>
        public ActionResult CreateExpense()
        {
            ExpenseFormViewModel expenseForm = new ExpenseFormViewModel();
            ExpenseReport expenseReport = new ExpenseReport();

            expenseReport.CreateDate = DateTime.Now;
            expenseReport.CreatedBy = employee;
            expenseReport.Department = employee.Department;

            Session["_expenseReport"] = expenseReport;

            expenseForm.ExpenseReport = expenseReport;
            TempData["msg"] = "There are currently no expense items";
            return View("CreateExpense", expenseForm);
        }
        public void Consultant_CreateExpense_CheckInitialExpenseReportIsInitialized()
        {
            //Arrange
            ConsultantController controller = new ConsultantController(mockEmployeeService, mockReportService, mockEmployee);
            MockHttpContext.SetFakeHttpContext(controller);

            ExpenseReport expenseReport = new ExpenseReport();

            expenseReport.CreateDate = DateTime.Now;
            expenseReport.CreatedBy = mockEmployee;
            expenseReport.Department = mockEmployee.Department;

            Assert.AreEqual(expenseReport.CreatedBy, mockEmployee, "The createby employee is not equal");
            Assert.AreEqual(String.Format("{0:dd/mm/yyyy}",expenseReport.CreateDate),String.Format("{0:dd/mm/yyyy}",DateTime.Now), "Create date is not same");
            Assert.AreEqual(expenseReport.Department, mockEmployee.Department, "Expense department is not equal to employee department");
        }
 public void CreateExpenseReport(ExpenseReport report)
 {
 }
 /// <summary>
 /// Inserts a new Expense report into the ReportDAL
 /// </summary>
 /// <param name="report">expense report object</param>
 public void CreateExpenseReport(ExpenseReport report)
 {
     reportDAL.InsertExpenseReport(report);
 }
        public void InsertExpenseReport(ExpenseReport report)
        {
            using (EMEntitiesContext ctx = new EMEntitiesContext())
            {
                ExpenseReport newReport = new ExpenseReport();

                newReport.CreatedBy = ctx.Employees.First(e => e.UserId == report.CreatedBy.UserId);
                newReport.CreateDate = report.CreateDate;
                newReport.Department = ctx.Departments.First(d => d.DepartmentId == report.Department.DepartmentId);
                newReport.Status = ReportStatus.Submitted.ToString();
                newReport.ExpenseItems = report.ExpenseItems;

                ctx.ExpenseReports.Add(newReport);
                ctx.SaveChanges();
            }
        }
        public void Consultant_CreateExpense_ViewData_ExpenseFormViewModal()
        {
            //Arrange
            ConsultantController controller = new ConsultantController(mockEmployeeService, mockReportService, mockEmployee);
            MockHttpContext.SetFakeHttpContext(controller);

            ExpenseFormViewModel model = new ExpenseFormViewModel();
            model.ExpenseItem = new ExpenseItem();
            ExpenseReport expenseReport = new ExpenseReport();

            expenseReport.CreateDate = DateTime.Now;
            expenseReport.CreatedBy = mockEmployee;
            expenseReport.Department = mockEmployee.Department;

            model.ExpenseReport = expenseReport;

            //Act
            var result = controller.CreateExpense(model) as ViewResult;

            //Assert
            Assert.AreEqual(model, (ExpenseFormViewModel)result.ViewData.Model, "The view model sent is not the same as what was intialized");
            Assert.IsNotNull((ExpenseFormViewModel)result.ViewData.Model, "The resulting view modal is null");
        }
 public ExpenseFormViewModel()
 {
     ExpenseReport = new ExpenseReport();
     remainBudgetCompany = 3000; // John
 }