public async Task <IActionResult> Create(CreateStageOfMethodViewModel newStage) { //Use for Titile in html ViewData["Title"] = "Создать стейдж"; //Use for head in page ViewBag.HeadPageText = "Создать стейдж"; //Check newStage on null if (newStage != null) { //Sever validation if (ModelState.IsValid) { //Work with data StageOfMethod currentStage = Mapper.Map <CreateStageOfMethodViewModel, StageOfMethod>(newStage); await StageOfMethodsContext.Add(currentStage); //ViewBags for "_Success" view ViewBag.SuccessText = "Стейдж успешно добавлен"; ViewBag.MethodRedirect = "Index"; ViewBag.ControllerRedirect = "StageOfMethod"; //Render user on temporary view "Views/Shared/_Success" return(PartialView("_Success")); } } //If newStage is null or validation was false return(View(newStage)); }
//Method for checking the Name of current Stage public IActionResult CheckNameOfStage(string name) { StageOfMethod stage = StageOfMethodsContext.FindWithInclude(s => s.Name == name).FirstOrDefault(); if (stage == null) { return(Json(true)); //If true current name doesn`t exist in database } return(Json(false)); //If false current name exists in database }