Ejemplo n.º 1
0
        public async Task <ActionResult> Create(
            [Bind("Name,Code,Description")] IFormCollection collection,
            [Bind("Name,Code,Description")] Education education)
        {
            if (ModelState.IsValid)
            {
                //1. Valid
                try
                {
                    //Add insert logic here
                    Education result = await educationRepo.Create(education);

                    if (result == null)
                    {
                        throw new Exception();
                    }
                    return(RedirectToAction(nameof(IndexAsync)));
                }
                catch (Exception exc)
                {
                    ModelState.AddModelError("", "Create is unable to save.");
                    return(View(education));
                }
            }
            else
            {
                //2. Invalid >> return
                return(View(education));
            }
        }
Ejemplo n.º 2
0
        public IActionResult Create(Education educationParam)
        {
            var education = _repo.Create(educationParam);

            return(Ok(education));
        }