예제 #1
0
        public async Task <IActionResult> Add(Clothing c)
        {
            if (ModelState.IsValid)
            {
                await ClothingDb.Add(c, _context);

                // TempData lasts for one redirect
                TempData["Message"] = $"{c.Title} added successfully";
                return(RedirectToAction("ShowAll"));
            }
            // Return same view with error/validation messages
            return(View(c));
        }
        public async Task <IActionResult> Add(Clothing c)
        {
            if (ModelState.IsValid)
            {
                await ClothingDb.Add(_context, c);

                //Temp data last for one redirect
                TempData["Msg"] = $"{c.Title} added successfully!";
                return(RedirectToAction("ShowAll"));
            }
            //Return same view with validation msgs.
            return(View(c));
        }
        public async Task <IActionResult> Add(Clothing c)
        {
            if (ModelState.IsValid)                //if data is valid
            {
                await ClothingDb.Add(c, _context); //add to database

                //TempData lasts for one redirect
                TempData["Message"] = $"{c.Title} added successfully";

                return(RedirectToAction("ShowAll"));
            }

            return(View(c)); //else return the same view with validation error messages
        }