示例#1
0
        public static ChatsViewModel FromDb(List <Chat> chatsDb, string userId = null, int studentId = 0)
        {
            ChatsViewModel model = new ChatsViewModel()
            {
                Title = chatsDb.First().Title,
                Chats = new List <ChatViewModel>()
            };

            foreach (Chat chatDb in chatsDb)
            {
                model.Chats.Add(ChatViewModel.FromDb(chatDb, userId, studentId));
            }

            return(model);
        }
示例#2
0
        public static ChatViewModel FromDb(Chat chatDb, string userId = null, int studentId = 0)
        {
            ChatViewModel model = new ChatViewModel()
            {
                Content       = chatDb.Content,
                AddedAt       = chatDb.AddedAt.ToString("dd.MM.yyyy HH:mm:ss"),
                Author        = chatDb.SenderStudent != null ? chatDb.SenderStudent.FirstName + " " + chatDb.SenderStudent.LastName : chatDb.SenderUser.FirstName + " " + chatDb.SenderUser.LastName,
                RealFileName  = chatDb.File != null ? chatDb.File.RealFileName : string.Empty,
                SavedFileName = chatDb.File != null ? chatDb.File.SavedFileName : string.Empty
            };

            if (!string.IsNullOrEmpty(userId))
            {
                model.IsFromMe = chatDb.SenderUserId == userId;
            }
            else if (studentId != 0)
            {
                model.IsFromMe = chatDb.SenderStudentId == studentId;
            }

            return(model);
        }