コード例 #1
0
        public async Task <IActionResult> Add()
        {
            var model = new AddDessertInputModel()
            {
                Categories = await this.categoriesService.GetAllAsSelectListItemAsync(),
            };

            return(this.View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Add(AddDessertInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input.Categories = await this.categoriesService.GetAllAsSelectListItemAsync();

                return(this.View(input));
            }

            await this.dessertsService.AddAsync(input.Name, input.Picture, input.Price, input.Description, input.CategoryId);

            this.TempData["InfoMessage"] = GlobalConstants.SuccessAddedMessage;

            return(this.RedirectToAction(nameof(this.GetAll)));
        }