コード例 #1
0
        public async Task <MessageDTO> GetMessageById(int id)
        {
            DAL.Entities.Message message = await Database.MessageManager.GetById(id);

            MessageDTO result;

            if (message != null)
            {
                result = new MessageDTO
                {
                    Id      = message.Id,
                    Content = message.Content,
                    Time    = message.Time
                };
                result.Sender = new UserDTO
                {
                    Id       = message.Sender.Id,
                    Name     = message.Sender.Name,
                    UserName = message.Sender.ApplicationUser.UserName
                };
                result.Dialog = new DialogDTO
                {
                    Id   = message.Dialog.Id,
                    Name = message.Dialog.Name
                };
            }
            else
            {
                result = null;
            }
            return(result);
        }
コード例 #2
0
        public async Task EditMessage(MessageDTO messageDto)
        {
            DAL.Entities.Message message = await Database.MessageManager.GetById(messageDto.Id);

            message.Content = messageDto.Content;
            await Database.MessageManager.Update(message);

            await Database.SaveAsync();
        }
コード例 #3
0
        public async Task <int> PostMessageToDialog(DialogDTO dialog, UserDTO user, MessageDTO message)
        {
            DAL.Entities.Dialog dialogEnt = await Database.DialogManager.GetById(dialog.Id);

            DAL.Entities.ClientProfile userEnt = await Database.ClientManager.GetById(user.Id);

            DAL.Entities.Message newMessage = new DAL.Entities.Message
            {
                Content = message.Content
            };
            newMessage.Time   = DateTime.Now;
            newMessage.Sender = userEnt;
            newMessage.Dialog = dialogEnt;
            await Database.MessageManager.Create(newMessage);

            await Database.SaveAsync();

            return(newMessage.Id);
        }