private void InsertMessage(ChatMessageDto message)
 {
     try
     {
         _chatService.Create(message);
     }
     catch (Exception ex)
     {
         return;
     }
 }
Beispiel #2
0
        public IActionResult Index(Guid Id)
        {
            byte[]  userArray;
            bool    userAvailable = HttpContext.Session.TryGetValue("User", out userArray);
            UserDto user          = null;

            if (userAvailable)
            {
                user = (UserDto)userArray.ToObject();
            }
            RoomDto room = _roomService.RetrieveAll().Data.ToList().Where(x => x.Id == Id).FirstOrDefault();

            if (room != null)
            {
                PagedResult <UserRoomDto> userRooms = _userRoomService.RetrieveAll(x => x.UserID == user.Id && x.RoomID == room.Id);
                UserRoomDto userRoom = userRooms != null && userRooms.Paging.Total > 0 ? userRooms.Data.ElementAt(0) : null;
                if (userRooms == null || userRooms.Paging.Total < 1)
                {
                    userRoom = new UserRoomDto()
                    {
                        UserID   = user.Id,
                        RoomID   = room.Id,
                        JoinedAt = DateTime.Now,
                    };
                    _userRoomService.Create(userRoom);
                }
                PagedResult <ChatMessageDto> roomChats = _chatService.RetrieveAll(x => x.RoomID == room.Id && x.CreatedAt >= userRoom.JoinedAt);
                if (roomChats != null && roomChats.Paging.Total > 0)
                {
                    foreach (ChatMessageDto mess in roomChats.Data)
                    {
                        mess.User = _userService.Retrieve(mess.UserID);
                    }
                }
                HttpContext.Session.Set("Room", room.ToByteArray());
                ChatViewModel vm = new ChatViewModel()
                {
                    UserID = userRoom.UserID,
                    RoomID = room.Id,
                    Chats  = roomChats.Data.ToList()
                };
                return(View("Index", vm));
            }
            else
            {
                return(Redirect("/Rooms/Index"));
            }
        }
Beispiel #3
0
        public IActionResult Index(string userName)
        {
            UserDto user = this.userService.RetrieveAll(x => x.Name == userName).Data.FirstOrDefault();

            if (user == null)
            {
                user = new UserDto()
                {
                    Name = userName,
                    Id   = Guid.NewGuid()
                };
                user = userService.Create(user);
            }
            HttpContext.Session.Set("User", user.ToByteArray());
            return(Redirect("/Rooms/Index"));
        }
Beispiel #4
0
 public IActionResult New(Room room)
 {
     if (ModelState.IsValid)
     {
         RoomDto exixtingRoom = roomService.RetrieveAll().Data.Where(x => x.Name == room.Name).FirstOrDefault();
         if(exixtingRoom == null)
         {
             RoomDto newRoom = new RoomDto()
             {
                 Id = Guid.NewGuid(),
                 Name = room.Name,
                 Description = room.Description
             };
             roomService.Create(newRoom);
         }
         return Redirect("/Rooms/Index");
     }
     return View("NewRoom");
 }