Exemplo n.º 1
0
        public object FindById(int id)
        {
            Vacation pom = new Vacation();
            pom = dataContext.Vacations.Find(id);

            return pom;
        }
        public ActionResult DeleteVacation(Vacation vacation, int? page,String calendar)
        {
            Vacation vac = (Vacation)db.FindById(vacation.VacationPeriodId);
            double numDays = (vac.DateTo - vac.DateFrom).TotalDays;
            radniDaniZaBrisanje = GetWorkDays(vac.DateFrom, vac.DateTo);
            UsersService users = new UsersService();
            User u = (User)users.FindUserByUsername(HttpContext.User.Identity.Name);
            if (!vac.IsSickLeave)
            {
                int days = u.VacationDays + radniDaniZaBrisanje;
                u.VacationDays = days;
            }

            users.Edit(u);
            db.DeleteVacation(vac.VacationPeriodId);

            if (calendar != null && calendar.Equals("true"))
            {
                return RedirectToAction("initHolidays", "LoadHolidays");
            }
            else
            {
                return SeeVacationsDelete(page);
            }
        }
Exemplo n.º 3
0
 public void EditVacation(Vacation testModel)
 {
     Vacation oldVacation = dataContext.Vacations.Find(testModel.VacationPeriodId);
     if (oldVacation != null)
         dataContext.Entry(oldVacation).CurrentValues.SetValues(testModel);
     dataContext.SaveChanges();
 }
