public IHttpActionResult GetMyVacation() { return(Ok(VacationRepository .Where(x => x.EmployeeId == CurrentUser.Id) .Where(x => x.Status == VacationStatus.Approved || x.Status == VacationStatus.Pending) .AsDto())); }
public IHttpActionResult GetPendingVacations() { return(Ok(VacationRepository .Where(x => x.Status == VacationStatus.Pending) .OrderBy(x => x.StartDate) .AsDto())); }
public IHttpActionResult GetVacations(DateTime date) { var startRange = new DateTime(date.Year, date.Month, 1); var endRange = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month), 23, 59, 59); return(Ok(VacationRepository .Where(x => x.StartDate <= endRange && startRange <= x.EndDate) .Where(x => x.Status == VacationStatus.Approved || x.Status == VacationStatus.Retired) .AsDto())); }
public virtual ActionResult Index() { if (User.Identity.IsAuthenticated) { if (!CurrentUser.IsInitialized) { return(View(MVC.Home.Views.Initial, new ChangeAccountSettingsViewModel { Phone = CurrentUser.PhoneNumber })); } var employees = EmployeeRepository .Where(x => x.Birthdate.HasValue) .Where(x => x.Birthdate.Value.Month == DateTime.Now.Month && x.Birthdate.Value.Day == DateTime.Now.Day) .AsDto(); var vacations = VacationRepository .Where(x => x.StartDate.Month == DateTime.Now.Month || x.EndDate.Month == DateTime.Now.Month) .Where(x => x.Status == VacationStatus.Approved) .OrderBy(x => x.StartDate) .Select(x => new EmployeeVacationModel() { EmployeeName = x.Employee.Name, StartDate = x.StartDate, EndDate = x.EndDate }) .ToList(); return(View(new IndexViewModel() { Employees = employees, Vacations = vacations })); } else { return(View(MVC.Home.Views.Public)); } }
public IHttpActionResult SetVacation(VacationModel model) { var id = CurrentUserId; var currentUserVacations = VacationRepository.Where(x => x.EmployeeId == id && x.StartDate.Year == DateTime.Now.Year && x.Status == VacationStatus.Declined && x.Status != VacationStatus.Retired) .Select(x => x.Days) .ToList(); int days = (int)model.End.Subtract(model.Start).TotalDays + 1; if (model.Start > model.End) { return(BadRequest("ERROR: Puhkuse lõpp on enne puhkuse algust")); } var employee = EmployeeRepository.First(x => x.Id == id); if (employee.VacationDays - days < 0) { return(BadRequest("ERROR: Pole piisavalt kasutamata puhkusepäevi")); } if (model.Comment?.Length > 250) { return(BadRequest("ERROR: Lisainfo väljal ei tohi olla rohkem kui 250 tähemärki")); } int[] vacationLimits = new int[] { 1, 2, 3, 4, 5, 6, 7, 14 }; int[][] specificVacationLimits = new int[][] { new int[] { 14, 1 }, new int[] { 7, 1 } }; if (vacationLimits.Contains(days)) { foreach (var limit in specificVacationLimits) { if (currentUserVacations.Where(x => x == limit[0]).Count() >= limit[1] && days == limit[0]) { return(BadRequest($"ERROR: Aastas on lubatud ainult {limit[1]} puhkus pikkusega {limit[0]} päeva.")); } } employee.VacationDays -= days; EmployeeRepository.SaveOrUpdate(employee); EmployeeRepository.Commit(); var vacation = new Vacation() { StartDate = model.Start, EndDate = model.End, Status = VacationStatus.Pending, EmployeeId = id, Days = days, Comments = model.Comment }; VacationRepository.AddIfNew(vacation); VacationRepository.Commit(); var emails = EmployeeRepository.Where(x => x.VacationMessages == true && x.Role.Rights.HasFlag(AccessRights.Vacations)).Select(x => x.Email).ToList(); EmailService.VacationRequested(vacation, emails); return(Ok()); } return(BadRequest("ERROR: Valitud puhkuse pikkus ei vasta eeskirjadele, lubatud on üks 14 päevane puhkus, üks 7 päevane puhkus ja ülejäänud puhkused on lühemad kui 7 päeva")); }
public IHttpActionResult GetConfirmedVacations() { return(Ok(VacationRepository .Where(x => x.Status == VacationStatus.Approved && x.EndDate > DateTime.Now) .AsDto())); }
public virtual async Task <ActionResult> InitializeAccount(ChangeAccountSettingsViewModel model) { if (EmployeeRepository.SingleOrDefault(x => x.Id == CurrentUserId) != null) { var employee = EmployeeRepository.First(x => x.Id == CurrentUser.Id); employee.PhoneNumber = model.Phone; employee.MonthlyBirthdayMessages = model.MonthlyBirthdayMessages; employee.DailyBirthdayMessages = model.DailyBirthdayMessages; employee.RequestMessages = model.RequestMessages; employee.VacationMessages = model.VacationMessages; employee.Skype = model.Skype; employee.SocialSecurityID = model.SocialSecurityID; employee.IsInitialized = true; if (model.BirthDay != null) { employee.Birthdate = model.BirthDay; } EmployeeRepository.SaveOrUpdate(employee); EmployeeRepository.Commit(); } else { IPagedCollection <IUser> result = await ADService.GetUsers(); IUser user = result.CurrentPage.Single(x => x.ObjectId == CurrentUserId); var defaultRole = RoleRepository.Single(x => x.Name == "User"); var employee = new Employee() { Id = user.ObjectId, Name = user.DisplayName, Email = user.Mail, Role = defaultRole, PhoneNumber = model.Phone, IsInitialized = true, VacationDays = 28, VacationMessages = model.VacationMessages, RequestMessages = model.RequestMessages, MonthlyBirthdayMessages = model.MonthlyBirthdayMessages, DailyBirthdayMessages = model.DailyBirthdayMessages, Birthdate = model.BirthDay, Skype = model.Skype, SocialSecurityID = model.SocialSecurityID }; EmployeeRepository.Add(employee); EmployeeRepository.Commit(); } var employees = EmployeeRepository .Where(x => x.Birthdate.HasValue) .Where(x => x.Birthdate.Value.Month == DateTime.Now.Month && x.Birthdate.Value.Day == DateTime.Now.Day) .AsDto(); var vacations = VacationRepository .Where(x => x.StartDate.Month == DateTime.Now.Month || x.EndDate.Month == DateTime.Now.Month) .Where(x => x.Status == VacationStatus.Approved) .OrderBy(x => x.StartDate) .Select(x => new EmployeeVacationModel() { EmployeeName = x.Employee.Name, StartDate = x.StartDate, EndDate = x.EndDate }) .ToList(); return(View(MVC.Home.Views.Index, new IndexViewModel() { Employees = employees, Vacations = vacations })); }