예제 #1
0
 private bool MessageExists(Wall wall, string id)
 {
     if (wall != null && wall.messages != null)
     {
         foreach (Message mess in wall.messages)
         {
             if (mess.id.Equals(id))
             {
                 return true;
             }
         }
     }
     return false;
 }
예제 #2
0
        public Wall MergeAndReturnWallChanges(User user, string returnWallName)
        {
            Wall returnWall = new Wall();
            returnWall.messages = new List<Message>();

            if (user.date != null)
            {
                userModel.date = user.date;
            }

            if (user.walls != null)
            {
                if (userModel.walls == null)
                {
                    userModel.walls = new List<Wall>();
                }

                foreach (Wall wall in user.walls)
                {
                    Wall foundWall = WallExists(wall.name);
                    if (foundWall != null)
                    {
                        if (foundWall.messages == null)
                        {
                            foundWall.messages = new List<Message>();
                        }

                        bool addMessage = false;
                        if(wall.name.Equals(returnWallName))
                        {
                            addMessage = true;
                        }

                        if (wall.messages == null)
                        {
                            foundWall.messages = new List<Message>();
                            continue;
                        }

                        foreach (Message mess in wall.messages)
                        {
                            if (!MessageExists(foundWall, mess.id))
                            {
                                foundWall.messages.Add(mess);
                                if (addMessage)
                                {
                                    returnWall.messages.Add(mess);
                                }
                            }
                        }
                    }
                    else
                    {
                        userModel.walls.Add(wall);
                    }
                }
            }

            return returnWall;
        }