Example #1
0
        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();
        }
Example #2
0
        private void deleteFriendFromDb(MyDBModels.DB db, MyDBModels.User fromDeleteUserModel, int deleteProfileId)
        {
            var friendArrayIdUpdate = fromDeleteUserModel.FriendIdArray.ToList();

            friendArrayIdUpdate.Remove(deleteProfileId);
            fromDeleteUserModel.FriendIdArray = friendArrayIdUpdate.ToArray();

            var dataAccess      = new CommunicationDataAccess();
            int communicationId = dataAccess.searchCommunication(fromDeleteUserModel.ProfileId, deleteProfileId);

            var communicationIdArray = fromDeleteUserModel.CommunicationIdArray;
            var communicationIdList  = communicationIdArray.ToList();

            communicationIdList.Remove(communicationId);
            fromDeleteUserModel.CommunicationIdArray = communicationIdList.ToArray();

            if (fromDeleteUserModel.CommunicationPinIdArray.Contains(communicationId))
            {
                var communicationPinIdArray = fromDeleteUserModel.CommunicationPinIdArray;
                var communicationPinIdList  = communicationPinIdArray.ToList();
                communicationPinIdList.Remove(communicationId);
                fromDeleteUserModel.CommunicationPinIdArray = communicationPinIdList.ToArray();
            }

            db.SaveChanges();
        }
        private PreviewProfileModel formatProfileData(int userId, ProfileStatisticsModel profileStatisticsModel)
        {
            var db = new MyDBModels.DB();
            var countUnreadMessages = 0;
            var countGroups         = 0;
            var dateUtils           = new DateUtils();

            var userModel    = db.user.Where(u => u.UserId == userId).First();
            var profileModel = db.profile.Where(p => p.ProfileId == userModel.ProfileId).First();

            var communicationIdArray    = userModel.CommunicationIdArray;
            var communicationDataAccess = new CommunicationDataAccess();

            communicationIdArray.ToList().ForEach(delegate(int communicationId)
            {
                var communicationModelDb = db.communication.Where(c => c.CommunicationId == communicationId).First();
                if (IsUnreadCommunication(communicationModelDb.MessageIdArray, profileModel.ProfileId))
                {
                    countUnreadMessages++;
                }
            });

            PreviewProfileModel previewProfileModel = new PreviewProfileModel();

            previewProfileModel.FullName              = String.Format("{0} {1}", profileModel.Name, profileModel.LastName);
            previewProfileModel.PhotoUrl              = profileModel.PhotoUrl;
            previewProfileModel.TimeLastActive        = profileModel.TimeLastActive;//dateUtils.calculateStateLastActivity(profileModel.TimeLastActive);
            previewProfileModel.CountRequestedFriends = userModel.FriendPossibleIdArray.Count();;
            previewProfileModel.CountUnreadMessages   = countUnreadMessages;
            previewProfileModel.CountRequestedGroups  = countGroups;
            previewProfileModel.ProfileStatistics     = profileStatisticsModel;

            return(previewProfileModel);
        }
Example #4
0
        public void confirmFriend(int userId, int confirmProfileId, bool addFriend)
        {
            var db              = new MyDBModels.DB();
            var myUserModel     = db.user.Where(u => u.UserId == userId).First();
            var myProfileModel  = db.profile.Where(p => p.ProfileId == myUserModel.ProfileId).First();
            var friendUserModel = db.user.Where(u => u.ProfileId == confirmProfileId).First();

            var possibleProfileIdArray = myUserModel.FriendPossibleIdArray;

            if (addFriend)
            {
                var friendArrayIdUpdate = myUserModel.FriendIdArray.ToList();
                friendArrayIdUpdate.Add(confirmProfileId);
                myUserModel.FriendIdArray = friendArrayIdUpdate.ToArray();

                var myFirendFriendArrayIdUpdate = friendUserModel.FriendIdArray.ToList();
                myFirendFriendArrayIdUpdate.Add(myUserModel.ProfileId);
                friendUserModel.FriendIdArray = myFirendFriendArrayIdUpdate.ToArray();

                if (friendUserModel.FriendPossibleIdArray.Contains(myUserModel.ProfileId))
                {
                    var firendPossibleArrayIdUpdate = friendUserModel.FriendPossibleIdArray.ToList();
                    firendPossibleArrayIdUpdate.Remove(myUserModel.ProfileId);
                    myUserModel.FriendPossibleIdArray = firendPossibleArrayIdUpdate.ToArray();
                }

                CommunicationDataAccess dataAccess = new CommunicationDataAccess();

                if (!dataAccess.searchAndConnectOldCommunication(myProfileModel.ProfileId, friendUserModel.ProfileId))
                {
                    CommunicationShortModel shortModel = new CommunicationShortModel();
                    var firendProfile = db.profile.Where(fp => fp.ProfileId == friendUserModel.ProfileId).First();

                    shortModel.Name     = String.Format("{0} {1} - {2} {3}", firendProfile.Name, firendProfile.LastName, myProfileModel.Name, myProfileModel.LastName);
                    shortModel.PhotoUrl = firendProfile.PhotoUrl;
                    shortModel.ParticipantProfileIdArray = new int[] { firendProfile.ProfileId, myUserModel.ProfileId };

                    dataAccess.createCommunication(userId, shortModel);

                    db.SaveChanges();
                }
            }

            var possibleArrayIdUpdate = possibleProfileIdArray.ToList();

            possibleArrayIdUpdate.Remove(confirmProfileId);
            myUserModel.FriendPossibleIdArray = possibleArrayIdUpdate.ToArray();

            db.SaveChanges();
        }