Пример #1
0
        //public SMSController()
        //{
        //}
        //public SMSController(ISMSService smsService)
        //{
        //    //_smsService = smsService;
        //}
        public HttpResponseMessage Post(SMSRequest request)
        {
            var smsevents = new SMSEvents();

            switch (request.action)
            {
                case "test":
                    break;
                case "outgoing":
                    {
                        var msgs = SMSService.FindBy(s => s.Status == 1);
                        var messages = new List<SmsOutgoingMessage>();

                        if (msgs.Count>0)
                        {
                            foreach (var msg in msgs)
                            {
                                var m = new SmsOutgoingMessage()
                                    {
                                        id = msg.SMSID.ToString(),
                                        message = "\"" + msg.Text + "\"",
                                        to = msg.MobileNumber,
                                        priority = null,
                                        type = null
                                    };

                                messages.Add(m);
                            }
                        }

                        // messages.Add(messageTwo);
                        var sendevents = new List<SmsEventSend>();

                        var ev = new SmsEventSend()
                            {
                                @event = "send",
                                messages = messages
                            };
                        sendevents.Add(ev);
                        smsevents.events = sendevents;

                        return Request.CreateResponse(HttpStatusCode.OK, smsevents);
                    }
                case "send_status":
                    {
                        if (request.status == "sent")
                        {
                            var id = Convert.ToInt32(request.id);
                            var msg = SMSService.FindById(id);
                            msg.Status = 2;
                            SMSService.EditSMS(msg);
                        }
                        break;
                    }
            }

            return Request.CreateResponse(HttpStatusCode.OK, smsevents);
        }
Пример #2
0
        //public SMSController()
        //{
        //}
        //public SMSController(ISMSService smsService)
        //{
        //    //_smsService = smsService;
        //}
        public HttpResponseMessage Post(SMSRequest request)
        {
            var smsevents = new SMSEvents();

            if (request.action == "test")
            {

            }

            else if (request.action == "outgoing")
            {
                var msgs = SMSService.FindBy(s => s.Status == 1);
                var messages = new List<SmsOutgoingMessage>();

                if (msgs.Count>0)
                {
                    foreach (var msg in msgs)
                    {
                        var m = new SmsOutgoingMessage()
                        {
                            id = msg.SMSID.ToString(),
                            message = "\"" + msg.Text + "\"",
                            to = msg.MobileNumber,
                            priority = null,
                            type = null
                        };

                       messages.Add(m);
                    }
                }

                var messageTwo = new SmsOutgoingMessage()
                {
                    id = "9c7c9cya5711b",
                    message = "\"Hello Fish! You are selected to be man of the day again! CATS\"",
                    to = "0911306248",
                    priority = null,
                    type = null
                };

               // messages.Add(messageTwo);
                var sendevents = new List<SmsEventSend>();

                var ev = new SmsEventSend()
                {
                    @event = "send",
                    messages = messages
                };
                sendevents.Add(ev);
                smsevents.events = sendevents;

                return Request.CreateResponse(HttpStatusCode.OK, smsevents);
            }

            return Request.CreateResponse(HttpStatusCode.OK, smsevents);
        }
Пример #3
0
        public HttpResponseMessage Post(SMSRequest request)
        {
            var smsevents = new SMSEvents();

            //var headerparam = request.GetQueryNameValuePairs();

            //if(request.Content.Headers.Contains("action"))
            //{
            //    return null;
            //}

            //var action = headerparam.SingleOrDefault(t => t.Key == "action");

            if (request.action == "test")
            {

            }

            else if (request.action == "outgoing")
            {
                var msgs = _smsService.FindBy(s => s.Status == 1);
                var messages = new List<SmsOutgoingMessage>();

                //var outmsgs = new List<out>
                foreach (var msg in msgs)
                {
                    var m = new SmsOutgoingMessage()
                        {
                            id = msg.SMSID.ToString(),
                            message = msg.Text,
                            to = msg.MobileNumber,
                            priority = null,
                            type = null
                        };
                    messages.Add(m);
                }

                var sendevents = new List<SmsEventSend>();

                //var messageOne = new SmsOutgoingMessage()
                //{
                //    id = "9y7c9cya5711b",
                //    message = "\"Hello Yareda! You are selected to be man of the day! CATS\"",
                //    to = "0911663223",
                //    priority = null,
                //    type = null
                //};

                //var messageTwo = new SmsOutgoingMessage()
                //{
                //    id = "9c7c9cya5711b",
                //    message = "\"Hello Fish! You are selected to be man of the day again! CATS\"",
                //    to = "0911306248",
                //    priority = null,
                //    type = null
                //};

                //messages.Add(messageOne);
                //messages.Add(messageTwo);

                var ev = new SmsEventSend()
                {
                    @event = "send",
                    messages = messages
                };
                sendevents.Add(ev);
                smsevents.events = sendevents;

                return Request.CreateResponse(HttpStatusCode.OK, smsevents);
            }
            return Request.CreateResponse(HttpStatusCode.OK, smsevents);
        }