Example #1
0
 public MessageViewModel(Message message)
 {
     Id = message.Id;
     ParentId = message.ParentId;
     Text = message.Text;
     CreatedAt = message.CreatedAt;
     User = new UserViewModelSimple(message.User); //converts my userId to the UserViewModel
     Family = new FamilyViewModelSimple(message.Family);
     Comments = message.getComments(message.Id).Select(c => new MessageViewModel(c));
 }
 public MessageViewModel Post(Message message, string id = null, string parentId = null)
 {
     Message toUpdate = null;
     if (id != null) {
         toUpdate = db.Messages.Find(id);
         toUpdate.Text = message.Text;
         toUpdate.CreatedAt = message.CreatedAt;
         toUpdate.FamilyId = message.FamilyId;
         toUpdate.UserId = message.UserId;
         toUpdate.ParentId = message.ParentId;
     } else db.Messages.Add(message);
     db.SaveChanges();
     return new MessageViewModel(toUpdate ?? message);
 }