Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(int buildingid, int departmentid)
        {
            BuildingIdRoute   = buildingid;
            DepartmentIdRoute = departmentid;

            ViewData["Building"] = new SelectList(_context.Buildings, "BuildingID", "Name", buildingid);

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            AllRoomNumbers = await _context.Rooms
                             .Where(r => r.BuildingID == buildingid)
                             .Select(i => i.Number)
                             .ToListAsync();

            if (AllRoomNumbers.Contains(Room.Number))
            {
                SameNumberError = "Już istnieje pokój o tym numerze.";

                return(Page());
            }

            _context.Rooms.Add(Room);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index", new { buildingid = BuildingIdRoute, departmentid = DepartmentIdRoute }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(int departmentid)
        {
            DepartmentIdRoute = departmentid;

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            AllBuildingsNames = await _context.Buildings
                                .Select(r => r.Name)
                                .AsNoTracking()
                                .ToListAsync();

            if (AllBuildingsNames.Contains(Building.Name))
            {
                DuplicateNameExistError = "Już istnieje budynek o tej nazwie.";
                return(Page());
            }

            var emptyBuilding = new Building();

            if (await TryUpdateModelAsync <Building>(
                    emptyBuilding,
                    "Building",
                    s => s.Name, s => s.Address, s => s.DepartmentID, s => s.GPS_E, s => s.GPS_N))
            {
                _context.Buildings.Add(emptyBuilding);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index", new { departmentid = DepartmentIdRoute }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int reservationid, int buildingid, int departmentid, string date)
        {
            CurrentUser = await _userManager.GetUserAsync(base.User);

            if (CurrentUser == null)
            {
                return(base.NotFound($"Unable to load user with ID '{_userManager.GetUserId(base.User)}'."));
            }

            BuildingIdRoute   = buildingid;
            DepartmentIdRoute = departmentid;

            DateTime.TryParse(date, out var ParseDate);
            Date = ParseDate;

            Reservation = await _context.Reservations.FindAsync(reservationid);



            if (Reservation != null)
            {
                if (CurrentUser.Id == Reservation.Id)
                {
                    _context.Reservations.Remove(Reservation);
                    await _context.SaveChangesAsync();
                }
            }
            return(Redirect("./Index" + "?" + "buildingid=" + BuildingIdRoute.ToString() + "&departmentid=" + DepartmentIdRoute.ToString() + "&date=" + Date.ToShortDateString()));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(int roomid, int buildingid, int departmentid)
        {
            BuildingIdRoute   = buildingid;
            DepartmentIdRoute = departmentid;

            ViewData["Building"] = new SelectList(_context.Buildings, "BuildingID", "Name", buildingid);

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            AllRoomNumbers = await _context.Rooms
                             .Where(r => r.BuildingID == buildingid)
                             .Select(i => i.Number)
                             .ToListAsync();

            if (AllRoomNumbers.Contains(Room.Number))
            {
                SameNumberError = "Już istnieje pokój o tym numerze.";
                return(Page());
            }

            var roomToUpdate = await _context.Rooms.FindAsync(roomid);

            if (await TryUpdateModelAsync <Room>(
                    roomToUpdate,
                    "Room",
                    s => s.Number, s => s.Type, s => s.Spots, s => s.Equipment, s => s.BuildingID))
            {
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index", new { buildingid = BuildingIdRoute, departmentid = DepartmentIdRoute }));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync(int roomid, int buildingid, int departmentid)
        {
            Room = await _context.Rooms.FindAsync(roomid);

            if (Room != null)
            {
                _context.Rooms.Remove(Room);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index", new { buildingid = buildingid, departmentid = departmentid }));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync()
        {
            Messages = await _context.Messages
                       .AsNoTracking()
                       .ToListAsync();

            foreach (var message in Messages)
            {
                _context.Messages.Remove(message);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./List"));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> OnPostAsync(int buildingid, int departmentid)
        {
            Building = await _context.Buildings.FindAsync(buildingid);

            if (Building != null)
            {
                _context.Buildings.Remove(Building);
                await _context.SaveChangesAsync();
            }
            else
            {
                return(NotFound());
            }

            return(RedirectToPage("./Index", new { departmentid = departmentid }));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> OnPostAsync(int departmentid)
        {
            Department = await _context.Departments.FindAsync(departmentid);

            if (Department != null)
            {
                _context.Departments.Remove(Department);
                await _context.SaveChangesAsync();
            }
            else
            {
                return(NotFound());
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> OnPostAsync(int departmentid)
        {
            AllNumbers = await _context.AppUsers
                         .Select(i => i.Number)
                         .ToListAsync();

            AllOtherDepartmentsNames = await _context.Departments
                                       .Where(r => r.Name != _context.Departments.SingleOrDefault(m => m.DepartmentID == departmentid).Name)
                                       .Select(i => i.Name)
                                       .ToListAsync();

            AppUsers = await _context.AppUsers
                       .AsNoTracking()
                       .ToListAsync();

            if (AllOtherDepartmentsNames.Contains(Department.Name))
            {
                DuplicateNameExistError = "Już istnieje wydział o podanej nazwie";
                return(Page());
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!AllNumbers.Contains(Department.Administrator))
            {
                AdministratorIdError = String.Format("Nie ma takiego człeka o numerze: {0}", Department.Administrator);
                return(Page());
            }

            var departmentToUpdate = await _context.Departments.FindAsync(departmentid);

            if (await TryUpdateModelAsync <Department>(departmentToUpdate, "Department", s => s.Name, s => s.Administrator))
            {
                await _context.SaveChangesAsync();
            }

            return(Page());
        }
Exemplo n.º 10
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            AllAppUsersIDs = await _context.AppUsers
                             .Select(i => i.Number)
                             .ToListAsync();

            AllDepartmentsNames = await _context.Departments
                                  .Select(i => i.Name)
                                  .ToListAsync();

            if (!AllAppUsersIDs.Contains(Department.Administrator))
            {
                AdministratorIdError = String.Format("Nie ma takiego człeka dla ID: {0}", Department.Administrator);
                return(Page());
            }
            if (AllDepartmentsNames.Contains(Department.Name))
            {
                DuplicateNameExistError = "Już istnieje wydział o podanej nazwie";
                return(Page());
            }

            var newDepartment = new Department();

            if (await TryUpdateModelAsync <Department>(
                    newDepartment,
                    "Department", // Prefix for form value.
                    s => s.Name, s => s.Administrator))
            {
                _context.Departments.Add(newDepartment);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> OnPostAsync(int buildingid, int departmentid)
        {
            DepartmentIdRoute = departmentid;


            ViewData["DepartmentID"] = new SelectList(_context.Departments, "DepartmentID", "Name");

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            AllOtherBuildingsNames = await _context.Buildings
                                     .Where(r => r.Name != _context.Buildings.SingleOrDefault(m => m.BuildingID == buildingid).Name)
                                     .Select(r => r.Name)
                                     .AsNoTracking()
                                     .ToListAsync();

            if (AllOtherBuildingsNames.Contains(Building.Name))
            {
                DuplicateNameExistError = "Już istnieje budynek o tej nazwie.";
                return(Page());
            }

            var buildingToUpdate = await _context.Buildings.FindAsync(buildingid);

            if (await TryUpdateModelAsync <Building>(
                    buildingToUpdate,
                    "Building",
                    s => s.Name, s => s.Address, s => s.DepartmentID, s => s.GPS_E, s => s.GPS_N))
            {
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index", new { departmentid = DepartmentIdRoute }));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> OnPostAsync(int reservationid, int roomid, int buildingid, int departmentid, string date)
        {
            CurrentUser = await _userManager.GetUserAsync(base.User);

            if (CurrentUser == null)
            {
                return(base.NotFound($"Unable to load user with ID '{_userManager.GetUserId(base.User)}'."));
            }

            BuildingIdRoute   = buildingid;
            DepartmentIdRoute = departmentid;

            DateTime.TryParse(date, out var ParseDate);
            Date = ParseDate;

            DateTime.TryParse(DateInputString, out var ParseStringDate);

            ReservationIdRoute = reservationid;



            AllNumbers = await _context.AppUsers
                         .Select(i => i.Number)
                         .ToListAsync();

            AppUsers = await _context.AppUsers
                       .AsNoTracking()
                       .ToListAsync();

            Reservations = await _context.Reservations
                           .Where(r => r.ReservationID != reservationid)
                           .Where(b => b.Room.BuildingID == buildingid)
                           .Where(d => d.Date == ParseStringDate)
                           .Where(r => r.RoomID == Reservation.RoomID)
                           .AsNoTracking()
                           .ToListAsync();

            Reservation = await _context.Reservations
                          .Include(r => r.ApplicationUser)
                          .Include(r => r.Room)
                          .ThenInclude(r => r.Building)
                          .ThenInclude(r => r.Department)
                          .AsNoTracking()
                          .SingleOrDefaultAsync(m => m.ReservationID == reservationid);

            Rooms = await _context.Rooms
                    .Where(b => b.BuildingID == Reservation.Room.BuildingID)
                    .AsNoTracking().OrderBy(r => r.Number)
                    .ToListAsync();

            Hours = new List <String>
            {
                new DateTime(2018, 1, 1, 8, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 8, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 9, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 9, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 10, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 10, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 11, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 11, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 12, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 12, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 13, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 13, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 14, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 14, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 15, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 15, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 16, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 16, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 17, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 17, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 18, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 18, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 19, 00, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 19, 30, 0).ToShortTimeString(),
                new DateTime(2018, 1, 1, 20, 00, 0).ToShortTimeString()
            };



            ViewData["StartTime"] = new SelectList(Hours, Reservation.StartTime.ToShortTimeString());
            ViewData["EndTime"]   = new SelectList(Hours, Reservation.EndTime.ToShortTimeString());


            // lista, atrybut ustawiany, atrybut wyświetlany, domyślnie wybrana pozycja z listy
            ViewData["Rooms"] = new SelectList(Rooms, "RoomID", "Number", Reservation.RoomID);

            if (StartTime == EndTime)
            {
                ErrorString = "Rezerwacja musi trwać co najmniej 30 minut.";
            }
            if (StartTime > EndTime)
            {
                ErrorString = "Rezerwacja nie może się zacząć później niż skończyć.";
            }

            foreach (var item in Reservations)
            {
                if (StartTime == item.StartTime || EndTime == item.EndTime)
                {
                    ErrorString = "W tym czasie trwa inna rezerwacja.";
                }
                if (EndTime < item.EndTime && StartTime < item.StartTime && Reservation.EndTime > item.StartTime)
                {
                    ErrorString = "W tym czasie trwa inna rezerwacja.";
                }
                if (EndTime > item.EndTime && StartTime < item.StartTime)
                {
                    ErrorString = "W tym czasie trwa inna rezerwacja.";
                }
                if (EndTime > item.EndTime && StartTime > item.StartTime && Reservation.StartTime < item.EndTime)
                {
                    ErrorString = "W tym czasie trwa inna rezerwacja.";
                }
                if (EndTime < item.EndTime && StartTime > item.StartTime)
                {
                    ErrorString = "W tym czasie trwa inna rezerwacja.";
                }
            }


            if (ErrorString != null)
            {
                return(Page());
            }



            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var reservationToUpdate = await _context.Reservations
                                      .SingleOrDefaultAsync(m => m.ReservationID == reservationid);

            var currentUserRoles = await _userManager.GetRolesAsync(CurrentUser);

            if (currentUserRoles.First() == "administrator")
            {
                if (!AllNumbers.Contains(Number))
                {
                    NumberError = String.Format("Nie ma takiego człeka o numerze: {0}", Number);
                    return(Page());
                }
                reservationToUpdate.Id = AppUsers.Where(i => i.Number == Number).Select(i => i.Id).FirstOrDefault();
            }
            if (currentUserRoles.First() == "użytkownik")
            {
                reservationToUpdate.Id = CurrentUser.Id;
            }

            reservationToUpdate.RoomID    = RoomID;
            reservationToUpdate.StartTime = StartTime;
            reservationToUpdate.EndTime   = EndTime;

            reservationToUpdate.Date = ParseStringDate;
            if (await TryUpdateModelAsync <Reservation>(
                    reservationToUpdate,
                    "Reservation",
                    s => s.RoomID, s => s.Note))
            {
                await _context.SaveChangesAsync();
            }

            return(Redirect("./Details" + "?" + "reservationid=" + reservationToUpdate.ReservationID.ToString() + "&buildingid=" + BuildingIdRoute.ToString() + "&departmentid=" + DepartmentIdRoute.ToString() + "&date=" + Date.ToShortDateString()));
        }