public void sendMessage(int userId, MessageSendModel model, string keyDialog) { var db = new MyDBModels.DB(); var user = db.user.Where(u => u.UserId == userId).First(); var profileId = user.ProfileId; var currentCommunication = db.communication.Where(c => c.KeyDialog == keyDialog).First(); MyDBModels.Message messsage = new MyDBModels.Message(); messsage.DataMessage = model.DataMessage; messsage.TimeWritten = model.TimeWritten; messsage.IsReadProfileId = new int[] { profileId }; messsage.ProfileId = profileId; messsage.TypeMessage = 1; db.message.Add(messsage); db.SaveChanges(); var messageIdArray = currentCommunication.MessageIdArray.ToList(); messageIdArray.Add(db.message.Where(m => m.ProfileId == profileId && m.TimeWritten == model.TimeWritten).FirstOrDefault().MessageId);//OrderByDescending need? currentCommunication.MessageIdArray = messageIdArray.ToArray(); var dataAccess = new CommunicationDataAccess(); if (!currentCommunication.IsGroup) { var friendProfileId = currentCommunication.ParticipantProfileIdArray.Where(p => p != profileId).First(); dataAccess.searchAndConnectOldCommunication(profileId, friendProfileId); } db.SaveChanges(); }
private bool chaeckIsReadMessage(MyDBModels.Message message, int userId) { var db = new MyDBModels.DB(); var myProfileId = db.user.Where(u => u.UserId == userId).First().ProfileId; return(!(message.ProfileId == myProfileId && message.IsReadProfileId.Count() < 2)); }
private void changeIsReadMessage(MyDBModels.Message message, int profileId, int messageId) { var isReadProfileIdArray = message.IsReadProfileId.ToList(); isReadProfileIdArray.Add(profileId); message.IsReadProfileId = isReadProfileIdArray.ToArray(); }
private MessageModel createMessageModelFromDb(MyDBModels.Message message, int userId) { MessageModel model = new MessageModel(); var profileModel = getProfileModel(message.ProfileId); model.ProfileId = profileModel.ProfileId; model.FullName = String.Format("{0} {1}", profileModel.Name, profileModel.LastName); model.PhotoUrl = profileModel.PhotoUrl; model.DataMessage = message.DataMessage; model.isRead = chaeckIsReadMessage(message, userId); model.TypeMessage = message.TypeMessage; model.TimeWritten = message.TimeWritten; return(model); }
public int createSystemMessage(int userId, string dateMessage, int type) { var db = new MyDBModels.DB(); var user = db.user.Where(u => u.UserId == userId).First(); var profileId = user.ProfileId; var dateCreate = DateTime.Now; MyDBModels.Message messsage = new MyDBModels.Message(); messsage.DataMessage = dateMessage; messsage.TimeWritten = dateCreate; messsage.IsReadProfileId = new int[] { profileId }; messsage.ProfileId = profileId; messsage.TypeMessage = type; db.message.Add(messsage); db.SaveChanges(); return(db.message.Where(m => m.ProfileId == profileId && m.TimeWritten == messsage.TimeWritten).FirstOrDefault().MessageId); }