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)); }
//Chech Unique data for "Name" public IActionResult CheckWordInEnglishName(string name) { //Get item by Name WordInEnglish WordInEnglish = WordsInEnglishContext.FindWithInclude(a => a.Name == name).FirstOrDefault(); //Check if (WordInEnglish == null) { return(Json(true)); //if true current word name doesen`t exists in database } return(Json(false)); //if false current word name exists in database }
//If find a compare returns true //private bool CompareResultWithTranslation(CreatedTestYourselfViewModel oneItem) //{ // WordInEnglish word = WordsInEnglishContext.FindWithInclude(w => w.Id == oneItem.Id, w => w.TranslationOfWords).FirstOrDefault(); // bool result = false; // for (int i = 0; i < word.TranslationOfWords.Count(); i++) // { // if (word.TranslationOfWords[i].Name == oneItem.NameOfCurrentInputTranslation.Trim()) // { // result = true; // break; // } // } // return result; //} private CreatedTestYourselfViewModel CompareResultWithTranslation(CreatedTestYourselfViewModel oneItem) { WordInEnglish word = WordsInEnglishContext.FindWithInclude(w => w.Id == oneItem.Id, w => w.TranslationOfWords).FirstOrDefault(); oneItem.Name = word.Name; oneItem.TranslationOfWords = word.TranslationOfWords; oneItem.MadeMistake = ExeptionInTranslation.WithMistake; for (int i = 0; i < word.TranslationOfWords.Count(); i++) { if (word.TranslationOfWords[i].Name == oneItem.NameOfCurrentInputTranslation.Trim()) { oneItem.MadeMistake = ExeptionInTranslation.WithoutMistake; break; } } return(oneItem); }
public IActionResult CompareWordInEnglishName(string name, long id) { //Get category by Name and by id WordInEnglish currentWordInEnglishWithId = WordsInEnglishContext.FindWithInclude(a => a.Name == name && a.Id == id).FirstOrDefault(); //Get category by Name WordInEnglish searchName = WordsInEnglishContext.FindWithInclude(a => a.Name == name && a.Id != id).FirstOrDefault(); //Check var result = Json(true); if (currentWordInEnglishWithId != null) { result = Json(true); //current "Name" with current "id" exist in DB } else if (searchName != null) { result = Json(false); //current "Name" exist in DB but without current id } return(result); //return result }