public void SaveDriverExpense() { var driverCost = 0.0; try { driverCost = Double.Parse(txtDriverCost.Text); } catch { } var driverExpenseId = -1; try { driverExpenseId = Int32.Parse(hidExpenseDriverId.Value); } catch { } var driverExpense = TransferRequestByDateBLL.ExpenseGetById(driverExpenseId); if (driverExpense == null) { driverExpense = new Expense(); } driverExpense.BusByDate = BusByDate; driverExpense.Name = txtDriverName.Text; driverExpense.Phone = txtDriverPhone.Text; driverExpense.Cost = driverCost; driverExpense.Type = "Drivers"; driverExpense.Date = Date.HasValue ? Date.Value : DateTime.Today; TransferRequestByDateBLL.ExpenseSaveOrUpdate(driverExpense); var expenseService = TransferRequestByDateBLL.ExpenseServiceGetByExpenseId(driverExpenseId); if (expenseService == null) { expenseService = new ExpenseService(); } var listCostType = TransferRequestByDateBLL.CostTypeGetAll().Future().ToList(); var expenseTypeNull = TransferRequestByDateBLL.ExpenseGetAllByCriterion(BusByDate.Date).Where(z => z.Type == null).FutureValue().Value; 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; TransferRequestByDateBLL.ExpenseServiceSaveOrUpdate(expenseService); BusByDate.Driver_Name = txtDriverName.Text; BusByDate.Driver_Phone = txtDriverPhone.Text; TransferRequestByDateBLL.BusByDateSaveOrUpdate(BusByDate); }