public ActionResult WorkFromHomeRequest(CreateWorkFromHomeRequest model) { try { if (!model.Succeeded) { return(RedirectToAction("WorkFromHomeRequest")); } EmployeeVacationsLogic.InsertNewWrokFromHomeRequest(model); ModelState.AddModelError("ErrorMessage", model.ErrorMessage); } catch (Exception e) { LogsLogic.InsertLog(new Log() { Message = e.Message, StackTrace = e.StackTrace, StoryName = "ManagementProject/EmployeeVacations/WorkFromHomeRequest(Post)", }); } return(PartialView(model)); }
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 ActionResult WorkFromHomeRequest() { CreateWorkFromHomeRequest model = new CreateWorkFromHomeRequest(); try { bool isAdmin = SessionData.UserRole == UserRoles.Admin ? true : false; model = EmployeeVacationsLogic.GetCreateWorkFromHomeRequest(isAdmin, SessionData.UserId); if (!model.Succeeded) { ModelState.AddModelError("ErrorMessage", model.ErrorMessage); } } catch (Exception e) { LogsLogic.InsertLog(new Log() { Message = e.Message, StackTrace = e.StackTrace, StoryName = "ManagementProject/EmployeeVacations/WorkFromHomeRequest(Get)", }); } return(PartialView(model)); }