protected void AddNewMessage(object sender, EventArgs e)
        {
            var currentUser = Membership.GetUser();

            if (string.IsNullOrWhiteSpace(txtMessage.Text) || string.IsNullOrWhiteSpace(guidIncidence.Value)
                || currentUser == null || currentUser.ProviderUserKey == null) return;

            try
            {
                var newMessage = new Message
                {
                    Id = Guid.NewGuid(),
                    CreatedDate = DateTime.Now,
                    Text = txtMessage.Text,
                    IncidenceId = new Guid(guidIncidence.Value),
                    UserId = new Guid(currentUser.ProviderUserKey.ToString()),
                    UserName = currentUser.UserName
                };

                _messageService.Add(newMessage);
                LoadMessageList();
            }

            catch (Exception ex)
            {
                lblResult.Text = ex.Message;
                lblResult.Visible = true;
            }
        }
Example #2
0
 /// <summary>
 /// Método para añadir un mensaje
 /// </summary>
 /// <param name="message">entidad</param>
 /// <returns>Deveuelve el mensage añadido</returns>
 public Message Add(Message message)
 {
     try
     {
         var newMessage = _dbContext.Messages.Add(message);
         _dbContext.SaveChanges();
         return newMessage;
     }
     catch (Exception ex)
     {
         throw new Exception("Error al añadir el Mensaje: " + ex.InnerException.Message);
     }
 }