Пример #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
        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"));
        }
Пример #3
0
 public ActionResult Edit([Bind(Include = "ID,Title,SubmitterUserId")] snippetCollection snippetCollection)
 {
     if (ModelState.IsValid)
     {
         db.Entry(snippetCollection).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(snippetCollection));
 }
Пример #4
0
        public ActionResult Create([Bind(Include = "ID,Title")] snippetCollection snippetCollection)
        {
            if (ModelState.IsValid)
            {
                snippetCollection.SubmitterUserId = User.Identity.GetUserId();
                db.collections.Add(snippetCollection);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(snippetCollection));
        }
Пример #5
0
        // GET: snippetCollections/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            snippetCollection snippetCollection = db.collections.Find(id);

            if (snippetCollection == null)
            {
                return(HttpNotFound());
            }
            return(View(snippetCollection));
        }
Пример #6
0
        public ActionResult ManageCollection(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            snippetCollection snippet = db.collections.Find(id);
            List <Snippet>    snippetsInCollection = snippet.snippets;

            if (snippet == null)
            {
                return(HttpNotFound());
            }
            return(View(snippet));
        }
Пример #7
0
        public ActionResult MakePublic(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            snippetCollection collection = db.collections.Find(id);

            if (collection == null)
            {
                return(HttpNotFound());
            }
            collection.IsPublic = true;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #8
0
        public ActionResult addSnippetToCollection(int?id)
        {
            //make new model and put snippet collection and snippet in there


            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            snippetCollection SnippetCollection = db.collections.Find(id);

            if (SnippetCollection == null)
            {
                return(HttpNotFound());
            }
            return(View(SnippetCollection));
        }
Пример #9
0
        public ActionResult SaveCollection(string id)  // might be ID
        {
            if (ModelState.IsValid)
            {
                snippetCollection collection = db.collections.Find(Convert.ToInt32(id));
                // add +1 to collection save count
                collection.SaveCount += 1;
                snippetCollection newSnippet = new snippetCollection();
                newSnippet.snippets        = creatSnippetListCopy(collection.snippets.ToList());
                newSnippet.Title           = collection.Title;
                newSnippet.SubmitterUserId = User.Identity.GetUserId();
                db.collections.Add(newSnippet);
                db.SaveChanges();
            }


            return(RedirectToAction("Index"));
        }
Пример #10
0
        public ActionResult DeleteConfirmed(int id)
        {
            //check and see if the list is not null
            // if not null, find all the snippets in the db that are the exact match, and remove them from the DB


            snippetCollection snippetCollection = db.collections.Find(id);

            if (snippetCollection.snippets.Count < 1)
            {
                foreach (Snippet snippet in snippetCollection.snippets)
                {
                    Snippet FoundSnippet = db.snippets.Find(snippet.ID);
                    db.snippets.Remove(FoundSnippet);
                }
            }

            db.collections.Remove(snippetCollection);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }