public BusByDateRepository(ISession session) : base(session) { RouteRepository = new RouteRepository(); ExpenseRepository = new ExpenseRepository(); CostTypeRepository = new CostTypeRepository(); ExpenseServiceRepository = new ExpenseServiceRepository(); }
public override void SaveOrUpdate(BusByDate busByDate) { if (busByDate == null) { return; } var createOrUpdate = ""; if (busByDate.Id <= 0) { createOrUpdate = "Create"; } else { createOrUpdate = "Update"; } var busByDateRouteBackRef = busByDate.BusByDateRouteBackRef; if (busByDateRouteBackRef != null) { busByDateRouteBackRef.Guide = busByDate.Guide; busByDateRouteBackRef.Group = busByDate.Group; base.SaveOrUpdate(busByDateRouteBackRef); } base.SaveOrUpdate(busByDate); if (createOrUpdate == "Create") { var driverExpense = new Expense() { BusByDate = busByDate, Type = "Drivers", Date = busByDate.Date.Value, }; ExpenseRepository.SaveOrUpdate(driverExpense); var listCostType = CostTypeRepository.CostTypeGetAll().Future().ToList(); var expenseTypeNull = ExpenseRepository.ExpenseGetAllByCriterion(-1, busByDate.Date).Where(z => z.Type == null).FutureValue().Value; var expenseService = ExpenseServiceRepository.ExpenseServiceGetAllByCriterion(driverExpense.Id).FutureValue().Value; if (expenseService == null || expenseService.Id <= 0) { expenseService = new ExpenseService(); } expenseService.Cost = driverExpense.Cost; expenseService.Name = driverExpense.BusByDate != null ? driverExpense.BusByDate.Driver_Name : ""; expenseService.Type = listCostType.Where(z => z.Name == "Driver").FirstOrDefault(); expenseService.Expense = expenseTypeNull; expenseService.ExpenseIdRef = driverExpense.Id; ExpenseServiceRepository.SaveOrUpdate(expenseService); } }
public new void Dispose() { if (RouteRepository != null) { RouteRepository.Dispose(); RouteRepository = null; } if (ExpenseRepository != null) { ExpenseRepository.Dispose(); ExpenseRepository = null; } if (CostTypeRepository != null) { CostTypeRepository.Dispose(); CostTypeRepository = null; } if (ExpenseServiceRepository != null) { ExpenseServiceRepository.Dispose(); ExpenseServiceRepository = null; } base.Dispose(); }