Пример #1
0
        public ActionResult ChromeCreate(Collections_Snippet_CombinedModel collection)
        {
            snippetCollection CurrentSnippetCollection = db.collections.Find(Convert.ToInt32(collection.selectedCollectionID));

            if (CurrentSnippetCollection == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Snippet snippet = collection.snippet;

            snippet.SnippetCollection = CurrentSnippetCollection;
            snippet.SubmitterUserId   = User.Identity.GetUserId();
            CurrentSnippetCollection.snippets.Add(snippet);

            db.snippets.Add(snippet);
            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }

            db.SaveChanges();
            return(RedirectToAction("extensionConfirmation"));    // redirect to confirmation
        }
Пример #2
0
        // GET: Snippet_snippetCollection
        public ActionResult Index()
        {
            var model = new Collections_Snippet_CombinedModel
            {
                snippets   = db.snippets.ToList(),
                collection = db.collections.ToList()
            };

            return(View(db.snippet_collections.ToList()));
        }
Пример #3
0
        public ActionResult ChromeCreate(ExtensionInfo info)
        {
            /*info = (ExtensionInfo)TempData["modeltopass"]*/;
            string userID = User.Identity.GetUserId();
            List <SelectListItem>    collectionsForDropdown = new List <SelectListItem>();
            List <snippetCollection> collections            = new List <snippetCollection>();

            collections = db.collections.Where(x => x.SubmitterUserId == userID).ToList();
            foreach (var collection in collections)
            {
                collectionsForDropdown.Add(new SelectListItem()
                {
                    Text = collection.Title, Value = collection.ID.ToString()
                });
            }
            string UniqueFileName = string.Format(@"{0}.jpeg", Guid.NewGuid());
            string path1          = HttpContext.Server.MapPath("~/Images/");
            string path           = path1 + UniqueFileName;

            string[] dbpath = path.Split(new string[] { "Snippets\\Snippets" }, StringSplitOptions.None);
            try
            {
                LoadImage(TempData["imageData"].ToString(), path);
            }
            catch {  };

            Collections_Snippet_CombinedModel model = new Collections_Snippet_CombinedModel
            {
                collection         = db.collections.ToList(),
                collectionDropdown = collectionsForDropdown,
                snippet            = new Snippet()
                {
                    Link  = TempData["UrlData"].ToString(),
                    image = dbpath[1]
                            // save image locally with the name being the ID
                }
            };


            return(View(model));
        }
Пример #4
0
        // GET: Snippets/Create
        public ActionResult Create()
        {
            string userID = User.Identity.GetUserId();
            List <SelectListItem>    collectionsForDropdown = new List <SelectListItem>();
            List <snippetCollection> collections            = new List <snippetCollection>();

            collections = db.collections.Where(x => x.SubmitterUserId == userID).ToList();
            foreach (var collection in collections)
            {
                collectionsForDropdown.Add(new SelectListItem()
                {
                    Text = collection.Title, Value = collection.ID.ToString()
                });
            }

            Collections_Snippet_CombinedModel model = new Collections_Snippet_CombinedModel
            {
                collection         = db.collections.ToList(),
                collectionDropdown = collectionsForDropdown,
                snippet            = new Snippet()
            };

            return(View(model));
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "ID,Link,description")] Snippet snippet, Collections_Snippet_CombinedModel collection)
        {
            if (ModelState.IsValid)
            {
                snippetCollection CurrentSnippetCollection = db.collections.Find(Convert.ToInt32(collection.selectedCollectionID));
                if (CurrentSnippetCollection == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                snippet.SnippetCollection = CurrentSnippetCollection;
                snippet.SubmitterUserId   = User.Identity.GetUserId();
                CurrentSnippetCollection.snippets.Add(snippet);

                db.snippets.Add(snippet);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            if (!ModelState.IsValid)
            {
                var errors = ModelState.SelectMany(x => x.Value.Errors.Select(z => z.Exception));
            }

            return(RedirectToAction("Index"));
        }