/// <summary> /// Save /// </summary> public void SaveForEdit(double newTakenDays) { VacationsInformationTDS vacationsInformationChanges = (VacationsInformationTDS)Data.GetChanges(); if (vacationsInformationChanges.RequestsInformation.Rows.Count > 0) { VacationsInformationRequestsInformationGateway vacationsInformationRequestsInformationGateway = new VacationsInformationRequestsInformationGateway(vacationsInformationChanges); foreach (VacationsInformationTDS.RequestsInformationRow row in (VacationsInformationTDS.RequestsInformationDataTable)vacationsInformationChanges.RequestsInformation) { int requestId = row.RequestID; int employeeId = row.EmployeeID; bool deleted = row.Deleted; int companyId = row.COMPANY_ID; // original values DateTime originalStartDate = vacationsInformationRequestsInformationGateway.GetStartDateOriginal(requestId); DateTime originalEndDate = vacationsInformationRequestsInformationGateway.GetEndDateOriginal(requestId); double originalTotalPaidVacationDays = vacationsInformationRequestsInformationGateway.GetTotalPaidVacationDaysOriginal(requestId); string originalState = vacationsInformationRequestsInformationGateway.GetStateOriginal(requestId); string originalComments = vacationsInformationRequestsInformationGateway.GetCommentsOriginal(requestId); string originalDetails = vacationsInformationRequestsInformationGateway.GetDetailsOriginal(requestId); string originalRejectReason = vacationsInformationRequestsInformationGateway.GetRejectReasonOriginal(requestId); string originalCancelReason = vacationsInformationRequestsInformationGateway.GetCancelReasonOriginal(requestId); bool originalDeleted = vacationsInformationRequestsInformationGateway.GetDeletedOriginal(requestId); // new values DateTime newStartDate = vacationsInformationRequestsInformationGateway.GetStartDate(requestId); DateTime newEndDate = vacationsInformationRequestsInformationGateway.GetEndDate(requestId); double newTotalPaidVacationDays = vacationsInformationRequestsInformationGateway.GetTotalPaidVacationDays(requestId); string newState = vacationsInformationRequestsInformationGateway.GetState(requestId); string newComments = vacationsInformationRequestsInformationGateway.GetComments(requestId); string newDetails = vacationsInformationRequestsInformationGateway.GetDetails(requestId); string newRejectReason = vacationsInformationRequestsInformationGateway.GetRejectReason(requestId); string newCancelReason = vacationsInformationRequestsInformationGateway.GetCancelReason(requestId); bool newDeleted = vacationsInformationRequestsInformationGateway.GetDeleted(requestId); VacationsEmployeeMaxPaidVacations vacationsEmployeeMaxPaidVacations = new VacationsEmployeeMaxPaidVacations(); vacationsEmployeeMaxPaidVacations.UpdateTotalTakenVacationDays(row.StartDate.Year, row.EmployeeID, newTakenDays); VacationRequests vacationRequests = new VacationRequests(null); vacationRequests.UpdateDirect(requestId, employeeId, originalStartDate, originalEndDate, originalTotalPaidVacationDays, originalState, originalComments, originalDetails, originalRejectReason, originalCancelReason, originalDeleted, companyId, requestId, employeeId, newStartDate, newEndDate, newTotalPaidVacationDays, newState, newComments, newDetails, newRejectReason, newCancelReason, newDeleted, companyId); } } }
/// <summary> /// Save /// </summary> public void Save() { VacationsInformationTDS vacationsInformationChanges = (VacationsInformationTDS)Data.GetChanges(); if (vacationsInformationChanges.RequestsInformation.Rows.Count > 0) { VacationsInformationRequestsInformationGateway vacationsInformationRequestsInformationGateway = new VacationsInformationRequestsInformationGateway(vacationsInformationChanges); foreach (VacationsInformationTDS.RequestsInformationRow row in (VacationsInformationTDS.RequestsInformationDataTable)vacationsInformationChanges.RequestsInformation) { int requestId = row.RequestID; int employeeId = row.EmployeeID; bool deleted = row.Deleted; int companyId = row.COMPANY_ID; // original values DateTime originalStartDate = vacationsInformationRequestsInformationGateway.GetStartDateOriginal(requestId); DateTime originalEndDate = vacationsInformationRequestsInformationGateway.GetEndDateOriginal(requestId); double originalTotalPaidVacationDays = vacationsInformationRequestsInformationGateway.GetTotalPaidVacationDaysOriginal(requestId); string originalState = vacationsInformationRequestsInformationGateway.GetStateOriginal(requestId); string originalComments = vacationsInformationRequestsInformationGateway.GetCommentsOriginal(requestId); string originalDetails = vacationsInformationRequestsInformationGateway.GetDetailsOriginal(requestId); string originalRejectReason = vacationsInformationRequestsInformationGateway.GetRejectReasonOriginal(requestId); string originalCancelReason = vacationsInformationRequestsInformationGateway.GetCancelReasonOriginal(requestId); // new values DateTime newStartDate = vacationsInformationRequestsInformationGateway.GetStartDate(requestId); DateTime newEndDate = vacationsInformationRequestsInformationGateway.GetEndDate(requestId); double newTotalPaidVacationDays = vacationsInformationRequestsInformationGateway.GetTotalPaidVacationDays(requestId); string newState = vacationsInformationRequestsInformationGateway.GetState(requestId); string newComments = vacationsInformationRequestsInformationGateway.GetComments(requestId); string newDetails = vacationsInformationRequestsInformationGateway.GetDetails(requestId); string newRejectReason = vacationsInformationRequestsInformationGateway.GetRejectReason(requestId); string newCancelReason = vacationsInformationRequestsInformationGateway.GetCancelReason(requestId); if (newState == "Rejected" || newState == "Cancelled") { VacationsInformationBasicInformationGateway vacationsInformationBasicInformationGateway = new VacationsInformationBasicInformationGateway(); vacationsInformationBasicInformationGateway.LoadByEmployeeIdYear(employeeId, originalStartDate.Year, companyId); double oldTotalTakenVacationDays = vacationsInformationBasicInformationGateway.GetTotalVacationDays(employeeId, originalStartDate.Year) - vacationsInformationBasicInformationGateway.GetRemainingPayVacationDays(employeeId, originalStartDate.Year); VacationsEmployeeMaxPaidVacations vacationsEmployeeMaxPaidVacations = new VacationsEmployeeMaxPaidVacations(); double newTotalTakenVacationDays = oldTotalTakenVacationDays - originalTotalPaidVacationDays; vacationsEmployeeMaxPaidVacations.UpdateTotalTakenVacationDays(row.StartDate.Year, row.EmployeeID, newTotalTakenVacationDays); } else { if (originalState == newState) { VacationsInformationBasicInformationGateway vacationsInformationBasicInformationGateway = new VacationsInformationBasicInformationGateway(); vacationsInformationBasicInformationGateway.LoadByEmployeeIdYear(employeeId, originalStartDate.Year, companyId); double oldTotalTakenVacationDays = vacationsInformationBasicInformationGateway.GetTotalVacationDays(employeeId, originalStartDate.Year) - vacationsInformationBasicInformationGateway.GetRemainingPayVacationDays(employeeId, originalStartDate.Year); VacationsEmployeeMaxPaidVacations vacationsEmployeeMaxPaidVacations = new VacationsEmployeeMaxPaidVacations(); double newTotalTakenVacationDays = oldTotalTakenVacationDays + newTotalPaidVacationDays; vacationsEmployeeMaxPaidVacations.UpdateTotalTakenVacationDays(row.StartDate.Year, row.EmployeeID, newTotalTakenVacationDays); } } VacationRequests vacationRequests = new VacationRequests(null); vacationRequests.UpdateDirect(requestId, employeeId, originalStartDate, originalEndDate, originalTotalPaidVacationDays, originalState, originalComments, originalDetails, originalRejectReason, originalCancelReason, deleted, companyId, requestId, employeeId, newStartDate, newEndDate, newTotalPaidVacationDays, newState, newComments, newDetails, newRejectReason, newCancelReason, deleted, companyId); } } }
private void SendMailEmployee(string newState) { if (newState == "Rejected") { // Update grid rows foreach (GridViewRow row in grdVacations.Rows) { int requestId = Int32.Parse(grdVacations.DataKeys[row.RowIndex].Values["RequestID"].ToString()); if (((CheckBox)row.FindControl("cbxSelected")).Checked) { string rejectReason = ((TextBox)row.FindControl("tbxRejectReason")).Text; // Get mail information string mailTo = ""; string nameTo = ""; string body = ""; string subject = ""; VacationsInformationRequestsInformationGateway vacationsInformationRequestsInformationGateway = new VacationsInformationRequestsInformationGateway(vacationsInformationTDS); int employeeId = vacationsInformationRequestsInformationGateway.GetEmployeeID(requestId); int rejectedById = (int)ViewState["rejected_by_id"]; EmployeeGateway employeesGateway = new EmployeeGateway(); employeesGateway.LoadByEmployeeId(employeeId); if (employeesGateway.Table.Rows.Count > 0) { // Assigned TeamMember mailTo = employeesGateway.GetEMail(employeeId); nameTo = employeesGateway.GetFirstName(employeeId) + " " + employeesGateway.GetLastName(employeeId); } subject = "Vacation request from " + vacationsInformationRequestsInformationGateway.GetStartDate(requestId).ToShortDateString() + " to " + vacationsInformationRequestsInformationGateway.GetEndDate(requestId).ToShortDateString(); // Mails body body = body + "\nHi " + nameTo + ",\n\nThe following vacation request has been rejected: \n\n"; body = body + "\t - Vacation request from " + vacationsInformationRequestsInformationGateway.GetStartDate(requestId).ToShortDateString() + " to " + vacationsInformationRequestsInformationGateway.GetEndDate(requestId).ToShortDateString() + "\n"; body = body + "\t - Detail: " + vacationsInformationRequestsInformationGateway.GetDetails(requestId) + "\n"; body = body + "\t - Comment: " + rejectReason; EmployeeGateway employeeRejected = new EmployeeGateway(); employeeRejected.LoadByEmployeeId(rejectedById); if (employeeRejected.Table.Rows.Count > 0) { body = body + "\n" + "\t - Rejected by: " + employeeRejected.GetFirstName(rejectedById) + " " + employeeRejected.GetLastName(rejectedById); } //Send Mail SendMail(mailTo, subject, body); } } } }