예제 #1
0
 public void SendToUser(User_Master obj)
 {
     using (LystenEntities db = new LystenEntities())
     {
         try
         {
             var    template     = db.EmailTemplates.Where(x => x.SystemName == "system.user.Password").FirstOrDefault();
             var    emailaccount = db.Settings.Where(x => x.Name == "SendGrid.Key").FirstOrDefault();
             var    Emailfrom    = db.Settings.Where(x => x.Name == "SendGrid.FromMail").FirstOrDefault();
             string body         = template.Body;
             body = body.Replace("{Fullname}", obj.Displayname);
             body = body.Replace("{Username}", obj.Email);
             body = body.Replace("{Password}", obj.Password);
             var res = SendGridServices.Execute(emailaccount.Value, body, Emailfrom.Value, obj.Email, template.Subject);
         }
         catch (Exception ex)
         {
             CommonServices.ErrorLogging(ex);
             throw ex;
         }
     }
 }
예제 #2
0
        public void appServer_NewMessageReceived(WebSocketSession session, string message)
        {
            try
            {
                ResultClass result = new ResultClass();

                string baseURL = (WebConfigurationManager.AppSettings["WebSiteUrl"]);
                baseURL += (WebConfigurationManager.AppSettings["userimagepath"]).Replace("~", "");

                var Message = message.Split(',')[2].Split(':')[1];
                var UserId  = message.Split(',')[0].Split(':')[1];
                var GroupId = message.Split(',')[1].Split(':')[1];

                int GId = Convert.ToInt32(GroupId);
                int Uid = Convert.ToInt32(UserId);


                List <WebSocketSessionDb> list = new List <WebSocketSessionDb>();
                MessageModel MessagesModel     = new MessageModel();
                using (LystenEntities db = new LystenEntities())
                {
                    Message ms = new Message()
                    {
                        Body            = Message,
                        CreatedDate     = System.DateTime.Now,
                        ParentMessageId = 0,
                        CreatorId       = Uid
                    };
                    db.Messages.Add(ms);
                    db.SaveChanges();

                    MessageRecipient MR = new MessageRecipient()
                    {
                        RecipientGroupId = GId,
                        RecipientId      = null,
                        MessageId        = ms.Id,
                        IsRead           = false
                    };
                    db.MessageRecipients.Add(MR);
                    db.SaveChanges();


                    int gid = Convert.ToInt32(GroupId);
                    list = db.WebSocketSessionDbs.Where(x => x.GroupID == gid).ToList();

                    MessagesModel = new MessageModel()
                    {
                        MessageId        = ms.Id,
                        Body             = ms.Body,
                        RecipientGroupId = GId,
                        CreatorId        = Uid,
                        IsRead           = false,
                        CreatedDate      = Convert.ToDateTime(ms.CreatedDate).ToString("dd MM yyyy HH:MM"),
                        Image            = US.GetFavouriteImage(baseURL, Uid),
                        CreatorName      = db.User_Master.Where(y => y.Id == Uid).Select(y => y.FullName).FirstOrDefault() == null ? "" : db.User_Master.Where(y => y.Id == Uid).Select(y => y.FullName).FirstOrDefault(),
                        ParentMessageId  = 0,
                        ExpiryDate       = System.DateTime.Now,
                        RecipientId      = 0
                    };
                    result.Code = (int)HttpStatusCode.OK;
                    result.Msg  = ap.Success;
                    result.Data = MessagesModel;
                }
                var json = new JavaScriptSerializer().Serialize(result);
                foreach (var item in list)
                {
                    if (item.UserId.Value != Uid)
                    {
                        foreach (WebSocketSession session1 in appServer.GetAllSessions().Where(x => x.SessionID == item.SessionId))
                        {
                            session1.Send(json);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
            }
        }