Пример #1
0
        // GET: BlogPost/Create
        public IActionResult Create()
        {
            var model = new BlogPostCreateViewModel();

            model.BackgroundImage = "";
            model.HeaderTitle     = "Create Post";
            model.PageTitle       = "Create Post";

            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Create(BlogPostCreateViewModel input)
        {
            if (ModelState.IsValid)
            {
                var post = await this.manager.CreateBlogPost(input);

                return(RedirectToAction(nameof(this.Edit), new { id = post.Id }));
            }

            return(View(input));
        }
Пример #3
0
        public async Task <IActionResult> Create()
        {
            var user = await base.GetCurrentUserAsync();

            var vm = new BlogPostCreateViewModel();

            if (user != null)
            {
                vm.CreatorId = user.Id;
            }

            return(View(vm));
        }
Пример #4
0
 public ActionResult Create([Bind(Include = "title,content,tags")] BlogPostCreateViewModel blogPost)
 {
     if (ModelState.IsValid)
     {
         Person thisPerson = (from user in db.Persons
                              where user.Email == User.Identity.Name
                              select user).FirstOrDefault();
         BlogPost newPost = new BlogPost();
         newPost.dateCreated = DateTime.Now;
         newPost.PersonId    = thisPerson.Id;
         newPost.tags        = new Collection <Tag>();
         var allTags = db.Tags.ToList();
         foreach (var s in blogPost.tags.Split(','))
         {
             string trimmed = s.Trim();
             Tag    thisTag = allTags.Find(tag => tag.tagName.Equals(trimmed));
             if (thisTag == null)
             {
                 thisTag         = new Tag();
                 thisTag.tagName = trimmed;
                 db.Tags.Add(thisTag);
             }
             newPost.tags.Add(thisTag);
         }
         newPost.title   = blogPost.title;
         newPost.content = blogPost.content;
         if (thisPerson.posts == null)
         {
             thisPerson.posts = new Collection <BlogPost>();
         }
         thisPerson.posts.Add(newPost);
         db.BlogPosts.Add(newPost);
         db.SaveChanges();
         return(RedirectToAction("Details", "Blog", new { id = newPost.Id }));
     }
     return(View(blogPost));
 }
Пример #5
0
        public async Task <IActionResult> Create([Bind("Title,Content")] BlogPostCreateViewModel blogPost)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //TODO : SET THIS TO SERVICE
                    var user = await this.userManager.GetUserAsync(HttpContext.User);

                    await this.blogPostService.Create(blogPost.Title, blogPost.Content, user.UserName, user.Id);

                    this.logger.LogInformation("New Post is created");

                    return(RedirectToLocal("Index", "Home"));
                }
                catch (EntityIsNullException ex)
                {
                    this.logger.LogError(ex.Message);

                    return(NotFound());
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    this.logger.LogError(ex.Message);

                    return(NotFound());
                }
                catch (Exception ex)
                {
                    this.logger.LogError(ex.Message);

                    return(NotFound());
                }
            }

            return(View(blogPost));
        }