コード例 #1
0
        public IHttpActionResult PutTenMsg(int id, TenMsg tenMsg)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tenMsg.MsgIndex)
            {
                return(BadRequest());
            }



            try
            {
                m_db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TenMsgExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public IHttpActionResult GetTenMsg(int id)
        {
            TenMsg tenMsg = m_db.TenMsgs.Find(id);

            if (tenMsg == null)
            {
                return(NotFound());
            }

            return(Ok(tenMsg));
        }
コード例 #3
0
        public IHttpActionResult DeleteTenMsg(int id)
        {
            TenMsg tenMsg = m_db.TenMsgs.Find(id);

            if (tenMsg == null)
            {
                return(NotFound());
            }

            m_db.TenMsgs.Remove(tenMsg);
            m_db.SaveChanges();

            return(Ok(tenMsg));
        }
コード例 #4
0
        public override async Task <object> ReadFromStreamAsync(Type type, Stream stream,
                                                                HttpContent httpContent,
                                                                IFormatterLogger iFormatterLogger)
        {
            MultipartStreamProvider parts = await httpContent.ReadAsMultipartAsync();

            IEnumerable <HttpContent> contents = parts.Contents;

            HttpContent content = contents.FirstOrDefault();

            foreach (HttpContent c in contents)
            {
                if (SupportedMediaTypes.Contains(c.Headers.ContentType))
                {
                    content = c;
                    break;
                }
            }

            using (var msgStream = await content.ReadAsStreamAsync())
            {
                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(TenMsg));
                TenMsg msg = (TenMsg)js.ReadObject(msgStream);
                Debug.WriteLine("msgString: " + msgStream.ToString());

                int      sender     = msg.Sender;
                int      receiver   = msg.Receiver;
                byte     phoneType  = msg.PhoneType;
                bool     isLocked   = msg.IsLocked;
                DateTime msgTime    = msg.MsgTime;
                string   msgContent = msg.MsgContent;
                Debug.WriteLine("Msg Content: " + msg.MsgContent);

                return(new TenMsg(sender, receiver, phoneType, isLocked, msgTime, msgContent));
            }
        }
コード例 #5
0
        public IHttpActionResult PostTenMsg(TenMsg tenMsg)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            m_db.TenMsgs.Add(tenMsg);
            m_db.SaveChanges();

            if (tenMsg.PhoneType == 0) // iPhone
            {
                TenLogin targetLogin = m_loginDb.TenLogins.Where(tl => tl.UserIndex == tenMsg.Receiver).FirstOrDefault();

                Debug.WriteLine("Target Login: "******"Device Token: " + ByteArrayToString(targetLogin.DeviceToken));

                m_pushBroker.QueueNotification(new AppleNotification()
                                               .ForDeviceToken(ByteArrayToString(targetLogin.DeviceToken))
                                               .WithAlert(tenMsg.MsgContent)
                                               .WithBadge(7)
                                               .WithSound("sound.caf"));

                /*
                 * m_pushBroker.QueueNotification(new AppleNotification()
                 *                         .ForDeviceToken("d0d0a5a868b2b70f5f6900a6cbe034facf38050b4402d14b61a68ae6c27b0b92")
                 *                         .WithAlert("Hi from TDS!")
                 *                         .WithBadge(7)
                 *                         .WithSound("sound.caf"));*/
            }
            else if (tenMsg.PhoneType == 1) // Android
            {
            }

            return(CreatedAtRoute("DefaultApi", new { id = tenMsg.MsgIndex }, tenMsg));
        }