Esempio n. 1
0
        public async Task <IActionResult> Create(Catalog catalog)
        {
            if (ModelState.IsValid)
            {
                catalog.Id = Guid.NewGuid();
                _context.Add(catalog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(catalog));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(PostCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Post post = new Post();
                post.Id      = Guid.NewGuid();
                post.Catalog = await _context.Catalog.FindAsync(viewModel.Catalog);

                post.Time    = DateTime.Now;
                post.Title   = viewModel.Title;
                post.Content = viewModel.Content;

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }