public async Task <IActionResult> Create(CreateWordInEnglishViewModel word) { //Use for Titile in html ViewData["Title"] = "Добавить слово"; //Use for head in page ViewBag.HeadPageText = "Добавить слово и перевод"; //Check newStage on null if (word != null) { // Server validation if (ModelState.IsValid) { //Work with data WordInEnglish currentWord = Mapper.Map <CreateWordInEnglishViewModel, WordInEnglish>(word); await WordsInEnglishContext.Add(currentWord); //Add many translations, user method "GetTranslationsFromStringArray" to make new object of TranslationOfWord type await TranslationsOfWordContext.AddMany(GetTranslationsFromListAndGiveIdOfWordInEnglish(word.Translations, currentWord.Id)); //ViewBags for "_Success" view ViewBag.SuccessText = "Слово успешно добавленно"; ViewBag.MethodRedirect = "Index"; ViewBag.ControllerRedirect = "Home"; //Render user on temporary view "Views/Shared/_Success" return(PartialView("_Success")); } } //Update SelectList for html data and and all stages in it with current word word.StagesOfMethod = new SelectList(StageOfMethodsContext.GetAllIQueryableWithInclude().ToList(), "Id", "Name", word.StageOfMethodId); //If word is null or validation was false return(View(word)); }
public IActionResult Create() { CreateWordInEnglishViewModel newWord = new CreateWordInEnglishViewModel { StagesOfMethod = new SelectList(StageOfMethodsContext.GetAllIQueryableWithInclude().ToList(), "Id", "Name") }; //Use for Titile in html ViewData["Title"] = "Добавить слово"; //Use for head in page ViewBag.HeadPageText = "Добавить слово и перевод"; //Render to View Create return(View(newWord)); }