Пример #1
0
        public static GetMessageResponse GetMessags()
        {
            GetMessageResponse Response = new GetMessageResponse();

            SendMessageRequest WellcomeNewMessage = new SendMessageRequest();

            List<Message> Messgase = GetAllMessages();

            WellcomeNewMessage.Message = "wellcome ";

            User _CurrentUser = null;

            if (Messgase.Count > 0)
            {
                Message message = Messgase.OrderByDescending(u => u.ID).FirstOrDefault();
                _CurrentUser = new User();
                _CurrentUser.UserID = Convert.ToInt16(message.ID + 1);
            }
            else
            {
                _CurrentUser.UserID = 100;
            }

            Response.Messages = Messgase.OrderByDescending(u => u.Time).ToList();

            if (Response.Messages.Count > 0)
            {
                _CurrentUser.LastSeenMessageTime = Response.Messages.FirstOrDefault().Time;
            }

            CurrentUser = _CurrentUser;

            return Response;
        }
Пример #2
0
        public static void AddItem(SendMessageRequest NewMessage)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Messages.xml"));

            XmlNode Message = doc.CreateNode(XmlNodeType.Element, "message", null);
            XmlNode date = doc.CreateNode(XmlNodeType.Element, "date", null);
            date.InnerText = DateTime.Now.ToString();

            XmlNode text = doc.CreateNode(XmlNodeType.Element, "text", null);
            text.InnerText = NewMessage.Message;

            XmlNode ID = doc.CreateNode(XmlNodeType.Element, "ID", null);
            ID.InnerText = MessagesProvider.CurrentUser.UserID.ToString();

            Message.AppendChild(date);
            Message.AppendChild(text);
            Message.AppendChild(ID);

            doc.SelectSingleNode("//messages").AppendChild(Message);

            doc.Save(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Messages.xml"));
        }