public void MessageReaded(Guid messageID) { int userid = Context.User.Identity.GetUserId <int>(); var nickname = Context.User.Identity.NickName(); ChatMessageRepository cRepo = new ChatMessageRepository(); var message = cRepo.Get(messageID); if (message != null) { if (!message.ReadedUsers.Any(u => u.ID == userid)) { //var userManager = UserManager; message.ReadedUsers.Add(new UserSurrogate { ID = userid, NickName = Context.User.Identity.NickName() }); cRepo.Save(message); var user = UserManager.Users.Where(u => u.Id == userid).SingleOrDefault(); user.LastReadedMessage = messageID; UserManager.Update(user); } Clients.Others.MessageReaded(new UserViewModel { UserID = userid, Name = nickname }, messageID); } }
public static OutgoingMessageViewModel GetMessage(Guid messageID) { ChatMessageRepository cRepo = new ChatMessageRepository(); var messageSurrogate = cRepo.Get(messageID); OutgoingMessageViewModel result = messageSurrogate; return(result); }
public List <OutgoingMessageViewModel> ScrollMoveMessages(Guid messageID, bool Up) { int totalCount = 0; ChatMessageRepository cRepo = new ChatMessageRepository(); var message = cRepo.Get(messageID); var messages = cRepo.GetAll(null, 0, 30, out totalCount, null, (ChatMessageSurrogate u) => Up ? u.ReceivedDate <message.ReceivedDate : u.ReceivedDate> message.ReceivedDate); return(messages.Select(u => (OutgoingMessageViewModel)u).ToList());//.Cast<OutgoingMessageViewModel>().ToList(); }
public static List <OutgoingMessageViewModel> GetInitMessage(Guid lastMessageID) { List <OutgoingMessageViewModel> result = new List <OutgoingMessageViewModel>(); var cRepo = new ChatMessageRepository(); var lastMessage = cRepo.Get(lastMessageID); if (lastMessage != null) { int totalCount = 0; var beforeMessages = cRepo.GetAll(null, 30, 0, out totalCount, "date", (ChatMessageSurrogate u) => u.ReceivedDate < lastMessage.ReceivedDate); var afterMessages = cRepo.GetAll(null, 30, 0, out totalCount, "date", (ChatMessageSurrogate u) => u.ReceivedDate > lastMessage.ReceivedDate); result.AddRange(beforeMessages.Select(u => (OutgoingMessageViewModel)u).ToList()); //beforeMessages.Cast<OutgoingMessageViewModel>()); OutgoingMessageViewModel lastOutgoinMessage = lastMessage; lastOutgoinMessage.LastReadedMessage = true; result.Add(lastOutgoinMessage); result.AddRange(afterMessages.Select(u => (OutgoingMessageViewModel)u).ToList()); } return(result); }
public ActionResult UploadFile( HttpPostedFileBase File, string UniqueIdentifier, ulong ChunkNumber, int ChunkSize, int CurrentChunkSize, ulong FileSize, string FileType, string FileName, string RelativePath, int AttachType, Guid MessageID) { string result = AppendFile(File, UniqueIdentifier, ChunkNumber, ChunkSize, CurrentChunkSize, FileSize, FileType, FileName, RelativePath, MessageID); if (result != null) { try { if (!User.Identity.IsAuthenticated) { throw new Exception("Giriş yap da gel! Mevlana değiliz!"); } ChatMessageRepository cRepo = new ChatMessageRepository(); var message = cRepo.Get(MessageID); if (message == null) { throw new Exception("Mesaj bulunamadı. Açık mı arıyon hacı?"); } FileInfo fileInfo = new FileInfo(result); string extension = fileInfo.Extension; string newFileName = Guid.NewGuid().ToString().Replace("-", "_") + extension; string chatFileDir = Server.MapPath(ChatFileDir); if (!Directory.Exists(chatFileDir)) { Directory.CreateDirectory(chatFileDir); } string fullFilePath = string.Format("{0}\\{1}", chatFileDir, newFileName); fileInfo.MoveTo(fullFilePath); string absoluteFilePath = Url.Content(string.Format("{0}/{1}", ChatFileDir, newFileName)); try { MessageFileSurrogate fileSurrogate = new MessageFileSurrogate(); fileSurrogate.FilePath = absoluteFilePath; fileSurrogate.AttachType = AttachType; message.Files.Add(fileSurrogate); cRepo.Save(message); } catch (Exception) { if (System.IO.File.Exists(fullFilePath)) { System.IO.File.Delete(fullFilePath); } throw; } return(Json(new { Result = "OK", FilePath = absoluteFilePath })); } catch (Exception e) { return(Json(new { Result = "ERROR", ErrorMessage = e.Message })); } } return(Json(new { Result = "OK", imagePath = "" }));; }