Ejemplo n.º 1
0
        public static RabbitUser GetSingleUser(int userId)
        {
            using var db = new RabbitChatContext();
            // return db.RabbitUsers.Include(user => user.Friends).Single(user => user.RabbitUserId == userId);

            return(new RabbitUser());
        }
Ejemplo n.º 2
0
        public Room CreatePersonalRoom(CreatePersonalRoomRequest request)
        {
            using var db = new RabbitChatContext();

            var first  = db.RabbitUsers.Single(user => user.RabbitUserId == request.CreatingUserId);
            var second = db.RabbitUsers.Single(user => user.RabbitUserId == request.InvitedUserId);

            var room = new Room
            {
                RoomName = request.RoomName
            };

            room.RabbitUserLink = new List <RabbitUserRoom>
            {
                new RabbitUserRoom
                {
                    RabbitUser = first,
                    Room       = room
                },
                new RabbitUserRoom
                {
                    RabbitUser = second,
                    Room       = room
                }
            };

            db.Add(room);
            db.SaveChanges();

            return(room);
        }
Ejemplo n.º 3
0
        public List <RabbitUser> GetFriends([FromBody] int userId)
        {
            using var db = new RabbitChatContext();

            var p = db.RabbitUsers.Include(x => x.Friends).Single(user => user.RabbitUserId == userId);

            return(p.Friends.ToList());
        }
        public List <Message> GetAllMessagesFromRoom(int roomId)
        {
            using var db = new RabbitChatContext();
            var room = db.Rooms.Include(x => x.Messages)
                       .First(x => x.RoomId == roomId);

            return(room.Messages.ToList());
        }
Ejemplo n.º 5
0
        public void AddRoom()
        {
            using var db = new RabbitChatContext();
            var unit = db.ActUnits.Include(u => u.ActUnitRooms).First();

            unit.ActUnitRooms.Add(new ActRoom {
                ActRoomName = "newroomtestingthisisinaunit"
            });
            db.SaveChanges();
        }
Ejemplo n.º 6
0
 public void CreateUser(CreateUserRequest createUserRequest)
 {
     using var db = new RabbitChatContext();
     db.Add(new RabbitUser
     {
         Username = createUserRequest.Username,
         Password = createUserRequest.Password,
         Alias    = createUserRequest.Alias
     });
     db.SaveChanges();
 }
Ejemplo n.º 7
0
        public void AddBed()
        {
            using var db = new RabbitChatContext();
            var room = db.ActRooms.Include(r => r.ActRoomBeds).First();

            room.ActRoomBeds.Add(new ActBed
            {
                ActBedName = "firstbed"
            });
            db.SaveChanges();
        }
Ejemplo n.º 8
0
        public void AddFriend(AddFriendRequest addFriendRequest)
        {
            using var db = new RabbitChatContext();

            var sendingUser = db.RabbitUsers.Include(x => x.Friends)
                              .Single(user => user.RabbitUserId == addFriendRequest.SendingUserId);
            var requestedUser = db.RabbitUsers.Include(x => x.Friends)
                                .Single(user => user.Username == addFriendRequest.RequestedFriendUsername);

            sendingUser.Friends.Add(requestedUser);
            db.SaveChanges();
        }
 public RabbitUser SimpleSignIn(SimpleSignInRequest simpleSignInRequest)
 {
     try
     {
         using var db = new RabbitChatContext();
         return(db.RabbitUsers.Single(user =>
                                      user.Username == simpleSignInRequest.Username && user.Password == simpleSignInRequest.Password));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
        public void CreateMessage(CreateMessageRequest createMessageRequest)
        {
            using var db = new RabbitChatContext();
            var room = db.Rooms.Include(x => x.Messages)
                       .First(x => x.RoomId == createMessageRequest.RoomId);

            room.Messages.Add(new Message
            {
                MessageContent = createMessageRequest.Content,
                RabbitUserId   = createMessageRequest.SendingUserId,
                TimeSent       = DateTime.Now
            });

            db.SaveChanges();
        }
Ejemplo n.º 11
0
        public ActBed GetBedWithEverything()
        {
            using var db = new RabbitChatContext();
            var test  = db.ActBeds.First();
            var test1 = db.ActRooms.First(x => x.ActRoomBeds.Contains(test));
            var bed   = new ActBed
            {
                ActBedId   = test.ActBedId,
                ActBedName = test.ActBedName,
                ActRoom    = test1,
                ActUnit    = db.ActUnits.First(x => x.ActUnitRooms.Contains(test1))
            };

            return(bed);
        }
        public static void OpenPersonalRoom(PersonalRoomRequest request)
        {
            using var db = new RabbitChatContext();

            /*
             * var personalRoom = db.Rooms.Include(x => x.Users).FirstOrDefault(room => room.Users.Count(user =>
             *  user.RabbitUserId == request.FriendId || user.RabbitUserId == request.RequestUserId) == 2);
             *
             * if (personalRoom == null)
             * {
             *  CreatePersonalRoom(request);
             * }
             *
             * return personalRoom;
             */
        }
        public static void CreatePersonalRoom(PersonalRoomRequest request)
        {
            using var db = new RabbitChatContext();

            /*
             * db.Rooms.Add(new Room
             * {
             *  RoomName = "test",
             *  Users = new List<RabbitUser>
             *  {
             *      db.RabbitUsers.Single(user => user.RabbitUserId == request.RequestUserId),
             *      db.RabbitUsers.Single(user => user.RabbitUserId == request.FriendId)
             *  }
             * });
             */
            db.SaveChanges();
        }
Ejemplo n.º 14
0
        public ActUnit GetUnitWithEverything()
        {
            using var db = new RabbitChatContext();
            var totalUnit = db.ActUnits.Include(u => u.ActUnitRooms).First();
            var finalUnit = new ActUnit
            {
                ActUnitId    = totalUnit.ActUnitId,
                ActUnitName  = totalUnit.ActUnitName,
                ActUnitRooms = new List <ActRoom>()
            };

            foreach (var room in totalUnit.ActUnitRooms)
            {
                finalUnit.ActUnitRooms.Add(db.ActRooms.Include(v => v.ActRoomBeds).Single(z => z.ActRoomId == room.ActRoomId));
            }
            return(finalUnit);
        }
Ejemplo n.º 15
0
 public RabbitUser GetUser([FromBody] int userId)
 {
     using var db = new RabbitChatContext();
     return(db.RabbitUsers.Include(x => x.Friends).Single(user => user.RabbitUserId == userId));
 }
Ejemplo n.º 16
0
        public void OpenPersonalRoom(PersonalRoomRequest request)
        {
            using var db = new RabbitChatContext();

            var room = db.Rooms.Include(x => x.RabbitUserLink)
        }