Ejemplo n.º 1
0
        public static List <Item> GetItemInitData(MembersCollection memberCollection)
        {
            List <Item> items     = new List <Item>();
            Member      mia       = memberCollection.GetMemberByFirstName("Mia");
            Member      marsellus = memberCollection.GetMemberByFirstName("Marsellus");
            Member      jules     = memberCollection.GetMemberByFirstName("Jules");
            Member      vincent   = memberCollection.GetMemberByFirstName("Vincent");

            //Mia create a document that Mia, Marsellus, Jules and Vincent have acces to
            items.Add(new Item(mia, "My funny story", new List <Member>()
            {
                mia, marsellus, jules, vincent
            }));

            //Marsellus create a document that Marsellus, Jules and Vincent have acces to
            items.Add(new Item(marsellus, "Why I threw Tony Rocky our of a window", new List <Member>()
            {
                marsellus, jules, vincent
            }));

            return(items);
        }
Ejemplo n.º 2
0
        public AddMemberResponse Post(AddMemberRequest request)
        {
            var               response          = new AddMemberResponse();
            MongoClient       client            = new MongoClient("mongodb://localhost:27017");
            MongoDatabaseBase db                = client.GetDatabase("ntut") as MongoDatabaseBase;
            var               merberscontroller = db.GetCollection <MembersCollection>("members");
            var               uids              = request.members.Select(e => e.uid).ToList();
            var               query             = Builders <MembersCollection> .Filter.In(e => e.Uid, uids);

            var doc = merberscontroller.Find(query).ToList();

            #region 移除存在在資料庫的會員
            if (doc.Count > 0)
            {
                var existUIDList = doc.Select(e => e.Uid).ToList();
                request.members.RemoveAll(e => existUIDList.Contains(e.uid));
                response.ok = false;
                var existUid = string.Join(",", existUIDList);
                response.errMsg = "編號為" + existUid + "的會員存在,請重新輸入別組會員編號。";
                if (request.members.Count() > 0)
                {
                    var memebers = new List <MembersCollection>();
                    for (var i = 1; i < 100000; i++)
                    {
                        var memDoc = new MembersCollection()
                        {
                            _id = new ObjectId(),
                            Uid = i.ToString()
                        };
                        memebers.Add(memDoc);
                    }
                    merberscontroller.InsertMany(memebers);

                    var membersDocs = request.members.Select(e =>
                    {
                        return(new MembersCollection()
                        {
                            _id = new ObjectId(),
                            Uid = e.uid,
                            Phone = e.phone,
                            Name = e.name
                        });
                    }).ToList();
                    merberscontroller.InsertMany(membersDocs);
                }
            }
            #endregion
            else
            {
                var membersDocs = request.members.Select(e =>
                {
                    return(new MembersCollection()
                    {
                        _id = new ObjectId(),
                        Uid = e.uid,
                        Phone = e.phone,
                        Name = e.name
                    });
                }).ToList();
                merberscontroller.InsertMany(membersDocs);
            }

            return(response);
        }
Ejemplo n.º 3
0
 public Group()
 {
     members         = new MembersCollection();
     GroupProperties = new ArrayList();
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string connectionString = "mongodb://localhost:27017";

            MongoDB.Driver.MongoClient client  = new MongoClient(connectionString);
            IMongoDatabase             mongoDb = client.GetDatabase("SampleDb1");

            //PART 1: Testing Crimes and MapReduce ...
            bool             initCrimesDb     = false; //set to true for the first run
            CrimesCollection crimesCollection = new CrimesCollection(mongoDb);

            if (initCrimesDb)
            {
                crimesCollection.InsertCrimeData(GetCrimesInitData());
            }
            List <BsonDocument> results = crimesCollection.MapReduceCrimesByDay();

            PrintMapReduceResults(results);

            //PART 2: Testing cross referenced docs (see Items) ...
            // 2-A members ...
            bool initMembers = false; //set to true for first run
            MembersCollection memberCollection = new MembersCollection(mongoDb);

            if (initMembers)
            {
                memberCollection.InsertMembers(GetMemberInitData());
            }

            List <Member> members = memberCollection.GetMembers();

            PrintMembers(members);

            Member mia = memberCollection.GetMemberByFirstName("Mia");

            PrintMembers(new List <Member>()
            {
                mia
            });

            //PART 2-B: Items ....
            bool           initItems      = false;
            ItemCollection itemCollection = new ItemCollection(mongoDb);

            if (initItems)
            {
                itemCollection.InsertItems(GetItemInitData(memberCollection));
            }

            mia = memberCollection.GetMemberByFirstName("Mia");
            Member      marsellus = memberCollection.GetMemberByFirstName("Marsellus");
            List <Item> items     = null;

            //Lets get the items that Marsellus can see. Should return 1
            items = itemCollection.GetItemsforMember(mia._id);
            PrintItemCollection(items, members);

            //Lets get items that Marsellus can see. Should return 2
            items = itemCollection.GetItemsforMember(marsellus._id);
            PrintItemCollection(items, members);

            Console.WriteLine("MongoDB test ... Done!");
        }
Ejemplo n.º 5
0
 public ActionResult Index()
 {
     var members = DB.Fetch<Member>("select * from Member");
       var collection = new MembersCollection(members);
       return View(collection);
 }