Beispiel #1
0
        public async Task <IActionResult> Edit(int id, AddCategoryFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.ForEdit = true;
                return(View(model));
            }

            await this.categories.EditAsync(
                id,
                model.Name,
                model.Description);

            TempData.AddSuccessMessage($"Category {model.Name} was edited successfully");

            return(RedirectToAction(nameof(HomeController.Index), "Home", new { area = string.Empty }));
        }
Beispiel #2
0
        public async Task <IActionResult> Create(AddCategoryFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.AllTrainers = await this.GetAllTrainers();

                return(View(model));
            }

            await this.categories.CreateAsync(
                model.Name,
                model.Description,
                model.SelectedTrainers);

            TempData.AddSuccessMessage($"Category {model.Name} was created successfully");

            return(RedirectToAction(nameof(HomeController.Index), "Home", new { area = string.Empty }));
        }