Esempio n. 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);
        }
Esempio n. 2
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);
        }