public ActionResult UploadPhoto(HttpPostedFileBase[] images, string id)
        {
            if (!Authenticated())
            {
                return RedirectToAction("AdminLogin", "Auth");
            }

            var repo = new ShirtRepository();
            var shirt = repo.FindShirtById(id);

            var urls = repo.uploadImages(images, shirt.Title);

            var photoList = shirt.Photos.ToList();
            photoList.AddRange(urls);
            shirt.Photos = photoList.ToArray();

            repo.UpdateShirt(shirt);

            return new JsonResult() { Data = new { sources = urls } };
        }
        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");
        }
        public ActionResult SetDisplay(string id, string display)
        {
            if (!Authenticated())
            {
                return RedirectToAction("AdminLogin", "Auth");
            }

            var repo = new ShirtRepository();

            repo.UpdateShirt(id, "display", display);
            var shirt = repo.FindShirtById(id);

            shirt.Display = bool.Parse(display);

            Globals.Types[shirt.Type] =
                repo.firstDisplayedShirtOfType(shirt.Type) == null ?
                null : "http://res.cloudinary.com/throw-down-attire/image/upload/" + shirt.Type + ".png";

            return RedirectToAction("Admin", "Auth");
        }
        public ActionResult DeletePhoto(string src, string id)
        {
            if (!Authenticated())
            {
                return RedirectToAction("AdminLogin", "Auth");
            }

            var repo = new ShirtRepository();
            var shirt = repo.FindShirtById(id);

            var pub_id = src.Split('/').Last().Replace(".png", "");

            try
            {
                repo.deleteImage(pub_id);

                var shirtList = shirt.Photos.ToList();
                shirtList.Remove(src);
                shirt.Photos = shirtList.ToArray();
                repo.UpdateShirt(shirt);
                ViewBag.Success = "Successfully deleted image for: " + shirt.Title;
            }
            catch (Exception e)
            {
                ViewBag.Failure = "Image delete failed " + e.Message;
            }

            return View("Edit", shirt.Id.ToString());
        }