Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Puttbl_Messages(int id, tbl_UserMessages tbl_Messages)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tbl_Messages.col_userMessagesID)
            {
                return(BadRequest());
            }

            db.Entry(tbl_Messages).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tbl_MessagesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> Gettbl_Messages(int id)
        {
            tbl_UserMessages tbl_Messages = await db.tbl_UserMessages.FindAsync(id);

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

            return(Ok(tbl_Messages));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Posttbl_Messages(MessageModel model)
        {
            LogApi.Log(User.Identity.GetUserId(), "PostMessage " + User.Identity.GetUserName() + " " + model.Message);

            try
            {
                var userId = User.Identity.GetUserId();
                //if (!ModelState.IsValid)
                //{
                //    return BadRequest(ModelState);
                //}
                tbl_UserMessages tbl_Messages = new tbl_UserMessages();
                tbl_Messages.col_DateTime        = DateTime.Now;
                tbl_Messages.col_Message         = model.Message;
                tbl_Messages.col_ToUserID        = model.userID;
                tbl_Messages.col_FromUserID      = userId;
                tbl_Messages.col_ParentMessageID = model.parentMessageID;
                db.tbl_UserMessages.Add(tbl_Messages);
                await db.SaveChangesAsync();

                try
                {
                    var    token = db.tbl_DeviceIds.Where(d => d.col_UserID == model.userID).FirstOrDefault().col_DeviceToken;
                    string from  = User.Identity.GetUserName();
                    Notifications.NotifyAsync(token, "Message from:" + from, model.Message);
                }
                catch (Exception ex)
                {
                }
                return(Ok("Posted"));
            }
            catch (Exception ex)
            {
                var     userId = User.Identity.GetUserId();
                tbl_Log log    = new tbl_Log();
                var     user   = db.AspNetUsers.Where(u => u.Id == userId).FirstOrDefault();
                log.col_UserID   = userId;
                log.col_DateTime = DateTime.Now;
                log.col_Feature  = ex.Message;
                db.tbl_Log.Add(log);
                db.SaveChanges();

                return(Ok("Error " + ex.Message));
            }
            //return CreatedAtRoute("DefaultApi", new { id = tbl_Messages.col_MessageID }, tbl_Messages);
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> Deletetbl_Messages(int id)
        {
            LogApi.Log(User.Identity.GetUserId(), "DeleteMessage " + User.Identity.GetUserName());

            try
            {
                tbl_UserMessages tbl_Messages = await db.tbl_UserMessages.FindAsync(id);

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

                db.tbl_UserMessages.Remove(tbl_Messages);
                await db.SaveChangesAsync();

                return(Ok("Deleted"));
            }
            catch (Exception ex)
            {
                return(Ok("Error " + ex.Message));
            }
        }