public async Task <IActionResult> Create([Bind("TagId,Name")] Tag tag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tag));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("PostId,Title,Content,UserId")] Post post)
        {
            //TODO dodać wyświetlanie tagów
            if (ModelState.IsValid)
            {
                post.ShortDescription = post.Content.Substring(0, 300);

                post.PostDate   = DateTime.Today;
                post.EditedDate = DateTime.Today;
                post.LikeCount  = 0;


                _context.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "UserId", "Nick", post.UserId);
            //TODO: Modify this method like Edit method
            PopulatePostsWithTags(post);
            return(View(post));
        }