public Guid?SendMessage(IncomingMessageViewModel message) { try { int userID = HttpContext.Current.User.Identity.GetUserId <int>(); string nickName = HttpContext.Current.User.Identity.NickName(); ChatMessageRepository cRepo = new ChatMessageRepository(); var messageSurrogate = cRepo.CreateNewInstance(message.Message); //messageSurrogate.AttachType = (byte)message.AttachType; messageSurrogate.ReplyToMessageID = message.ReplyToMessageID; messageSurrogate.UserID = userID; messageSurrogate.ReceivedDate = DateTime.Now; cRepo.Save(messageSurrogate); OutgoingMessageViewModel outgoingMessage = messageSurrogate; Clients.All.IncomingMessage(outgoingMessage); //if ((AttachType)messageSurrogate.AttachType != AttachType.None) //{ // this.Clients.Caller.StartMessageFileUpload(messageSurrogate.ID); //} return(messageSurrogate.ID); } catch { return(null); } }
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 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 = "" }));; }