public void SetMessageReadForSender(int msgId) { IMessagePrive msg = GetMessage(msgId); msg.IsFromNewMessage = false; _dataContext.SubmitChanges(); }
public void SetMessageUnReadForReceiver(int msgId) { IMessagePrive msg = GetMessage(msgId); msg.IsToNewMessage = true; _dataContext.SubmitChanges(); }
public void DeleteMessage(int MsgId) { IMessagePrive msg = GetMessage(MsgId); _dataContext.cov_MessagePrives.DeleteOnSubmit((cov_MessagePrive)msg); _dataContext.SubmitChanges(); }
public bool SendNewMessageNotify(IMessagePrive msg) { const string templateName = "PrivateMessageNotify.txt"; // const string mailTemplatePath = "~/MailTemplates/Signup.txt"; bool IsHTML = templateName.Contains(".htm"); string siteName = CovCakeConfiguration.SiteName; string from = CovCakeConfiguration.SiteNotifierEmail; string fromEmailName = siteName; string toEmail = msg.ToUser.Email; string subject = "CoVoyage.net : " + msg.FromUser.PrenomNom + " vous a envoyé un message sur CoVoyage"; // msgResponseLink = CovCakeConfiguration.SiteUrl + msgResponseLink; // msgResponseLink = this.Url.CovCakeActionUrl("ShowMessage", "Messages", new RouteValueDictionary { { "MsgId", newMsgId } }, "http", CovCakeConfiguration.SiteName); string msgResponseLink = this.RefController.Url.CovCakeActionUrl("ShowMessage", "Messages", new { MsgId = msg.MsgId }); string body = this.LoadMailTemplate(templateName); string relatedProjSentence = ""; if (msg.ProjetRelatedId != null) { relatedProjSentence = "concernant le voyage " + msg.ProjetRelated.GetShortDisplayName(); } body = body.Replace("#DISPLAYNAME#", msg.ToUser.Prenom); body = body.Replace("#SENDERDISPLAYNAME#", msg.FromUser.Prenom); body = body.Replace("#MESSAGE#", msg.TextMessage); body = body.Replace("#SUBJECT#", msg.SujetMessage); body = body.Replace("#SHOWMESSAGELINK#", msgResponseLink); body = body.Replace("#RELATEDTOPROJETSENTENCE#", relatedProjSentence); try { MailAddress fromAddress = new MailAddress(from, fromEmailName); // this.To.Add(new MailAddress(email)); this.SendMailAsync(fromAddress, toEmail, subject, body, IsHTML); } catch (Exception ex) { CovCake.Log.Exception.cError("SendNewMessageNotify userId=" + CovCake.GetCurrentUserId().ToString(), ex); return(false); } return(true); }
private IMessagePrive InsertNewMessage(Guid fromUserId, Guid toUserId, string sujet, string message, int?responseMsgId, int?projetRelatedId) { IMessagePrive newMsg = Data.MessageDataAccess.CreateMessage(); newMsg.DateMessage = DateTime.Now; newMsg.FromUserId = fromUserId; newMsg.ToUserId = toUserId; newMsg.ProjetRelatedId = projetRelatedId; newMsg.IsFromNewMessage = false; newMsg.IsToNewMessage = true; newMsg.SujetMessage = sujet; newMsg.Ip = Request.UserHostAddress; newMsg.TextMessage = message; newMsg.MsgResponseId = responseMsgId; //Insert in DB Data.MessageDataAccess.InsertMessage(newMsg); return(newMsg); }
public static bool IsNewThread(this IMessagePrive msg) { // throw new NotImplementedException(); Guid currUserId = CovCake.GetCurrentUserId(); if (msg.ToUserId == currUserId) { return(msg.IsToNewMessage); } else if (msg.FromUserId == currUserId) { return(msg.IsFromNewMessage); } else { throw new Exception("Ce message ne devrait pas concerner cet utilisateur (ni ToUser ni FromUser). UserId: " + currUserId.ToString()); } //return (msg.MsgAnswers.NewMessagesFor(currUserId).Count() > 0); // return (CovCake.DataProvider.MessageDataAccess.NewMessagesInThread(msg.MsgId, currUserId).Count() > 0); }
public void InsertMessage(IMessagePrive message) { this._dataContext.cov_MessagePrives.InsertOnSubmit((cov_MessagePrive)message); this._dataContext.SubmitChanges(); }
public static bool IsThreadHead(this IMessagePrive msg) { return(msg.MsgResponseId == null); }
// [TrimActionParams] public ActionResult SendSingleMessage(SendMessageViewData sentMsgData) { //Si le message répond à un autre on met la tête de thread a non lu. throw new Exception("Exception non catchée"); const int MAXMESSAGELENGHT = 4000; int newMsgId = -1; try { /* * System.Diagnostics.Debug.WriteLine("homosexuel : " + sentMsgData.sujet); * System.Diagnostics.Trace.WriteLine("homosexuel : " + sentMsgData.sujet); */ //bool ajax = Request.IsAjaxRequest(); //C'est moche mais sa saoul //21/07/09 20:12 var sujet = sentMsgData.sujet; var message = sentMsgData.message; var toUserId = sentMsgData.toUserId; var fromUserId = sentMsgData.fromUserId; var relatedProjetId = sentMsgData.relatedProjetId;//.Trim(); var responseMsgId = sentMsgData.responseMsgId; int?relProjId = (!relatedProjetId.IsNullOrEmpty()) ? (int?)int.Parse(relatedProjetId) : null; int?respIdMsg = (!responseMsgId.IsNullOrEmpty()) ? (int?)int.Parse(responseMsgId) : null; newMsgId = respIdMsg ?? newMsgId; if (message.Length > MAXMESSAGELENGHT) { this.ModelState.AddModelError("message", "Votre message est trop long. (plus de " + MAXMESSAGELENGHT + " caractères)"); } if (!this.ModelState.IsValid) { throw new Exception("Message trop long"); } if (sujet.IsNullOrEmpty() && respIdMsg.HasValue) { IMessagePrive originalMsg = Data.MessageDataAccess.GetMessage(respIdMsg.Value); originalMsg.IsFromNewMessage = true; // le thread est considéré comme nouveau originalMsg.IsToNewMessage = true; sujet = "RE : " + originalMsg.SujetMessage; } //sujet généré automatiqment si nul if (sujet.IsNullOrEmpty() && relProjId != null) { sujet = GetDefaultMessageSubject(relProjId.Value); } else if ((sujet).IsNullOrEmpty()) { sujet = "(sans sujet)"; } IMessagePrive newMsg = InsertNewMessage(new Guid(fromUserId), new Guid(toUserId), sujet, message, respIdMsg, relProjId); newMsgId = newMsg.MsgId; //Envoi de l'email de notification this.CovCakeMailer.SendNewMessageNotify(newMsg); } catch (Exception e) { if (Request.IsAjaxRequest()) { return(Json(false)); } else { this.ModelState.AddModelError("_FORMMSG", "Le message n'a pas pu être envoyé"); TempData["ModelError"] = this.ModelState; return(RedirectToAction("ShowMessage", new { msgId = newMsgId })); } // return PartialView("sendMessageError"); } if (Request.IsAjaxRequest()) { return(Json(true)); // new TextViewResult("Le messsage a bien été envoyé"); // PartialView("SendMessageModal", sendMessageData); } else { return(RedirectToAction("ShowMessage", new { msgId = newMsgId })); } }