コード例 #1
0
        /// <summary>
        /// This method stores a order.
        /// </summary>
        /// <param name="o">The order object to store</param>
        /// <returns>Success/Failure</returns>
        public Boolean storeOrder(Order o)
        {
            dLog.Info("Entering method storeOrder | ID: " + o.id);
            Boolean result = false;

            try
            {
                MongoServer server = MongoServer.Create();
                MongoDatabase db = server.GetDatabase("neatoBurrito");
                //MongoCredentials credentials = new MongoCredentials("username", "password");
                //MongoDatabase salaries = server.GetDatabase("salaries", credentials);

                using (server.RequestStart(db))
                {
                    MongoCollection<BsonDocument> coll = db.GetCollection("order");
                    var query = new QueryDocument("id", o.id);

                    dLog.Debug("Finding if order exists");
                    BsonDocument myDoc = coll.FindOne(query);

                    query.Add("isComplete", o.isComplete);
                    query.Add("isSubmitted", o.isSubmitted);
                    query.Add("orderDate", o.orderDate);
                    query.Add("totalCost", o.totalCost.ToString());

                    //ensure we were passed a valid object before attempting to write
                    if (myDoc == null)
                    {
                        dLog.Debug("Inserting order");
                        coll.Insert(query);

                        result = true;
                    }
                    else
                    {
                        var update = new UpdateDocument();
                        update.Add(query.ToBsonDocument());
                        dLog.Debug("Updating order");
                        dLog.Debug("myDoc: " + myDoc.ToString());
                        dLog.Debug("update Query: " + update.ToString());

                        SafeModeResult wr = coll.Update(new QueryDocument("id", o.id), update, SafeMode.True);

                        dLog.Debug("SafeModeResult: " + wr.Ok);
                        if (wr.LastErrorMessage == null && wr.Ok)
                        {
                            result = true;
                        }
                        else
                        {
                            dLog.Debug("SafeModeResult: " + wr.LastErrorMessage);
                        }
                    }

                    //now insert the burritos
                    if (result)
                    {
                        dLog.Debug("Trying to insert " + o.burritos.Count + " burritos");

                        var index = 0;
                        foreach (Burrito b in o.burritos)
                        {
                            b.orderID = o.id;

                            dLog.Debug("Set order ID " + o.id + " for burrito: " + index);
                            if (b.validate())
                            {
                                dLog.Debug("Storing burrito: " + index);
                                result = burritoSvc.storeBurrito(b);
                            }
                            index++;
                        }
                    }
                }
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in storeBurrito: " + e2.Message);
            }
            finally
            {
                //using statement above already calls RequestDone()
            }

            return result;
        }
