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 ActionResult NewMessage(OutgoingMessageViewModel message) { if (ModelState.IsValid) { dataManager.Messages.SaveOutgoingMessage(message.Id, message.UserId, message.UserToId, message.Text, message.CreatedDate); return(RedirectToAction("Index", "Home")); } return(View(message)); }
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 SendMessage(OutgoingMessageViewModel msg) { try { if (ModelState.IsValid) { // The To list can be separated by comma or semicolon string[] toList = msg.Recipient.Split(MessageHelper.SupportedSeparators, StringSplitOptions.RemoveEmptyEntries); string groupId = MessageHelper.GenerateUniqueIdentifier(); GatewayConfig gwConfig = repository.First <GatewayConfig>(gc => gc.Id == msg.Channel); repository.UnitOfWork.BeginTransaction(); foreach (string to in toList) { OutgoingMessage message = new OutgoingMessage(); message.Id = MessageHelper.GenerateUniqueIdentifier(); message.GatewayId = msg.Channel; message.Recipient = to.Trim(); if (gwConfig != null) { message.Originator = gwConfig.OwnNumber; } else { message.Originator = string.Empty; } message.MessageType = msg.MessageType; message.MessageFormat = msg.MessageFormat; message.LastUpdate = DateTime.Now; message.CreateDate = message.LastUpdate; message.SrcPort = Convert.ToInt32(msg.SrcPort); message.DestPort = Convert.ToInt32(msg.DestPort); message.Status = "Pending"; message.MessageClass = msg.MessageClass; message.Priority = msg.Priority; message.StatusReport = msg.StatusReport; message.Quantity = 1; message.GroupId = groupId; message.ScheduledDate = msg.ScheduledDate; message.Message = msg.Message; if (msg.MessageType.Equals("WAP Push", StringComparison.OrdinalIgnoreCase)) { message.WapUrl = msg.WapUrl; message.WapSignal = msg.WapSignal; message.WapCreateDate = msg.WapCreateDate; message.WapExpiryDate = msg.WapExpiryDate; } repository.Add <OutgoingMessage>(message); } repository.UnitOfWork.CommitTransaction(); return(RedirectToAction("Index")); } } catch (DataException) { if (repository.UnitOfWork.IsInTransaction) { // Rollback the transaction repository.UnitOfWork.RollBackTransaction(); } // Log the error (add a variable name after DataException) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(msg)); }
/// <summary> /// Sends the message. /// </summary> /// <returns></returns> public ActionResult SendMessage() { OutgoingMessageViewModel msg = new OutgoingMessageViewModel(); return(View(msg)); }