Example #1
0
        public HttpResponseMessage DeleteMaintenance(Guid bookingId)
        {
            var context             = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var userRepository      = new UserRepository(context);
            var bookingRepository   = new BookingRepository(context);
            var classroomRepository = new ClassroomRepository(context);

            var bookingService = new BookingService(bookingRepository, classroomRepository);
            var userService    = new UserService(userRepository);

            var user = userService.GetUserById(UserId);

            if (user.Role != TimeTableRole.Management && user.Role != TimeTableRole.Admin && user.Role != TimeTableRole.Fit)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Insufficient permissions."));
            }

            var deletedBooking = bookingService.DeleteBooking(bookingId);

            if (deletedBooking)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }
Example #2
0
        public HttpResponseMessage EditRol(UserEdit edit)
        {
            if (edit.UserId == UserId)
            {
                return(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "You can't edit yourself"));
            }

            var isDefined = Enum.IsDefined(typeof(TimeTableRole), edit.NewRole);

            if (!isDefined)
            {
                return(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "New role is not a valid one"));
            }

            var context        = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var userRepository = new UserRepository(context);

            var managementService = new ManagementService();
            var userService       = new UserService(userRepository);

            var user = userService.GetUserById(UserId);

            if (user.Role != TimeTableRole.Admin)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Insufficient permissions."));
            }

            var isUserEdited = managementService.EditUser(userRepository, edit);

            return(isUserEdited
                ? Request.CreateResponse(HttpStatusCode.OK)
                : Request.CreateResponse(HttpStatusCode.BadRequest));
        }
        public HttpResponseMessage Book(Booking booking)
        {
            var context             = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var bookingRepository   = new BookingRepository(context);
            var classroomRepository = new ClassroomRepository(context);
            var service             = new BookingService(bookingRepository, classroomRepository);

            booking.Owner = UserId;
            var bookingService = service.BookRoom(booking, UserProfile);

            switch (bookingService)
            {
            case BookingAvailability.Success:
                return(Request.CreateResponse(HttpStatusCode.OK, booking));

            case BookingAvailability.Booked:
                return(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "The room was already booked"));

            case BookingAvailability.Scheduled:
                return(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "There was a normal lesson during the time you would like to reserve"));

            case BookingAvailability.Maintenance:
                return(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "There is maintenance in this classroom during the time you would like to reserve."));

            default:
                return(null);
            }
        }
 public EmployeeInfoForm(string employeeEGN)
 {
     InitializeComponent();
     this.db                 = new TimeTableContext();
     this.employee           = this.db.Employees.Include(em => em.ProjectHours).First(em => em.EmployeeEgn == employeeEGN);
     this.employeeTasksCount = employee.ProjectHours.Count;
 }
Example #5
0
 public TaskRegisterForm(TimeTableContext db, Employee employee)
 {
     InitializeComponent();
     this.db            = db;
     this.employee      = employee;
     this.projectsNames = this.db.Projects.Select(p => p.ProjectName).ToList();
 }
Example #6
0
        public void TestInitialize()
        {
            var options = new DbContextOptionsBuilder <TimeTableContext>()
                          .UseInMemoryDatabase(databaseName: "InMemoryPopulated")
                          .Options;

            db = new TimeTableContext(options);
        }
Example #7
0
 public TasksForm(Employee employee, decimal projectId, string projectName)
 {
     InitializeComponent();
     this.employee    = employee;
     this.projectId   = projectId;
     this.projectName = projectName;
     this.tasks       = new List <ProjectHours>();
     this.db          = new TimeTableContext();
 }
Example #8
0
        public HttpResponseMessage GetAvailableWeeksHttpResponseMessage()
        {
            var context    = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var repository = new ClassroomRepository(context);
            var service    = new TimeTableService(repository);

            var weeks = service.GetAvailableWeeks();

            return(Request.CreateResponse(HttpStatusCode.OK, weeks));
        }
        public HttpResponseMessage Find(int start, int end, int dayofweek)
        {
            var context             = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var classroomRepository = new ClassroomRepository(context);
            var service             = new TimeTableService(classroomRepository);

            var emptyRooms = service.FindEmpty(start, end, dayofweek);

            return(Request.CreateResponse(HttpStatusCode.OK, emptyRooms));
        }
