public MessagePreviewDTO Get(int id, UserDTO userDTO) { using (var Data = DataFactory.Get()) { var user = GetUserService.Get(userDTO, Data); var message = Data.MessageRepository.Get().FirstOrDefault(x => x.Id == id); if (message == null || !MessageRules.CanRead(user, message)) { return(null); } return(forumDTOHelper.GetDTO(message)); } }
public MessageDTO GetDTO(Message message, User user) { if (message == null) { return(null); } return(new MessageDTO { LastEditor = DTOHelper.GetUser(message.LastEditor), LastEditTime = message.LastEditTime, Owner = DTOHelper.GetUser(message.Owner), Time = message.Time, Text = message.Text, Id = message.Id, Route = GetRoute(message), Access = new AccessDTO { CanDelete = MessageRules.CanDelete(user, message), CanRead = MessageRules.CanRead(user, message), CanUpdate = MessageRules.CanEdit(user, message) } }); }