public static List <VacationType> GetVacationTypesList(int page) { int takeCount = Config.PageItemCount(); int skipCount = page * takeCount; return(VacationTypesRepositories.GetVacationTypesList(skipCount, takeCount).ToList()); }
public static bool IsRequestedVacationDaysValid(CreateEmployeeVacationModel model) { int vacationMaxDays = VacationTypesRepositories.GetVacationTypeById(model.EmployeeVacation.VacationTypeId).VacationLength; int userVacationDays = EmployeeVacationsRepositories.GetUserVacationDays(model.EmployeeVacation.EmployeeUserId, model.EmployeeVacation.VacationTypeId, model.EmployeeVacation.StartDate.Year); int remainingDaysOfVacation = vacationMaxDays - userVacationDays; return(model.EmployeeVacation.VacationDays <= remainingDaysOfVacation); }
public static CreateEmployeeVacationModel CreateEmployeeVacationRequest(int userId) { CreateEmployeeVacationModel model = new CreateEmployeeVacationModel(); model.EmployeeVacation = new EmployeeVacation() { EmployeeUserId = userId, StartDate = DateTimeHelper.Today(), EndDate = DateTimeHelper.Today() }; model.VacationTypesList = VacationTypesRepositories.GetVacationTypesExceptUnpaid(); return(model); }
public static void CreateEmployeeVacationRequest(CreateEmployeeVacationModel model) { model.Succeeded = false; if (model.EmployeeVacation.StartDate.Date.CompareTo(DateTimeHelper.Today().Date) < 0 && !model.IsAdmin) { model.ErrorMessage = "Start Date Must Not be Less than Today"; return; } if (model.EmployeeVacation.EndDate.Date.CompareTo(DateTimeHelper.Today().Date) < 0 && !model.IsAdmin) { model.ErrorMessage = "End Date Must be Greater than Today"; return; } if (model.EmployeeVacation.EndDate.CompareTo(model.EmployeeVacation.StartDate) < 0) { model.ErrorMessage = "End Date Must be Later than Start Date"; return; } if (model.EmployeeVacation.StartDate.Year != model.EmployeeVacation.EndDate.Year) { model.ErrorMessage = "End Date Must be in same Start Date Year."; return; } model.EmployeeVacation.StatusId = model.IsAdmin ? (int)EVacationStatus.Approved : (int)EVacationStatus.Pending; model.VacationTypesList = VacationTypesRepositories.GetVacationTypesExceptUnpaid(); model.EmployeeVacation.VacationDays = GetRequestedVacationDays(model.EmployeeVacation.StartDate, model.EmployeeVacation.EndDate); if (model.EmployeeVacation.VacationDays < 1) { model.ErrorMessage = "Requested Vacation Period is already Vacation in our system ;)."; return; } if (!IsRequestedVacationDaysValid(model)) { model.ErrorMessage = "Requested Vacation Days Must be less than Remaining Days Of This Vacation."; return; } if (IsVacationDaysTakenBefore(model)) { model.ErrorMessage = "There are days or part of them was requested before"; return; } EmployeeVacationsRepositories.InsertNewEmployeeVacation(model.EmployeeVacation); //EmailHelper.VacationSendEmail(model, SessionData.UserName); model.Succeeded = true; }
public static CreateWorkFromHomeRequest GetCreateWorkFromHomeRequest(bool isAdmin, int userId) { CreateWorkFromHomeRequest model = new CreateWorkFromHomeRequest() { EmployeeVacation = new EmployeeVacation(), RemainingDaysPerMonth = (int)WorkFromHomeDaysCount.MaxDaysPerMonth }; model.EmployeeVacation.EmployeeUserId = userId; model.EmployeeVacation.StartDate = DateTimeHelper.Today(); VacationType vacationType = VacationTypesRepositories.GetWorkFromHomeVacationType(); model.EmployeeVacation.VacationTypeId = vacationType.Id; model.EmployeeVacation.VacationDays = 1; model.EmployeeVacation.StatusId = isAdmin ? (int)EVacationStatus.Approved : (int)EVacationStatus.Pending; int totalTakenDaysPerYear = EmployeeVacationsRepositories.GetUserWorkFromHomeDaysPerYear(userId, vacationType.Id, DateTimeHelper.Today()); int vacationMaxDays = vacationType.VacationLength; model.RemainingDaysPerYear = vacationMaxDays - totalTakenDaysPerYear; if (model.RemainingDaysPerMonth < 1) { model.ErrorMessage = "Can not Take or Request more than " + vacationMaxDays + " Days Per Year."; return(model); } int totalTakenDaysPerMonth = EmployeeVacationsRepositories.GetUserWorkFromHomeDaysPerMonth(userId, vacationType.Id, DateTimeHelper.Today()); model.RemainingDaysPerMonth = (int)WorkFromHomeDaysCount.MaxDaysPerMonth - totalTakenDaysPerMonth; if (model.RemainingDaysPerMonth < 1) { model.ErrorMessage = "Can not Take or Request more than " + (int)WorkFromHomeDaysCount.MaxDaysPerMonth + " Days Per Month."; return(model); } model.Succeeded = true; return(model); }
public static CreateWorkFromHomeRequest InsertNewWrokFromHomeRequest(CreateWorkFromHomeRequest model) { model.Succeeded = false; model.EmployeeVacation.EndDate = model.EmployeeVacation.StartDate; if (model.EmployeeVacation.StartDate.Date.CompareTo(DateTimeHelper.Today().Date) < 0) { model.ErrorMessage = "Start Date Must Not be Less than Today."; return(model); } VacationType vacationType = VacationTypesRepositories.GetWorkFromHomeVacationType(); int totalTakenDaysPerYear = EmployeeVacationsRepositories.GetUserWorkFromHomeDaysPerYear(model.EmployeeVacation.EmployeeUserId, vacationType.Id, DateTimeHelper.Today()); int vacationMaxDays = vacationType.VacationLength; model.RemainingDaysPerYear = vacationMaxDays - totalTakenDaysPerYear; if (model.RemainingDaysPerMonth < 1) { model.ErrorMessage = "Can not Take or Request more than " + vacationMaxDays + " Days Per Year."; return(model); } int totalTakenDaysPerMonth = EmployeeVacationsRepositories.GetUserWorkFromHomeDaysPerMonth(model.EmployeeVacation.EmployeeUserId, vacationType.Id, DateTimeHelper.Today()); model.RemainingDaysPerMonth = (int)WorkFromHomeDaysCount.MaxDaysPerMonth - totalTakenDaysPerMonth; if (model.RemainingDaysPerMonth < 1) { model.ErrorMessage = "Can not Take or Request more than " + (int)WorkFromHomeDaysCount.MaxDaysPerMonth + " Days Per Month."; return(model); } if (EmployeeVacationsRepositories.IsWorkFromHomeDayTakenBefore(model.EmployeeVacation.StartDate, model.EmployeeVacation.EmployeeUserId, vacationType.Id)) { model.ErrorMessage = "You Request Work From Home at " + model.EmployeeVacation.StartDate.ToString("dd MMM yyyy") + ", Date before."; return(model); } EmployeeVacationsRepositories.InsertNewEmployeeVacation(model.EmployeeVacation); model.ErrorMessage = "Your Request Submit Successfully at " + model.EmployeeVacation.StartDate.ToString("dd MMM yyyy") + " Date."; model.Succeeded = true; return(model); }
public static List <EmployeeUsersDetails> GetEmployeesInVacationType(int vacationTypeId) { return(VacationTypesRepositories.GetEmployeesInVacationType(vacationTypeId)); }
public static void UpdateVacationType(VacationType vacationType) { VacationTypesRepositories.UpdateVacationType(vacationType); }
public static VacationType GetVacationTypeById(int?id) { return(VacationTypesRepositories.GetVacationTypeById(id)); }
public static void InsertVacationType(VacationType vacationType) { VacationTypesRepositories.InsertVacationType(vacationType); }
public static void DeleteVacationType(int id) { VacationTypesRepositories.DeleteVacationType(id); }