Example #10
0
        public HttpResponseMessage GetScheduleForClass(string classCode, int week)
        {
            var context    = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var repository = new ClassroomRepository(context);
            var service    = new TimeTableService(repository);

            var room = service.GetClassScheduleByCodeAndWeek(classCode, week);

            return(Request.CreateResponse(HttpStatusCode.OK, room));
        }
Example #11
0
 public TaskEditForm(int rowIndex, ProjectHours task, string projectName, Employee employee)
 {
     InitializeComponent();
     this.rowIndex    = rowIndex;
     this.task        = task;
     this.projectName = projectName;
     this.employee    = employee;
     this.db          = new TimeTableContext();
     this.project     = this.db.Projects.Include(p => p.ProjectMonths).First(p => p.ProjectName == projectName);
 }
        public HttpResponseMessage GetBookingsPerRoomPerWeek(string roomCode, int week)
        {
            var context             = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var bookingRepository   = new BookingRepository(context);
            var classroomRepository = new ClassroomRepository(context);
            var service             = new BookingService(bookingRepository, classroomRepository);

            var bookings = service.GetBookingsPerRoomPerWeek(roomCode, week);

            return(Request.CreateResponse(HttpStatusCode.OK, bookings));
        }
Example #13
0
        public void TestInitialize()
        {
            var options = new DbContextOptionsBuilder <TimeTableContext>()
                          .UseInMemoryDatabase(databaseName: "InMemoryPopulated")
                          .Options;

            db = new TimeTableContext(options);

            // Load sample data for this test
            ApplicationDbInitializer.Initialize(db).Wait();
        }
        private void AddLessonIndex(int startColumn, int numberofCell)
        {
            for (var i = 0; i < numberofCell; i++)
            {
                var columnIndex  = startColumn + i;
                var lessonHeader = new DCell(1, columnIndex, 1, 1);
                lessonHeader.BackgroundContent = (i + 1).ToString();

                TimeTableContext.AddCell(lessonHeader);
            }
        }
        public HttpResponseMessage Filter(int guests, int startBlock, int endBlock, int week, int weekDay)
        {
            var context             = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var bookingRepository   = new BookingRepository(context);
            var classroomRepository = new ClassroomRepository(context);
            var service             = new BookingService(bookingRepository, classroomRepository);

            var bookingService = service.Filter(guests, startBlock, endBlock, week, weekDay);

            return(Request.CreateResponse(HttpStatusCode.OK, bookingService));
        }
        public HttpResponseMessage GetAllClassrooms()
        {
            var context    = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var repository = new ClassroomRepository(context);
            var service    = new ClassroomService(repository);

            var rooms = service.GetAllClassrooms();

            return(rooms == null
                ? Request.CreateResponse(HttpStatusCode.NoContent)
                : Request.CreateResponse(HttpStatusCode.OK, rooms));
        }
        public HttpResponseMessage Scrape(int week)
        {
            var context             = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var scraperRepository   = new ScraperRepository(context);
            var classroomRepository = new ClassroomRepository(context);
            var bookingRepository   = new BookingRepository(context);
            var classRepository     = new ClassRepository(context);
            var scraperService      = new ScraperService(scraperRepository, classroomRepository, classRepository, bookingRepository);

            Task.Run(() => scraperService.Scrape(week));

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
 /// <summary>
 /// InsertBackgroudForAllTimeItems
 /// </summary>
 private void InsertBackgroudForAllTimeItems()
 {
     // row form 2 to end
     for (var i = 2; i < TimeTableContext.Rows.Count; i++)
     {
         // column from 1 to end
         for (var j = 1; j < TimeTableContext.Columns.Count; j++)
         {
             var contentCell = new DCell(i, j, 1, 1);
             contentCell.BackgroundContent = "";
             TimeTableContext.AddCell(contentCell);
         }
     }
 }
Example #19
0
        public HttpResponseMessage GetAllUsers()
        {
            var context           = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var repository        = new UserRepository(context);
            var managementService = new ManagementService();
            var userService       = new UserService(repository);

            var user = userService.GetUserById(UserId);

            if (user.Role != TimeTableRole.Management && user.Role != TimeTableRole.Admin)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Insufficient permissions."));
            }

            var allUsers = managementService.GetAllUsers(repository);

            return(Request.CreateResponse(HttpStatusCode.OK, allUsers));
        }
