コード例 #1
0
        public IActionResult Create()
        {
            var viewModel = new CreateViceInputModel
            {
                Categories = this.vicesCategoriesService.GetAll(),
            };

            return(this.View(viewModel));
        }
コード例 #2
0
        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"));
        }
コード例 #3
0
        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();
        }