Beispiel #1
0
        public void AddToChart(string id)
        {
            MongodbFunctions mongo = new MongodbFunctions();

            Database.DomainModel.User  user  = mongo.GetUser(User.Identity.Name);
            Database.DomainModel.Order order = mongo.GetOpenOrder(user.Id);

            if (order == null)
            {
                List <MongoDBRef> products = new List <MongoDBRef>();
                products.Add(new MongoDBRef("products", new ObjectId(id)));

                order = new Database.DomainModel.Order
                {
                    Date     = DateTime.Now,
                    Status   = "opened",
                    Products = products
                };

                mongo.AddUpdateOrder(order, user.Email, "add");
            }
            else
            {
                order.Products.Add(new MongoDBRef("products", new ObjectId(id)));
                mongo.AddUpdateOrder(order, user.Email, "update");
            }
        }