Exemplo n.º 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Database.SetInitializer<HMContext>(null);

            var domainUserProvider = NinjectWebCommon.Kernel.GetService(typeof(IDomainUserProvider)) as IDomainUserProvider;
            var hmUnitOfWork = NinjectWebCommon.Kernel.GetService(typeof(IHMUnitOfWork)) as IHMUnitOfWork;

            var adminADName = ConfigurationManager.AppSettings["AdminADName"];

            var adminUserRole = hmUnitOfWork.RoleRepository.FindBy(x => x.Name == "AdminUser").SingleOrDefault();
            var normalUserRole = hmUnitOfWork.RoleRepository.FindBy(x => x.Name == "NormalUser").SingleOrDefault();

            foreach (var domainUser in domainUserProvider.GetAllUsers())
            {
                var employee = hmUnitOfWork.EmployeeRepository.FindBy(x => x.ADName == domainUser.Name).SingleOrDefault();

                if (employee == null)
                {
                    employee = new Employee
                    {
                        FirstName = domainUser.Name,
                        LastName = domainUser.Name,
                        ADName = domainUser.Name,
                        EmailAddress = domainUser.EmailAddress,
                        RoleId = domainUser.Name == adminADName ? adminUserRole.Id : normalUserRole.Id
                    };

                    hmUnitOfWork.EmployeeRepository.Add(employee);

                    var holidayInformation = new HolidayInformation
                    {
                        DaysAvailable = 21,
                        Year = DateTime.Now.Year,
                        Employee = employee
                    };

                    hmUnitOfWork.HolidayInformationRepository.Add(holidayInformation);
                }
            }

            hmUnitOfWork.Save();
        }
Exemplo n.º 2
0
        protected MonthlyCalendarViewModel[] CreateMonthlyCalendarViewModels(Employee employee)
        {
            var months = new MonthlyCalendarViewModel[12];

            var now = DateTime.Now;

            for (var i = 0; i < 12; ++i)
            {
                var month = new DateTime(now.Year, i + 1, 1);

                months[i] = new MonthlyCalendarViewModel
                {
                    Month = month.ToString("MMMM"),
                    MonthIndex = i,
                    FirstDay = (int)month.DayOfWeek,
                    NumberOfDays = DateTime.DaysInMonth(now.Year, i + 1),
                    Holidays = new List<int>(),
                    Requests = new List<int>(),
                };
            }

            var holidayPeriods = employee.HolidayPeriods.Where(x => x.StartDate.Year == DateTime.Now.Year && x.CancelDate == null);

            foreach (var holidayPeriod in holidayPeriods)
            {
                for (var date = holidayPeriod.StartDate; date <= holidayPeriod.EndDate; date = date.AddDays(1))
                {
                    months[date.Month - 1].Holidays.Add(date.Day);
                }
            }

            var requests = employee.Requests.Where(x => x.StartDate.Year == DateTime.Now.Year && x.CancelDate == null);

            foreach (var request in requests)
            {
                for (var date = request.StartDate; date <= request.EndDate; date = date.AddDays(1))
                {
                    months[date.Month - 1].Requests.Add(date.Day);
                }
            }

            return months;
        }