public int CancelBooking(int id)
        {
            var bookingToDelete = RoomTime.SingleOrDefault(b => b.Id == id);

            RoomTime.Remove(bookingToDelete);
            return(SaveChanges());
        }
        public int UpdateBooking(UpdateEventVM viewModel)
        {
            var bookingToUpdate = RoomTime.SingleOrDefault(b => b.Id == viewModel.BId);

            bookingToUpdate.RId         = viewModel.RoomId;
            bookingToUpdate.StartTime   = viewModel.Start;
            bookingToUpdate.EndTime     = viewModel.End;
            bookingToUpdate.Description = viewModel.Description;

            return(SaveChanges());
        }
        public int DeleteRoom(int id)
        {
            var roomToDelete = Room.SingleOrDefault(b => b.Id == id);

            foreach (var booking in RoomTime.Where(rt => rt.RId == id))
            {
                RoomTime.Remove(booking);
            }

            Room.Remove(roomToDelete);
            return(SaveChanges());
        }
        public async Task BookRoom(CreateEventVM viewModel, string userName)
        {
            var user = await userManager.FindByNameAsync(userName);

            var userId      = user.Id;
            var newRoomTime = new RoomTime
            {
                RId         = viewModel.RoomId,
                UId         = userId,
                StartTime   = viewModel.Start,
                EndTime     = viewModel.End,
                Description = viewModel.Description
            };

            this.RoomTime.Add(newRoomTime);
            await this.SaveChangesAsync();
        }
        public ShowBookingVM[] GetBooking(string id)
        {
            var bookings = Room
                           .Join(RoomTime.Where(c => c.UId == id && c.EndTime > DateTime.Now),
                                 r => r.Id,
                                 rt => rt.RId,
                                 (r, rt) => new ShowBookingVM
            {
                Id          = rt.Id,
                RoomName    = r.Name,
                Start       = rt.StartTime,
                End         = rt.EndTime,
                Description = rt.Description
            });

            return(bookings.ToArray());;
        }
        public int DeleteUser(string id)
        {
            var userToDelete = Users.Include(p => p.RoomTime).SingleOrDefault(b => b.Id == id);

            if (userToDelete != null)
            {
                foreach (var booking in userToDelete.RoomTime)
                {
                    RoomTime.Remove(booking);
                }

                Users.Remove(userToDelete);
                return(SaveChanges());
            }
            else
            {
                return(0);
            }
        }
        public List <EventObject> GetRoomVM(int id)
        {
            var events    = new List <EventObject>();
            var newRoomVM = new RoomVM();

            /* Hitta rummet med parameter id i tabellen Room i db */
            var room = Room.SingleOrDefault(r => r.Id == id);

            if (room != null)
            {
                newRoomVM.RoomName      = room.Name;
                newRoomVM.Capacity      = room.Capacity;
                newRoomVM.HasProjector  = room.HasProjector;
                newRoomVM.HasTvScreen   = room.HasTvScreen;
                newRoomVM.HasWhiteBoard = room.HasWhiteBoard;


                newRoomVM.RoomTimeAndUser = RoomTime
                                            .Join(
                    Users,
                    rt => rt.UId,
                    u => u.Id,
                    (rt, u) => new RoomTimeAndUser
                {
                    RId         = rt.RId,
                    UId         = u.Id,
                    FirstName   = u.FirstName,
                    LastName    = u.LastName,
                    StartTime   = rt.StartTime,
                    EndTime     = rt.EndTime,
                    Description = rt.Description
                })
                                            .Where(x => x.RId == id /*&& x.EndTime >= DateTime.Now*/)
                                            .ToList();

                foreach (var item in newRoomVM.RoomTimeAndUser)
                {
                    events.Add(new EventObject(item.FirstName + " " + item.LastName, item.StartTime, item.EndTime, item.Description));
                }
            }
            return(events);
        }