/// <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; } }
public void UpdateMessage(Message m) { ctx.Entry(m).State = System.Data.Entity.EntityState.Modified; try { ctx.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void RemoveMessage(Message m) { ctx.Messages.Remove(m); try { ctx.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
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; }