Exemplo n.º 1
0
        private async Task initializeData()
        {

            var repo = new ShirtRepository();
            var docs = await repo.collection.Find(new BsonDocument()).ToListAsync();

            foreach(var doc in docs)
            {
                var shirt = repo.createShirtFromBson(doc);
                if (!Globals.Types.Keys.Contains(shirt.Type) || (Globals.Types[shirt.Type] == null && shirt.Display == true))
                {
                    var url = shirt.Display ? 
                        "http://res.cloudinary.com/throw-down-attire/image/upload/" + shirt.Type + ".png" : null;
                    Globals.Types.Add(shirt.Type, url);
                }

                Globals.Shirts.Add(shirt);
            }

            Globals.Shirts.Sort((x, y) => x.Title.CompareTo(y.Title));
            Globals.Types = Globals.Types.OrderBy(x => x.Key.Length).ToDictionary(x => x.Key, x => x.Value);

            var faqDocs = await repo.FAQCollection.Find(new BsonDocument()).ToListAsync();

            foreach (var doc in faqDocs)
            {
                repo.createFAQFromBson(doc);
            }
        }
        public ActionResult Edit(ShirtEditViewModel model)
        {
            if (!Authenticated())
            {
                return RedirectToAction("AdminLogin", "Auth");
            }

            var repo = new ShirtRepository();
            var shirtDoc = repo.UpdateShirt(model);
            var shirt = repo.createShirtFromBson(shirtDoc);
            var oldShirt = repo.FindShirtById(shirt.Id.ToString());

            var i = Globals.Shirts.FindIndex(x => x.Id == shirt.Id);
            Globals.Shirts[i] = shirt;

            if (repo.firstShirtOfType(oldShirt.Type) == null)
            {
                Globals.Types.Remove(oldShirt.Type);
                repo.deleteImage(oldShirt.Type);
            }

            return RedirectToAction("Admin", "Auth");
        }