Exemple #1
0
        public static Calendar GetCalendarVacation(DateTime?start)
        {
            DutyContext db = new DutyContext();

            Calendar calendar = GetInstanse(start);

            DateTime current     = new DateTime(calendar.CurrentDate.Year, calendar.CurrentDate.Month, 1);
            int      allDayMonth = DateTime.DaysInMonth(calendar.CurrentDate.Year, calendar.CurrentDate.Month);
            DateTime last        = new DateTime(calendar.CurrentDate.Year, calendar.CurrentDate.Month, allDayMonth);

            var vacations = db.Vacations.Include(x => x.Employee).Where(x => x.Start >= current && x.Start <= last ||
                                                                        x.Start < current && x.Finish >= current).ToList();

            while (current <= last)
            {
                var emps = vacations.Where(x => x.Start <= current && x.Finish >= current).Select(x => x.Employee).ToArray();

                if (emps.Length != 0)
                {
                    calendar.Duties.Add(current, emps);
                }

                current = current.AddDays(1);
            }
            return(calendar);
        }
Exemple #2
0
        public ViewResult Index(string sortOrder, string currentFilter, string searchString, int?page)
        {
            using (DutyContext db = new DutyContext())
            {
                if (searchString != null)
                {
                    page = 1;
                }
                else
                {
                    searchString = currentFilter;
                }

                var emps = from s in db.Employees select s;
                emps = emps.OrderByDescending(s => s.Name);

                if (!String.IsNullOrEmpty(searchString))
                {
                    emps = emps.Where(s => s.Name.Contains(searchString));
                }

                int pageSize   = 5;
                int pageNumber = (page ?? 1);

                Models.Sort sort = new Models.Sort();
                sort.CurrentSort   = sortOrder;
                sort.CurrentFilter = searchString;
                sort.Emps          = emps.ToPagedList(pageNumber, pageSize);

                return(View("GetEmployee", sort));
            }
        }
Exemple #3
0
        public static void GetHoliday(DateTime start, int countDays)
        {
            DutyContext db = new DutyContext();

            WebClient webClient = new WebClient();

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            DateTime finish = start.AddDays(countDays);

            while (start <= finish)
            {
                string url = "https://isdayoff.ru/" + start.ToString("yyyyMMdd") + "?cc=ru";
                Console.WriteLine(start.ToString("yyyyMMdd"));
                string response = webClient.DownloadString(url);

                if (response == "1")
                {
                    Console.WriteLine("Загружено");
                    db.Holidays.Add(new Holidays(start));
                }

                start = start.AddDays(1);
            }

            db.SaveChanges();
            Console.ReadKey();
        }
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            using (DutyContext db = new DutyContext())
            {
                string Login = HttpContext.Current.User.Identity.Name;

                Access access = db.Accesses.Where(x => x.Login == Login).FirstOrDefault();

                if (access == null)
                {
                    filterContext.Result = new RedirectToRouteResult(
                        new System.Web.Routing.RouteValueDictionary {
                        { "controller", "Error" }, { "action", "NoAuthorization" }
                    });
                }

                else
                {
                    if (!access.AllowedEdit)
                    {
                        filterContext.Result = new RedirectToRouteResult(
                            new System.Web.Routing.RouteValueDictionary {
                            { "controller", "Error" }, { "action", "NotAvailable" }
                        });
                    }
                }
            }
        }
Exemple #5
0
 public ActionResult Create([Bind(Include = "Name, Email, Login")] Employee employee)
 {
     using (DutyContext db = new DutyContext())
     {
         if (ModelState.IsValid)
         {
             db.Employees.Add(employee);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View("CreateEmployee"));
     }
 }
Exemple #6
0
        public ActionResult Delete(int id, int pageDelete)
        {
            using (DutyContext db = new DutyContext())
            {
                Employee employee = db.Employees.Find(id);

                if (ModelState.IsValid)
                {
                    db.Employees.Remove(employee);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index", new { page = pageDelete }));
            }
        }
Exemple #7
0
        private static Calendar GetInstanse(DateTime?start)
        {
            DutyContext db       = new DutyContext();
            DateTime    target   = start ?? DateTime.Now.Date;
            Calendar    calendar = new Calendar();

            calendar.CurrentDate = target;

            calendar.Emps = new SelectList(db.Employees.OrderBy(x => x.Name), "EmployeeId", "Name");

            calendar.Holidays = db.Holidays.Include(x => x.Holiday).Where(x => x.Holiday.Year == calendar.CurrentDate.Year &&
                                                                          x.Holiday.Month == calendar.CurrentDate.Month).Select(x => x.Holiday.Day).ToList();

            return(calendar);
        }
Exemple #8
0
        public static Calendar GetCalendarDuty(DateTime?start)
        {
            /*Метод создаёт экземепляр класса Calendar и записывает в него текущую дату и дежурных сотрудников в этом месяце */
            DutyContext db = new DutyContext();

            Calendar calendar = GetInstanse(start);

            var dutyLists = db.DutyLists.Include(x => x.Employee).Where(x => x.DateDuty.Year == calendar.CurrentDate.Year &&
                                                                        x.DateDuty.Month == calendar.CurrentDate.Month).OrderBy(x => x.DateDuty).ToList();

            var dates = dutyLists.Select(x => x.DateDuty).Distinct();

            foreach (DateTime s in dates)
            {
                Employee[] emps = dutyLists.Where(x => x.DateDuty == s).Select(x => x.Employee).ToArray();
                calendar.Duties.Add(s, emps);                 // Duties - массив пар значений - число месяца и сотрудник
            }
            return(calendar);
        }