Exemplo n.º 1
0
        public ActionResult Edit(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            else
            {
                Article newarticle = db.Articles.Find(id);

                Guid UserID = new Guid(User.Identity.Name);
                var Categories = db.Categories.Where(x => x.UserID == UserID).ToList();
                ViewBag.CategoryID = new SelectList(Categories, "CategoryID", "Name", newarticle.CategoryID);

                ArticleModel newarticleModel = new ArticleModel();
                newarticleModel.ArticleID = newarticle.ArticleID;
                newarticleModel.Title = newarticle.Title;
                newarticleModel.Article1 = newarticle.Article1;
                return View(newarticleModel);
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit(ArticleModel Article)
        {
            Article newarticle = db.Articles.Find(Article.ArticleID);

            newarticle.CategoryID = Article.CategoryID;
            newarticle.Title = Article.Title;
            newarticle.DateModified = DateTime.Now;
            newarticle.Article1 = Article.Article1;

            db.Entry(newarticle).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
Exemplo n.º 3
0
        public ActionResult ViewArticle(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            else
            {
                Article article = db.Articles.Find(id);
                ArticleModel newArticle = new ArticleModel();

                User user = new User();
                string name;
                user = db.Users.Find(article.UserID);
                name = user.Name + " " + user.Surname;

                newArticle.Article1 = article.Article1;
                newArticle.ArticleID = article.ArticleID;
                newArticle.Owner = name;
                newArticle.UserID = article.UserID;
                Category category = db.Categories.Find(article.CategoryID);
                newArticle.category = category.Name;
                newArticle.CategoryID = article.CategoryID;
                newArticle.DateModified = article.DateModified;
                newArticle.DatePosted = article.DatePosted;
                newArticle.Title = article.Title;
                return View(newArticle);
            }

        }
Exemplo n.º 4
0
        public ActionResult AddArticle(ArticleModel Article)
        {
            Guid UserID = new Guid(User.Identity.Name);
            var Categories = db.Categories.Where(x => x.UserID == UserID).ToList();

            if ((Article.Title == null) || (Article.Title.Trim() == ""))
            {
                ViewBag.error = "Add a title to your article.";
                ViewBag.CategoryID = new SelectList(Categories, "CategoryID", "Name", "");
                return View();
            }

            if (ModelState.IsValid)
            {
                Article newArticle = new Article();
                newArticle.ArticleID = Guid.NewGuid();
                newArticle.UserID = UserID;
                newArticle.CategoryID = Article.CategoryID;
                newArticle.Title = Article.Title;
                newArticle.Article1 = Article.Article1;
                newArticle.DatePosted = DateTime.Now;
                db.Articles.Add(newArticle);
                db.SaveChanges();

                return RedirectToAction("Index");
            }

            ViewBag.CategoryID = new SelectList(Categories, "CategoryID", "Name","");
            return View();
        }