Example #1
0
 public ActionResult Create( int blogId, Article articleEdit )
 {
     articleEdit.Blogs = db.Blog.Where( p => p.ID == blogId ).ToArray();
     var um = new UserManager<Person>( new UserStore<Person>( db ) );
     var author = um.FindByName( User.Identity.Name );
     if( author == null )
         return View( "Error", "Can't find your account in persons" );
     articleEdit.Author = author;
     articleEdit.Date_of_Creation = DateTime.Now;
     articleEdit.Likes_Count = 0;
     articleEdit.Dislikes_Count = 0;
     var article = db.Article.Add( articleEdit );
     //Какой-то неопознанный баг, пришлось костылить, простите меня(
     ModelState["Author"].Errors.Clear();
     if( !ModelState.IsValid ) {
         ViewBag.BlodID = blogId;
         return View( article );
     }
     db.SaveChanges();
     if( article == null )
         return View( "Error" );
     return RedirectToAction( "blog", "Blogs", new { id = article.Blogs.First().ID } );
 }
Example #2
0
        public ActionResult Edit( int id, Article articleEdit )
        {
            Article article = db.Article.Where( p => id == p.ID ).FirstOrDefault();
            if( article != null ) {
                if( article.Author.UserName == User.Identity.Name || User.IsInRole( "admin" ) ) {
                    article.Text = articleEdit.Text;
                    article.Name = articleEdit.Name;
                    //Какой-то неопознанный баг, пришлось костылить, простите меня(
                    ModelState["Author"].Errors.Clear();
                    if( !ModelState.IsValid ) {
                        return View( article );
                    }

                    db.SaveChanges();
                    return RedirectToAction( "Index", "articles", article.ID );
                } else {
                    return HttpNotFound();
                }
            } else {
                return HttpNotFound();
            }
        }