Пример #1
0
        private void Receiver()
        {
            IPEndPoint endPoint        = new IPEndPoint(IPAddress.Any, PORT);
            addMessage messageDelegate = MessageReceived;

            while (true)
            {
                byte[] data    = receivingClient.Receive(ref endPoint);
                string message = Encoding.ASCII.GetString(data);
                Invoke(messageDelegate, message);
            }
        }
Пример #2
0
        public HttpResponseMessage Add(int school_id, int user_id, [FromBody] addMessage message)
        {
            try
            {
                using (Entities entities = new Entities())
                {
                    MESSAGES _message = new MESSAGES()
                    {
                        MESSAGE_ID      = entities.MESSAGES.Max(n => n.MESSAGE_ID) + 1,
                        FROM_USER_ID    = user_id,
                        MESSAGE_SUBJECT = message.title,
                        MESSAGE_CONTENT = message.body,
                        MESSAGE_DATE    = DateTime.Now,
                        CREATION_DATE   = DateTime.Now,
                        MESSAGE_TYPE    = 1,
                        MESSAGE_STATUS  = 2,
                        SCHOOL_ID       = school_id
                    };
                    entities.MESSAGES.Add(_message);

                    foreach (var user in message.toUsers)
                    {
                        MESSAGE_RECIPIENTS _mr = new MESSAGE_RECIPIENTS()
                        {
                            MESSAGE_RECIPIENT_ID = entities.MESSAGE_RECIPIENTS.Max(mr => mr.MESSAGE_RECIPIENT_ID) + 1,
                            MESSAGE_ID           = _message.MESSAGE_ID,
                            USER_ID = user
                        };
                        entities.MESSAGE_RECIPIENTS.Add(_mr);
                        entities.SaveChanges();
                    }

                    MessageClass messageResult = new MessageClass(entities.MESSAGES.FirstOrDefault(n => n.MESSAGE_ID == _message.MESSAGE_ID));
                    return(Request.CreateResponse(HttpStatusCode.OK, new Result()
                    {
                        statusCode = 200, status = "Sending...", results = new List <MessageClass>()
                        {
                            messageResult
                        }
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new Result()
                {
                    statusCode = 400, status = ex.Message
                }));
            }
        }