public object FindById(int id)
        {
            Holiday pom = new Holiday();
            pom = dataContext.Holidays.Find(id);

            return pom;
        }
 public void EditHoliday(Holiday h)
 {
     Holiday oldHoliday = dataContext.Holidays.Find(h.HolidayId);
     if(oldHoliday!=null)
      dataContext.Entry(oldHoliday).CurrentValues.SetValues(h);
     dataContext.SaveChanges();
 }
        public ActionResult EditHoliday(Holiday h)
        {
            if (h.DateFrom == h.DateTo)
            {
                return RedirectToAction("initHolidays");
            }

            bool overlap = false;
            Holiday overlapingHoliday = new Holiday();

            foreach (Holiday holiday in db.GetHolidays())
            {
                if (holiday.HolidayId == h.HolidayId)
                    continue;

                if (h.DateFrom < holiday.DateTo && holiday.DateFrom < h.DateTo)
                {
                    overlap = true;
                    break;
                }
                else
                {
                    overlap = false;
                }
            }

            if (!overlap)
            {
                if (h.DateFrom <= h.DateTo)
                {
                    Holiday oldHoliday = (Holiday)db.FindById(h.HolidayId);
                    revertOldVacationDays(oldHoliday);
                    db.EditHoliday(h);
                    changeVacationDays(h);
                }
                else
                {
                    ViewBag.errorMessage = "Date from can't be greater that date to.";
                }
            }
            else
            {
                Console.WriteLine("PREKLAPANJE!!!");
            }

            return RedirectToAction("initHolidays");
        }
        public ActionResult AddHoliday(Holiday h)
        {
            bool overlap = false;
            Holiday overlapingHoliday = new Holiday();

            if (h.DateFrom == h.DateTo)
            {
                return RedirectToAction("initHolidays");
            }

            foreach (Holiday holiday in db.GetHolidays())
            {
                if (h.DateFrom < holiday.DateTo && holiday.DateFrom < h.DateTo)
                {
                    overlap = true;
                    break;
                }
                else
                {
                    overlap = false;
                }
            }

            if (!overlap)
            {
                if (h.DateFrom <= h.DateTo)
                {
                    db.AddHoliday(h);
                    changeVacationDays(h);
                }
                else
                {
                    ViewBag.errorMessage = "Date from can't be greater that date to.";
                }
            }
            else
            {
                Console.WriteLine("PREKLAPANJE!!!");
            }

            return RedirectToAction("initHolidays");
        }
 public void AddHoliday(Holiday h)
 {
     dataContext.Holidays.Add(h);
     dataContext.SaveChanges();
 }
        private void revertOldVacationDays(Holiday h)
        {
            TestService vacationService = new TestService();
            UsersService users = new UsersService();
            List<Vacation> vacations = vacationService.GetVacations().ToList();
            double addMoreDaysToVacation = 0;
            foreach (Vacation v in vacations)
            {
                if (v.IsSickLeave) continue;

                //ako se praznik nalazi ceo izmedju, povecaj dane za sve.
                if (h.DateFrom >= v.DateFrom && h.DateFrom <= v.DateTo)
                {
                    if (h.DateTo <= v.DateTo)
                    {
                        addMoreDaysToVacation = (h.DateTo - h.DateFrom).TotalDays;
                    }
                    else
                    {
                        addMoreDaysToVacation = (v.DateTo - h.DateFrom).TotalDays;
                    }
                }
                else if (h.DateFrom <= v.DateFrom && h.DateTo >= v.DateTo)
                {
                    addMoreDaysToVacation = (v.DateTo - v.DateFrom).TotalDays;
                }
                else if (h.DateFrom <= v.DateFrom && h.DateTo <= v.DateTo && h.DateTo >= v.DateFrom)
                {

                    addMoreDaysToVacation = (h.DateTo - v.DateFrom).TotalDays;
                }

                if (addMoreDaysToVacation > 0)
                {
                    User u = (User)users.FindById(v.UserId);
                    u.VacationDays -= Convert.ToInt32(addMoreDaysToVacation);
                    users.Edit(u);
                }
            }
        }