コード例 #2
0
        /// <summary>
        /// This method stores a burrito.
        /// </summary>
        /// <param name="b">The burrito object to store</param>
        /// <returns>Success/Failure</returns>
        public Boolean storeBurrito(Burrito b)
        {
            dLog.Info("Entering method storeBurrito | ID: " + b.id);
            Boolean result = false;

            try
            {
                MongoServer server = MongoServer.Create();
                MongoDatabase db = server.GetDatabase("neatoBurrito");
                //MongoCredentials credentials = new MongoCredentials("username", "password");
                //MongoDatabase salaries = server.GetDatabase("salaries", credentials);

                using (server.RequestStart(db))
                {
                    MongoCollection<BsonDocument> coll = db.GetCollection("burrito");
                    var query = new QueryDocument("id", b.id);

                    dLog.Debug("Finding if burrito exists");
                    BsonDocument myDoc = coll.FindOne(query);

                    query.Add("beef", b.Beef);
                    query.Add("blackBeans", b.BlackBeans);
                    query.Add("brownRice", b.BrownRice);
                    query.Add("chicken", b.Chicken);
                    query.Add("chiliTortilla", b.ChiliTortilla);
                    query.Add("cucumber", b.Cucumber);
                    query.Add("flourTortilla", b.FlourTortilla);
                    query.Add("guacamole", b.Guacamole);
                    query.Add("herbGarlicTortilla", b.HerbGarlicTortilla);
                    query.Add("hummus", b.Hummus);
                    query.Add("jalapenoCheddarTortilla", b.JalapenoCheddarTortilla);
                    query.Add("jalapenos", b.Jalapenos);
                    query.Add("lettuce", b.Lettuce);
                    query.Add("onion", b.Onion);
                    query.Add("orderID", b.orderID);
                    query.Add("pintoBeans", b.PintoBeans);
                    query.Add("price", b.Price.ToString());
                    query.Add("salsaPico", b.SalsaPico);
                    query.Add("salsaSpecial", b.SalsaSpecial);
                    query.Add("salsaVerde", b.SalsaVerde);
                    query.Add("tomatoBasilTortilla", b.TomatoBasilTortilla);
                    query.Add("tomatoes", b.Tomatoes);
                    query.Add("wheatTortilla", b.WheatTortilla);
                    query.Add("whiteRice", b.WhiteRice);

                    //ensure we were passed a valid object before attempting to write
                    if (myDoc == null)
                    {
                        dLog.Debug("Inserting burrito");
                        coll.Insert(query);

                        result = true;
                    }
                    else
                    {
                        var update = new UpdateDocument();
                        update.Add(query.ToBsonDocument());
                        dLog.Debug("Updating burrito");
                        dLog.Debug("myDoc: " + myDoc.ToString());
                        dLog.Debug("update Query: " + update.ToString());

                        SafeModeResult wr = coll.Update(new QueryDocument("id", b.id), update, SafeMode.True);

                        dLog.Debug("SafeModeResult: " + wr.Ok);
                        if (wr.LastErrorMessage == null && wr.Ok)
                        {
                            result = true;
                        }
                        else
                        {
                            dLog.Debug("SafeModeResult: " + wr.LastErrorMessage);
                        }
                    }
                }
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in storeBurrito: " + e2.Message);
            }
            finally
            {
                //using statement above already calls RequestDone()
            }

            return result;
        }
コード例 #3
0
        /// <summary>
        /// This method stores a user.
        /// </summary>
        /// <param name="u">The user object to store</param>
        /// <returns>Success/Failure</returns>
        public Boolean storeUser(User u)
        {
            dLog.Info("Entering method storeUser | ID: " + u.id);
            Boolean result = false;

            try
            {
                MongoServer server = MongoServer.Create();
                //MongoCredentials credentials = new MongoCredentials("username", "password");
                MongoDatabase db = server.GetDatabase("neatoBurrito");
                //MongoDatabase db = server.GetDatabase("neatoBurrito", credentials);

                using (server.RequestStart(db))
                {
                    MongoCollection<BsonDocument> coll = db.GetCollection("user");
                    var query = new QueryDocument("id", u.id);

                    dLog.Debug("Finding if user exists");
                    BsonDocument myDoc = coll.FindOne(query);

                    query.Add("username", u.userName);
                    query.Add("password", u.password);

                    //ensure we were passed a valid object before attempting to write
                    if (myDoc == null)
                    {
                        dLog.Debug("Inserting user");
                        coll.Insert(query);

                        result = true;
                    }
                    else
                    {
                        var update = new UpdateDocument();
                        update.Add(query.ToBsonDocument());
                        dLog.Debug("Updating user");
                        dLog.Debug("myDoc: " + myDoc.ToString());
                        dLog.Debug("update Query: " + update.ToString());

                        SafeModeResult wr = coll.Update(new QueryDocument("id", u.id), update, SafeMode.True);

                        dLog.Debug("SafeModeResult: " + wr.Ok);
                        if (wr.LastErrorMessage == null && wr.Ok)
                        {
                            result = true;
                        }
                        else
                        {
                            dLog.Debug("SafeModeResult: " + wr.LastErrorMessage);
                        }
                    }
                }
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in storeEUser: " + e2.Message);
            }
            finally
            {
                //using statement above already calls RequestDone()
            }

            return result;
        }