public void NewGroupChatMessage(GroupChatMessage msg, GroupChat chat) { if (msg.MessageId == 0) { msg.DateAdded = DateTime.Now; context.Attach(chat); msg.CreatedAt = DateTime.Now; msg.UpdatedAt = DateTime.Now; context.GroupChatMessages.Add(msg); context.SaveChanges(); } }
public void EditGroupChat(GroupChat chat) { //if not exists create new if (chat.ChatId == 0) { context.GroupChats.Add(chat); chat.CreatedAt = DateTime.Now; chat.UpdatedAt = DateTime.Now; context.SaveChanges(); } else { GroupChat dbEntry = context.GroupChats .FirstOrDefault(c => c.ChatId == chat.ChatId); dbEntry.UpdatedAt = DateTime.Now; dbEntry.ChatPhotoPath = chat.ChatPhotoPath; dbEntry.Title = chat.Title; context.SaveChanges(); } }