Пример #1
0
        public MessageDTO(Message message)
        {
            Id = message.Id;
            string path;

            using (Meseger ctx = new Meseger())
            {
                message    = ctx.Messages.SingleOrDefault(a => a.Id == Id);
                Text       = message.Text;
                DateTime   = message.DateTime;
                SenderId   = message.Sender.Id;
                ReciversId = message.Receivers.Select(a => a.Id).ToArray <int>();
                ChatId     = message.Chat.Id;
                if (message.File != null)
                {
                    path = message.File.Path;
                }
                else
                {
                    path = String.Empty;
                }
            }
            if (path != String.Empty && System.IO.File.Exists(path))
            {
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(path);
                FileName = fileInfo.Name;
            }
            else
            {
                FileName = String.Empty;
            }
        }
Пример #2
0
 public FileDTO(Model.File file)
 {
     Model.File tmp;
     using (Meseger ctx = new Meseger())
     {
         tmp    = ctx.Files.SingleOrDefault(a => a.Id == file.Id);
         ChatId = tmp.Message.Chat.Id;
     }
     FileInfo   = new FileInfo(tmp.Path);
     FileStream = new FileStream(tmp.Path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
     FileName   = FileInfo.Name;
 }