public IHttpActionResult PutMessage(long id, Message message)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            if (id != message.Id)
            {
                return BadRequest();
            }
            try
            {
                _repository.Update(message);
            }
            catch
            {
                if (!MessageExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Ejemplo n.º 2
0
        public MessageDTO GetById(int id)
        {
            Entities.Models.Message message = messageRepository.GetMessageById(id);
            if (message == null)
            {
                return(null);
            }

            return(_mapper.Map <MessageDTO>(message));
        }
        public IHttpActionResult PostMessage(Message message)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            _repository.Add(message);

            return CreatedAtRoute("DefaultApi", new { id = message.Id }, message);
        }
 protected void SendNewMessage(object sender, EventArgs e)
 {
     if (!Page.IsValid) return;
     var conversation = _conversationRepository.Get(_conversationId);
     if(conversation==null)return;
     if (conversation.ReciverUserDeleted || conversation.SenderUserDeleted)
     {
         ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Javascript", "Javascript:RemovedConversation();",
             true);
         NewMessageEditor.Text = string.Empty;
         return;
     }
     var message = new Message
     {
         ContentText = NewMessageEditor.Text,
         Date = DateTime.Now,
         ConversationId = _conversationId,
         HasBeenSeen = false,
         SenderUserId = long.Parse(User.Identity.GetUserId())
     };
     _messageRepository.Add(message);
     Response.RedirectPermanent("/Profile/"+User.Identity.GetUserId());
 }