/// <summary> /// Get page of friends of user by Id /// </summary> /// <param name="model"><see cref="UserPaginationReceiveModel"/></param> /// <returns><see cref="UserListResponseModel"/></returns> public List <UserListResponseModel> ReadPage(UserPaginationReceiveModel model) { using (var context = new DatabaseContext()) { var friends = string.IsNullOrEmpty(model.SearchingUserName) ? context.Friends .Where(f => f.UserId == model.UserId) .Select(f => context.Users.FirstOrDefault(u => u.Id == f.FriendId)) : context.Friends .Where(f => f.UserId == model.UserId) .Select(f => context.Users.FirstOrDefault(u => u.Id == f.FriendId)) .ToList() .Where(u => u.UserName.StartsWith(model.SearchingUserName, true, CultureInfo.InvariantCulture)); friends.Reverse(); return(friends .Skip(model.Page * 15) .Take(15) .Select(u => new UserListResponseModel() { UserId = u.Id, UserName = u.UserName, Picture = new FileModel() { FileName = u.PictureName, Extension = u.PictureExtension, BinaryForm = u.Picture }, IsOnline = u.IsOnline }) .ToList()); } }
//TODO : изменить модель NotificationResponseModel и изменить метод /// <summary> /// Get page of notifications of user by Id /// </summary> /// <param name="model"><see cref="UserPaginationReceiveModel"/></param> /// <returns><see cref="NotificationResponseModel"/></returns> public List <NotificationResponseModel> ReadPage(UserPaginationReceiveModel model) { using (var context = new DatabaseContext()) { var notifications = context.Notifications .Where(n => n.ToUserId == model.UserId && n.IsAccepted == false) .Include(n => n.FromUser); notifications.Reverse(); return(notifications .Skip(model.Page * 10) .Take(10) .Select(n => new NotificationResponseModel() { Id = n.Id, Message = n.Message, FromUserId = n.FromUserId, FromUserName = n.FromUser.UserName, UserPicture = new FileModel() { FileName = n.FromUser.PictureName, Extension = n.FromUser.PictureExtension, BinaryForm = n.FromUser.Picture } }) .ToList()); } }
/// <summary> /// Get page of users by prefix of userName or without prefix /// </summary> /// <param name="userModel"><see cref="UserPaginationReceiveModel"/></param> /// <returns><see cref="UserListResponseModel"/></returns> public List <UserListResponseModel> ReadPage(UserPaginationReceiveModel userModel) { using (DatabaseContext context = new DatabaseContext()) { var users = string.IsNullOrEmpty(userModel.SearchingUserName) ? context.Users .Where(u => u.Id != userModel.UserId) : context.Users .Where(u => u.Id != userModel.UserId) .ToList() .Where(u => u.UserName.StartsWith(userModel.SearchingUserName, true, CultureInfo.InvariantCulture)); users.Reverse(); return(users .Skip(userModel.Page * 15) .Take(15) .Select(u => new UserListResponseModel() { UserId = u.Id, UserName = u.UserName, Picture = new FileModel() { FileName = u.PictureName, Extension = u.PictureExtension, BinaryForm = u.Picture }, IsOnline = u.IsOnline }) .ToList()); } }
/// <summary> /// Get page of chats of user by Id /// </summary> /// <param name="userPagination"><see cref="UserPaginationReceiveModel"/></param> /// <returns>List of ChatResponceModel <see cref="ChatResponseModel"/></returns> public List <ChatResponseModel> ReadPage(UserPaginationReceiveModel userPagination) { using (DatabaseContext context = new DatabaseContext()) { var relationChatUsers = context.RelationChatUsers .Where(rcu => rcu.UserId == userPagination.UserId) .Include(rcu => rcu.Chat) .Select(rcu => rcu.Chat); relationChatUsers.Reverse(); return(relationChatUsers .Skip(userPagination.Page * 10) .Take(10) .Select(chat => new ChatResponseModel() { Id = chat.Id, ChatName = chat.ChatName, CreatorId = chat.CreatorId, ChatUsers = context.RelationChatUsers .Where(rcu => rcu.ChatId == chat.Id) .Include(rcu => rcu.User) .Select(rcu => new ChatUserResponseModel() { Id = rcu.User.Id, UserName = rcu.User.UserName, Picture = new FileModel() { FileName = rcu.User.PictureName, BinaryForm = rcu.User.Picture, Extension = rcu.User.PictureExtension }, IsOnline = rcu.User.IsOnline }) .ToList(), CountUsers = chat.CountUsers, LastMessages = _messageLogic.ReadPage(new ChatPaginationReceiveModel() { ChatId = chat.Id, Page = 0 }) }) .ToList()); } }
public OperationResultInfo GetPageOfChats(UserPaginationReceiveModel model) { try { var chatsPage = _chatLogic.ReadPage(model); return(new OperationResultInfo() { ErrorInfo = string.Empty, OperationResult = OperationsResults.Successfully, JsonData = chatsPage, ToListener = ListenerType.ChatListListener }); } catch (Exception ex) { return(new OperationResultInfo() { ErrorInfo = ex.Message, OperationResult = OperationsResults.Unsuccessfully, ToListener = ListenerType.ChatListListener }); } }
public OperationResultInfo GetNotificationsPage(UserPaginationReceiveModel model) { try { var notifications = _notificationLogic.ReadPage(model); return(new OperationResultInfo() { ErrorInfo = string.Empty, OperationResult = OperationsResults.Successfully, ToListener = ListenerType.NotificationListListener, JsonData = notifications }); } catch (Exception ex) { return(new OperationResultInfo() { ErrorInfo = ex.Message, OperationResult = OperationsResults.Unsuccessfully, ToListener = ListenerType.NotificationListListener }); } }