public IActionResult Create() { var viewModel = new CreateViceInputModel { Categories = this.vicesCategoriesService.GetAll(), }; return(this.View(viewModel)); }
public async Task <IActionResult> Create(CreateViceInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; await this.vicesService.CreateAsync(input, userId); return(this.Redirect("/Vices/All")); }
public async Task CreateAsync(CreateViceInputModel input, string userId) { var vice = new Vice() { AddedByUserId = userId, CategoryId = input.CategoryId, Content = input.Content, }; await this.vicesRepository.AddAsync(vice); await this.vicesRepository.SaveChangesAsync(); }