Example #20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TimeTableContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            if (bool.Parse(Configuration["AddSampleData"].ToString()))
            {
                ApplicationDbInitializer.Initialize(context).Wait();
            }

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });

            app.UseSignalR(routes =>
            {
                routes.MapHub <ScheduleHub>("/schedules");
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
Example #21
0
        public HttpResponseMessage Login()
        {
            var context    = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var repository = new UserRepository(context);
            var service    = new UserService(repository);

            var login = service.HandleUserLogin(UserProfile);

            if (login == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, new
            {
                role = login.Role,
                rolestring = login.RoleString
            }));
        }
Example #22
0
        public HttpResponseMessage MostUsedClassroomsLessons(int top, int week)
        {
            var context        = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var userRepository = new UserRepository(context);
            var userService    = new UserService(userRepository);

            var user = userService.GetUserById(UserId);

            if (user.Role != TimeTableRole.Management && user.Role != TimeTableRole.Admin && user.Role != TimeTableRole.Fit)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Insufficient permissions."));
            }

            var repository = new ClassroomRepository(context);
            var service    = new StatisticsService();

            var rooms = service.GetMostUsedClassroomsByLessons(repository, top, week);

            return(Request.CreateResponse(HttpStatusCode.OK, rooms));
        }
Example #23
0
        public HttpResponseMessage AmountOfMaintenanceBookings(int week)
        {
            var context        = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var userRepository = new UserRepository(context);
            var userService    = new UserService(userRepository);

            var user = userService.GetUserById(UserId);

            if (user.Role != TimeTableRole.Management && user.Role != TimeTableRole.Admin && user.Role != TimeTableRole.Fit)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Insufficient permissions."));
            }

            var repository = new BookingRepository(context);
            var service    = new StatisticsService();

            var amount = service.AmountOfMaintenanceBookings(repository, week);

            return(Request.CreateResponse(HttpStatusCode.OK, amount));
        }
Example #24
0
        public HttpResponseMessage GetAllMaintenaceBookingsByWeek(int week)
        {
            var context     = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var repository  = new UserRepository(context);
            var userService = new UserService(repository);

            var user = userService.GetUserById(UserId);

            if (user.Role != TimeTableRole.Management && user.Role != TimeTableRole.Admin && user.Role != TimeTableRole.Fit)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Insufficient permissions."));
            }

            var bookingRepository   = new BookingRepository(context);
            var classroomRepository = new ClassroomRepository(context);
            var bookingService      = new BookingService(bookingRepository, classroomRepository);

            var allBookings = bookingService.GetAllMaintenanceBookings(week);

            return(Request.CreateResponse(HttpStatusCode.OK, allBookings));
        }
Example #25
0
        public async Task <HttpResponseMessage> BookMaintenance(Booking booking)
        {
            var context             = new TimeTableContext(WebConfigurationManager.AppSettings["DbConnectionString"]);
            var userRepository      = new UserRepository(context);
            var bookingRepository   = new BookingRepository(context);
            var classroomRepository = new ClassroomRepository(context);

            var managementService = new ManagementService();
            var bookingService    = new BookingService(bookingRepository, classroomRepository);
            var userService       = new UserService(userRepository);

            var user = userService.GetUserById(UserId);

            if (user.Role != TimeTableRole.Management && user.Role != TimeTableRole.Admin && user.Role != TimeTableRole.Fit)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Insufficient permissions."));
            }

            var notifier = new Notifier.Notifier();
            var allUsers = await managementService.MaintenanceBooking(classroomRepository, bookingRepository, userRepository, bookingService, booking, UserId, notifier);

            return(Request.CreateResponse(HttpStatusCode.OK, allUsers));
        }
 public EmployeeRegisterForm(TimeTableContext db)
 {
     InitializeComponent();
     this.db = db;
 }
 /// <summary>
 /// A konstruktor, ami létrehoz egy CourseRepository objektumot
 /// </summary>
 /// <param name="context">A TimeTableContext</param>
 public CourseRepository(TimeTableContext context) : base(context)
 {
 }
Example #28
0
 public void TimeTableContextTest()
 {
     var timeTableContext = new TimeTableContext("DefaultConnection");
 }
 public GenerateService() : base()
 {
     db = new TimeTableContext();
 }
Example #30
0
 public CreateScheduleCommandHandler(TimeTableContext context)
 {
     _context = context;
 }