コード例 #1
0
 /// <summary>
 /// Adds the message to the db and returns it if it succeeds in adding it
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 public Message AddMessage(Message m)
 {
     using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities()))
     {
         query.AddMessage(m);
         Message addedMessage = query.GetMessageByUserAndDate(m.UserId, m.DateCreated);
         return (addedMessage != null) ? addedMessage : null;
     }
 }
コード例 #2
0
        public void UpdateMessage(Message m)
        {
            ctx.Entry(m).State = System.Data.Entity.EntityState.Modified;

            try
            {
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #3
0
        public void RemoveMessage(Message m)
        {
            ctx.Messages.Remove(m);

            try
            {
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #4
0
 public bool DeleteMessage(Message m)
 {
     using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities()))
     {
         Message messageToDelete = query.GetMessageById(m.Id);
         if (messageToDelete != null)
         {
             query.RemoveMessage(messageToDelete);
             return true;
         }
     }
     return false;
 }