Esempio n. 1
0
        public async Task <IActionResult> Create(TopicCreateOrUpdateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Identity.GetUserId <long>();

                var entity = new Topic()
                {
                    Title   = model.Title,
                    Content = model.Content,
                    // Guid = Guid.NewGuid(),
                    Status        = TopicStatus.Published, // default published
                    PublishedTime = DateTime.Now,
                    TagsId        = model.TagsId,
                    UserId        = userId,
                };

                try
                {
                    await _topicService.AddAsync(entity);

                    return(RedirectToAction(nameof(Details), new { id = entity.Id }));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            PrepareViewModel(model);
            return(View(model));
        }