Exemplo n.º 4
0
 public void AddVacation(Vacation testModel)
 {
     dataContext.Vacations.Add(testModel);
     dataContext.SaveChanges();
 }
 private double DaysIsntCountHoliday(Vacation vacation)
 {
     HolidayService holidaysService = new HolidayService();
     List<Holiday> holidays = holidaysService.GetHolidays().ToList();
     double holidayDaysIsntCount = 0;
     if (vacation.IsSickLeave) return holidayDaysIsntCount;
     foreach (Holiday h in holidays)
     {
         //kada je praznik izmedju pocetka i kraja odmora
         if (h.DateFrom >= vacation.DateFrom && h.DateFrom <= vacation.DateTo)
         {
             if (h.DateTo <= vacation.DateTo)
             {
                 holidayDaysIsntCount = (h.DateTo - h.DateFrom).TotalDays;
             }
             else if (h.DateTo >= vacation.DateTo)
             {
                 holidayDaysIsntCount = (vacation.DateTo - h.DateFrom).TotalDays;
             }
         }
         //kada je praznik poceo pre pocetka odmora i traje posle
         else if (h.DateFrom <= vacation.DateFrom && h.DateTo >= vacation.DateTo)
         {
             holidayDaysIsntCount = (vacation.DateTo - vacation.DateFrom).TotalDays;
         }
         //zavrsi se izmedju
         else if (h.DateFrom <= vacation.DateFrom && h.DateTo <= vacation.DateTo && h.DateTo >= vacation.DateFrom)
         {
             holidayDaysIsntCount = (h.DateTo - vacation.DateFrom).TotalDays;
         }
     }
     return holidayDaysIsntCount;
 }
        public ActionResult RegistracijaOdmora(Vacation vacation)
        {
            int vikend = 0;
            flag = 0;
            UsersService users = new UsersService();
            User u = (User)users.FindById(vacation.UserId);
            String datum = DateTime.Now.ToString("yyyy-MM-dd");
            ViewBag.Datum = datum;
            Double numDays = (vacation.DateTo - vacation.DateFrom).TotalDays;
            List<Vacation> vacations = db.GetVacationsForCurrentUser(u.UserId);
            numDays -= DaysIsntCountHoliday(vacation);

                brojacRadnihDanaBezVikenda = GetWorkDays(vacation.DateFrom, vacation.DateTo);
                vikend = Convert.ToInt32(numDays) - brojacRadnihDanaBezVikenda;
                numDays -= vikend;

            if (vacation.IsSickLeave && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(datum))) && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(vacation.DateFrom.ToString("yyyy-MM-dd")))))
            {
                int brojac = 0;
                if (ModelState.IsValid)
                {

                    foreach (Vacation v in vacations)
                    {
                        if ((vacation.DateFrom >= v.DateFrom && vacation.DateFrom < v.DateTo) || (vacation.DateTo >= v.DateFrom && vacation.DateTo <= v.DateTo) || (vacation.DateFrom <= v.DateFrom && vacation.DateTo >= v.DateTo))
                        {
                            flag = 1;

                        }
                        else
                        {
                            brojac++;
                        }
                    }
                    if (brojac == vacations.Count)
                    {
                        flag = 0;
                        vacation.DateFrom = vacation.DateFrom;
                        vacation.DateTo = vacation.DateTo;
                        db.AddVacation(vacation);
                        return RedirectToAction("initHolidays", "LoadHolidays");
                    }
                    else
                    {
                        flag = 1;
                        return RedirectToAction("RegistracijaOdmora", new { parameterdatum1 = vacation.DateFrom.ToString("yyyy-MM-dd"), parameterdatum2 = vacation.DateTo.ToString("yyyy-MM-dd") });
                    }

                }
                return View();
            }
            else
            {
                if (Convert.ToInt32(numDays) <= u.VacationDays && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(datum))) && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(vacation.DateFrom.ToString("yyyy-MM-dd")))))
                {
                    int brojac = 0;
                    if (ModelState.IsValid)
                    {
                        foreach (Vacation v in vacations)
                        {
                            if ((vacation.DateFrom >= v.DateFrom && vacation.DateFrom < v.DateTo) || (vacation.DateTo >= v.DateFrom && vacation.DateTo <= v.DateTo) || (vacation.DateFrom <= v.DateFrom && vacation.DateTo >= v.DateTo))
                            {
                                flag = 1;

                            }
                            else
                            {

                                brojac++;
                            }
                        }

                        if (brojac == vacations.Count)
                        {
                            flag = 0;
                            vacation.DateFrom = vacation.DateFrom;
                            vacation.DateTo = vacation.DateTo;
                            db.AddVacation(vacation);
                            int days = u.VacationDays - Convert.ToInt32(numDays);
                            u.VacationDays = days;
                            users.Edit(u);
                            return RedirectToAction("initHolidays", "LoadHolidays");
                        }
                        else
                        {
                            flag = 1;
                            return RedirectToAction("RegistracijaOdmora", new { parameterdatum1 = vacation.DateFrom.ToString("yyyy-MM-dd"), parameterdatum2 = vacation.DateTo.ToString("yyyy-MM-dd") });
                        }

                    }
                    return View();
                }
                else
                {

                    return RedirectToAction("RegistracijaOdmora", new { parameterdatum1 = vacation.DateFrom.ToString("yyyy-MM-dd"), parameterdatum2 = vacation.DateTo.ToString("yyyy-MM-dd") });
                }
                //provera
            }
        }
        public ActionResult RegistracijaOdmora(String parameterdatum1, String parameterdatum2)
        {
            UsersService users = new UsersService();
            User u = users.FindUserByUsername(HttpContext.User.Identity.Name);
            String datum = DateTime.Now.ToString("yyyy-MM-dd");
            ViewBag.Datum = datum;
            s1 = parameterdatum1;
            s2 = parameterdatum2;
            ViewBag.Parameterdatum1 = parameterdatum1;
            ViewBag.Parameterdatum2 = parameterdatum2;
            ViewBag.UserId = u.UserId;
            ViewBag.BrDana = u.VacationDays;
            var vac = new Vacation();
            vac.UserId = Int32.Parse(u.UserId.ToString());
            vac.DateFrom = Convert.ToDateTime(parameterdatum1);
            vac.DateTo = Convert.ToDateTime(parameterdatum2);
            daniZaProveru = GetWorkDays(vac.DateFrom, vac.DateTo);
            ViewBag.DaniZaProveru = daniZaProveru;
            ViewBag.Flag = flag;
            flag = 0;

            return View(vac);
        }
        public ActionResult EditVacation(Vacation vacation, int? page,String calendar)
        {
            int vikend1 = 0;
            int vikend2 = 0;
            int vikend3 = 0;
            int vikend4 = 0;
            int razlikaZaVikendDane = 0;
            int razlikaZaVikendDanePocetak = 0;
            brojacRadnihDanaZaEditBezVikenda = 0;
            brojacRadnihDanaZaEditBezVikendaFrom = 0;
            String datum = DateTime.Now.ToString("yyyy-MM-dd");
            ViewBag.Datum = datum;
            UsersService users = new UsersService();
            User u = (User)users.FindById(vacation.UserId);
            Double numDays = (vacation.DateTo - vacation.DateFrom).TotalDays;
            Double povecavanjeOdmora = (vacation.DateTo - datumProveraZaEdit).TotalDays;
            Double povecavanjeOdmoraZaPocetak = (vacation.DateFrom - datumProveraZaEditPocetak).TotalDays;
            Vacation oldVacation = (Vacation)db.FindById(vacation.VacationPeriodId);
            List<Vacation> vacations = db.GetVacationsForCurrentUser(u.UserId);
            double oldHolidayVacationCount = DaysIsntCountHoliday(oldVacation);
            double totalHolidayDays = oldHolidayVacationCount - DaysIsntCountHoliday(vacation);
            numDays += totalHolidayDays;
            if (vacation.DateTo > datumProveraZaEdit)
            {
                brojacRadnihDanaZaEditBezVikenda = GetWorkDays(datumProveraZaEdit, vacation.DateTo);
                vikend1 = Convert.ToInt32(povecavanjeOdmora) - brojacRadnihDanaZaEditBezVikenda;
                razlikaZaVikendDane += vikend1;

            }
            else if (vacation.DateTo <= datumProveraZaEdit)
            {
                brojacRadnihDanaZaEditBezVikenda = -(GetWorkDays(vacation.DateTo, datumProveraZaEdit));
                vikend2 = -(Convert.ToInt32(povecavanjeOdmora)) + brojacRadnihDanaZaEditBezVikenda;
                razlikaZaVikendDane -= vikend2;

            }

            if (vacation.DateFrom > datumProveraZaEditPocetak)
            {
                brojacRadnihDanaZaEditBezVikendaFrom = GetWorkDays(datumProveraZaEditPocetak, vacation.DateFrom);
                vikend3 = (Convert.ToInt32(povecavanjeOdmoraZaPocetak)) - brojacRadnihDanaZaEditBezVikendaFrom;
                razlikaZaVikendDanePocetak -= vikend3;

            }
            else
            {
                brojacRadnihDanaZaEditBezVikendaFrom = -(GetWorkDays(vacation.DateFrom, datumProveraZaEditPocetak));
                vikend4 = -(Convert.ToInt32(povecavanjeOdmoraZaPocetak)) + brojacRadnihDanaZaEditBezVikendaFrom;
                razlikaZaVikendDanePocetak += vikend4;

            }

            if (vacation.IsSickLeave && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(datum))) && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(vacation.DateFrom.ToString("yyyy-MM-dd")))))
            {
                int brojac = 0;
                foreach (Vacation v in vacations)
                {
                    if (vacation.VacationPeriodId == v.VacationPeriodId)
                    {
                        brojac++;
                        continue;
                    }
                    if ((vacation.DateFrom >= v.DateFrom && vacation.DateFrom < v.DateTo) || (vacation.DateTo >= v.DateFrom && vacation.DateTo <= v.DateTo) || (vacation.DateFrom <= v.DateFrom && vacation.DateTo >= v.DateTo))
                    {

                        flag = 1;

                    }
                    else
                    {
                        brojac++;
                    }
                }
                if (brojac == vacations.Count)
                {
                    flag = 0;
                    db.EditVacation(vacation);
                    if (calendar != null && calendar.Equals("true")) {
                        return RedirectToAction("initHolidays", "LoadHolidays");
                    }
                    else
                    {
                        return SeeVacations(page);
                    }
                }
                else
                {
                    flag = 1;
                    if (calendar != null && calendar.Equals("true"))
                    {
                        return RedirectToAction("EditVacation", new { vacationId = vacation.VacationPeriodId, calendar = "true" });
                    }
                    else
                    {
                        return RedirectToAction("EditVacation", new { vacationId = vacation.VacationPeriodId });

                    }
                }

            }
            else
            {
               if (Convert.ToInt32(brojacRadnihDanaZaEditBezVikenda - brojacRadnihDanaZaEditBezVikendaFrom)> u.VacationDays)
                {
                    daniZaProveruZaEdit = brojacRadnihDanaZaEditBezVikenda - brojacRadnihDanaZaEditBezVikendaFrom;
                    flagZaPozivEdita = 1;
                }
                if (Convert.ToInt32(brojacRadnihDanaZaEditBezVikenda - brojacRadnihDanaZaEditBezVikendaFrom) <= u.VacationDays && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(datum))) && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(vacation.DateFrom.ToString("yyyy-MM-dd")))))
                {
                    int brojac = 0;

                    if (ModelState.IsValid)
                    {
                        foreach (Vacation v in vacations)
                        {
                            if (vacation.VacationPeriodId == v.VacationPeriodId)
                            {
                                brojac++;
                                continue;
                            }
                            if ((vacation.DateFrom >= v.DateFrom && vacation.DateFrom < v.DateTo) || (vacation.DateTo >= v.DateFrom && vacation.DateTo <= v.DateTo) || (vacation.DateFrom <= v.DateFrom && vacation.DateTo >= v.DateTo))
                            {
                                flag = 1;
                            }
                            else
                            {
                                brojac++;
                            }
                        }
                        if (brojac == vacations.Count)
                        {
                            flag = 0;
                            int days = u.VacationDays - Convert.ToInt32(numDays) + daniZaVracanje + razlikaZaVikendDane + razlikaZaVikendDanePocetak;
                            u.VacationDays = days;
                            users.Edit(u);
                            db.EditVacation(vacation);
                            daniZaVracanje = Convert.ToInt32(numDays);
                            if (calendar != null && calendar.Equals("true"))
                            {
                                return RedirectToAction("initHolidays", "LoadHolidays");
                            }
                            else
                            {
                                return SeeVacations(page);
                            }
                        }
                        else
                        {
                            flag = 1;
                            if (calendar != null && calendar.Equals("true"))
                            {
                                return RedirectToAction("EditVacation", new { vacationId = vacation.VacationPeriodId, calendar = "true" });
                            }
                            else
                            {
                                return RedirectToAction("EditVacation", new { vacationId = vacation.VacationPeriodId });

                            }
                        }

                    }
                    return View();
                }
                else
                {
                    if (calendar != null && calendar.Equals("true"))
                    {
                        return RedirectToAction("initHolidays", "LoadHolidays");
                    }
                    else
                    {
                        flagZaPozivEdita = 1;
                        return RedirectToAction("EditVacation", new { vacationId = vacation.VacationPeriodId, calendar = "true" });
                    }
                }
            }
        }