private void btnFindCommuniKateTopPageLocation_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "Open Board Format (*.obz)|*.obz" }; if (openFileDialog.ShowDialog() == true) { string fileLocation = null; if (openFileDialog.FileName.EndsWith(@".obz")) { txtCommuniKateTopPageLocation.Text = openFileDialog.FileName; fileLocation = txtCommuniKateTopPageLocation.Text; } else { txtCommuniKateTopPageLocation.Text = Properties.Resources.COMMUNIKATE_TOPPAGE_LOCATION_ERROR_LABEL; } WordsViewModel viewModel = this.DataContext as WordsViewModel; if (viewModel != null && !string.IsNullOrWhiteSpace(fileLocation)) { viewModel.CommuniKatePagesetLocation = fileLocation; viewModel.CommuniKateStagedForDeletion = true; } } }
public void TaskAreas_SortBy_WordsSortedCorrectly() { using (var env = new TestEnvironment()) { SetupProjectWithWords(env); var commonTasks = (TaskAreaItemsViewModel)env.VarietiesViewModel.TaskAreas[0]; env.VarietiesViewModel.SelectedVariety = env.VarietiesViewModel.Varieties.First(v => v.Name == "variety2"); WordsViewModel wordsViewModel = env.VarietiesViewModel.SelectedVariety.Words; wordsViewModel.WordsView = new ListCollectionView(wordsViewModel.Words); var sortWordsByItems = (TaskAreaItemsViewModel)commonTasks.Items[4]; var sortWordsByGroup = (TaskAreaCommandGroupViewModel)sortWordsByItems.Items[0]; // default sorting is by gloss, change to form sortWordsByGroup.SelectedCommand = sortWordsByGroup.Commands[1]; sortWordsByGroup.SelectedCommand.Command.Execute(null); Assert.That(wordsViewModel.WordsView.Cast <WordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] { "goofy", "google search", "help" })); // sort by validity sortWordsByGroup.SelectedCommand = sortWordsByGroup.Commands[2]; sortWordsByGroup.SelectedCommand.Command.Execute(null); Assert.That(wordsViewModel.WordsView.Cast <WordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] { "google search", "help", "goofy" })); // change sorting back to gloss sortWordsByGroup.SelectedCommand = sortWordsByGroup.Commands[0]; sortWordsByGroup.SelectedCommand.Command.Execute(null); Assert.That(wordsViewModel.WordsView.Cast <WordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] { "help", "google search", "goofy" })); } }
//[Authorize(Roles = "Teacher")] public async Task <IActionResult> Create(WordsViewModel words) { if (ModelState.IsValid) { var image = words.Image; if (image != null && image.Length > 0) { var fileName = Path.GetFileName(image.FileName); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img\\WordImg", fileName); using (var fileSteam = new FileStream(filePath, FileMode.Create)) { await image.CopyToAsync(fileSteam); } words.ImagePath = fileName; } Words word = new Words { WordEnglish = words.WordEnglish, WordTurkish = words.WordTurkish, ImagePath = words.ImagePath, Meaning = words.Meaning }; _context.Add(word); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(words)); }
private void btnFindPresageDatabaseLocation_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "Presage Database (*.db)|*.db" }; if (openFileDialog.ShowDialog() == true) { string fileLocation = null; if (openFileDialog.FileName.EndsWith(@".db")) { txtPresageDatabaseLocation.Text = openFileDialog.FileName; fileLocation = txtPresageDatabaseLocation.Text; } else { txtPresageDatabaseLocation.Text = Properties.Resources.COMMUNIKATE_TOPPAGE_LOCATION_ERROR_LABEL; } WordsViewModel viewModel = this.DataContext as WordsViewModel; if (viewModel != null && !string.IsNullOrWhiteSpace(fileLocation)) { viewModel.PresageDatabaseLocation = fileLocation; } } }
public void FindCommand_SwitchVarietyFormNothingSelectedMatches_CorrectWordsSelected() { using (var env = new TestEnvironment()) { SetupProjectWithWords(env); env.OpenFindDialog(); env.VarietiesViewModel.SelectedVariety = env.VarietiesViewModel.Varieties[1]; WordsViewModel wordsViewModel = env.VarietiesViewModel.SelectedVariety.Words; wordsViewModel.WordsView = new ListCollectionView(wordsViewModel.Words); WordViewModel[] wordsViewArray = wordsViewModel.WordsView.Cast <WordViewModel>().ToArray(); env.FindViewModel.Field = FindField.Form; env.FindViewModel.String = "go"; env.FindViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); wordsViewModel.SelectedWords.Clear(); wordsViewModel.SelectedWords.Add(wordsViewArray[0]); env.FindViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); env.FindViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable())); env.FindViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable())); } }
public ActionResult NewWord(WordsViewModel data) { var httpContext = _accessor.HttpContext; _member = httpContext.Session.GetString("_member"); if (!string.IsNullOrEmpty(_member)) { //Checking token for request if (_tokenhelper.CheckToken()) { _token = httpContext.Session.GetString("_token"); } else { Task <string> result = _tokenhelper.CreateToken(); result.Wait(); _token = result.Result; } Task <bool> operationResult = _webApiHelper.InsertNewWordByWebApi(data, _token); operationResult.Wait(); return(Json(new { success = operationResult.Result })); } else { return(Json(new { success = false })); } }
// GET: Words public ActionResult NewWords() { WordsViewModel viewModel = new WordsViewModel { Context = WordsData.GetNewWords() }; return View(viewModel); }
private void ApplyChanges() { DictionaryViewModel.ApplyChanges(); OtherViewModel.ApplyChanges(); PointingAndSelectingViewModel.ApplyChanges(); SoundsViewModel.ApplyChanges(); VisualsViewModel.ApplyChanges(); WordsViewModel.ApplyChanges(); }
public void FindCommand() { DispatcherHelper.Initialize(); var segmentPool = new SegmentPool(); var projectService = Substitute.For <IProjectService>(); var dialogService = Substitute.For <IDialogService>(); var busyService = Substitute.For <IBusyService>(); var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService); var exportService = Substitute.For <IExportService>(); WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words); WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word); var segments = new SegmentsViewModel(projectService, dialogService, busyService, exportService, wordsFactory, wordFactory); CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool); project.Meanings.AddRange(new[] { new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3") }); project.Varieties.AddRange(new[] { new Variety("variety1"), new Variety("variety2") }); project.Varieties[0].Words.AddRange(new[] { new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæd", project.Meanings[2]) }); project.Varieties[1].Words.AddRange(new[] { new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2]) }); projectService.Project.Returns(project); analysisService.SegmentAll(); projectService.ProjectOpened += Raise.Event(); WordsViewModel observedWords = segments.ObservedWords; observedWords.WordsView = new ListCollectionView(observedWords.Words); FindViewModel findViewModel = null; Action closeCallback = null; dialogService.ShowModelessDialog(segments, Arg.Do <FindViewModel>(vm => findViewModel = vm), Arg.Do <Action>(callback => closeCallback = callback)); segments.FindCommand.Execute(null); Assert.That(findViewModel, Is.Not.Null); Assert.That(closeCallback, Is.Not.Null); // already open, shouldn't get opened twice dialogService.ClearReceivedCalls(); segments.FindCommand.Execute(null); dialogService.DidNotReceive().ShowModelessDialog(segments, Arg.Any <FindViewModel>(), Arg.Any <Action>()); // nothing selected, no match findViewModel.Field = FindField.Form; findViewModel.String = "nothing"; findViewModel.FindNextCommand.Execute(null); Assert.That(observedWords.SelectedWords, Is.Empty); // nothing selected, matches segments.SelectedSegment = segments.Varieties[1].Segments[3]; WordViewModel[] wordsViewArray = observedWords.WordsView.Cast <WordViewModel>().ToArray(); findViewModel.String = "fi"; findViewModel.FindNextCommand.Execute(null); Assert.That(observedWords.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); findViewModel.FindNextCommand.Execute(null); Assert.That(observedWords.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); }
// Lists all available Words from a given language // GET: Admin/Words?languageId={languageId} public ActionResult Words(int languageId) { var model = new WordsViewModel() { Words = UOW.SlowoRepo.GetAll(languageId), LanguageId = languageId }; return(View(model)); }
public void OpenProject(CogProject project) { _projectService.Project.Returns(project); _projectService.ProjectOpened += Raise.Event(); VarietiesViewModel.VarietiesView = new ListCollectionView(VarietiesViewModel.Varieties); if (VarietiesViewModel.SelectedVariety != null) { WordsViewModel wordsViewModel = VarietiesViewModel.SelectedVariety.Words; wordsViewModel.WordsView = new ListCollectionView(wordsViewModel.Words); } }
public IActionResult Index(WordsViewModel wvm) { // Si la validación es correcta, añadimos la nueva palabra a la lista if (ModelState.IsValid) { wvm.Words.AddWord(wvm.Word); wvm.Word = ""; } return(View(wvm)); }
public void DoNotReloadDictionaryWhenLanguageIsTheSame(){ //Arrange var mockDictionaryService = new Mock<IDictionaryService>(); var wordsViewModel = new WordsViewModel(mockDictionaryService.Object); //Act wordsViewModel.KeyboardAndDictionaryLanguage = wordsViewModel.KeyboardAndDictionaryLanguage; wordsViewModel.ApplyChanges(); //Assert mockDictionaryService.Verify(t => t.LoadDictionary(), Times.Exactly(0)); }
public void ReloadDictionaryWhenLanguageChanged(){ //Arrange var mockDictionaryService = new Mock<IDictionaryService>(); var wordsViewModel = new WordsViewModel(mockDictionaryService.Object); //Act wordsViewModel.KeyboardAndDictionaryLanguage = wordsViewModel.KeyboardAndDictionaryLanguage == Enums.Languages.FrenchFrance ? Enums.Languages.EnglishUK : Enums.Languages.FrenchFrance; wordsViewModel.ApplyChanges(); //Assert mockDictionaryService.Verify(t => t.LoadDictionary(), Times.AtLeast(1)); }
public ManagementViewModel( IAudioService audioService, IDictionaryService dictionaryService) { //Instantiate child VMs DictionaryViewModel = new DictionaryViewModel(dictionaryService); OtherViewModel = new OtherViewModel(); PointingAndSelectingViewModel = new PointingAndSelectingViewModel(); SoundsViewModel = new SoundsViewModel(audioService); VisualsViewModel = new VisualsViewModel(); WordsViewModel = new WordsViewModel(dictionaryService); //Instantiate interaction requests and commands ConfirmationRequest = new InteractionRequest <Confirmation>(); OkCommand = new DelegateCommand <Window>(Ok); //Can always click Ok CancelCommand = new DelegateCommand <Window>(Cancel); //Can always click Cancel }
public void FindCommand_GlossNothingSelectedMatches_CorrectWordsSelected() { using (var env = new TestEnvironment()) { SetupProjectWithWords(env); env.OpenFindDialog(); // gloss searches env.FindViewModel.Field = FindField.Gloss; env.FindViewModel.String = "gloss2"; env.FindViewModel.FindNextCommand.Execute(null); WordsViewModel wordsViewModel = env.VarietiesViewModel.SelectedVariety.Words; WordViewModel[] wordsViewArray = wordsViewModel.WordsView.Cast <WordViewModel>().ToArray(); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); env.FindViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); } }
public void SetUp() { _busyService = Substitute.For <IBusyService>(); _analysisService = Substitute.For <IAnalysisService>(); _meaning = new Meaning("gloss", "category"); _words = new ObservableList <WordViewModel> { new WordViewModel(_busyService, _analysisService, new Word("valid", _meaning)) { IsValid = true }, new WordViewModel(_busyService, _analysisService, new Word("invalid", _meaning)) { IsValid = false } }; _wordsViewModel = new WordsViewModel(_busyService, new ReadOnlyBindableList <WordViewModel>(_words)); }
////// //This method using for update word in database ////// public async Task <bool> UpdateWordByWebApi(WordsViewModel requestBody, string token) { var request = new HttpRequestMessage(HttpMethod.Post, webApiUrl + "api/WordGame/UpdateWord"); request.Headers.Add("Authorization", "Bearer " + token); var json = JsonConvert.SerializeObject(requestBody); request.Content = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); var client = _clientFactory.CreateClient(); var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { return(true); } else { return(false); } }
public void FindCommand() { DispatcherHelper.Initialize(); var projectService = Substitute.For <IProjectService>(); var dialogService = Substitute.For <IDialogService>(); var busyService = Substitute.For <IBusyService>(); var analysisService = Substitute.For <IAnalysisService>(); WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words); WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word); VarietiesVarietyViewModel.Factory varietyFactory = variety => new VarietiesVarietyViewModel(projectService, dialogService, wordsFactory, wordFactory, variety); var varieties = new VarietiesViewModel(projectService, dialogService, analysisService, varietyFactory); var project = new CogProject(_spanFactory) { Meanings = { new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3") }, Varieties = { new Variety("variety1"), new Variety("variety2") } }; project.Varieties[0].Words.AddRange(new[] { new Word("hello", project.Meanings[0]), new Word("good", project.Meanings[1]), new Word("bad", project.Meanings[2]) }); project.Varieties[1].Words.AddRange(new[] { new Word("help", project.Meanings[0]), new Word("google", project.Meanings[1]), new Word("goofy", project.Meanings[2]) }); projectService.Project.Returns(project); projectService.ProjectOpened += Raise.Event(); varieties.VarietiesView = new ListCollectionView(varieties.Varieties); WordsViewModel wordsViewModel = varieties.SelectedVariety.Words; wordsViewModel.WordsView = new ListCollectionView(wordsViewModel.Words); WordViewModel[] wordsViewArray = wordsViewModel.WordsView.Cast <WordViewModel>().ToArray(); FindViewModel findViewModel = null; Action closeCallback = null; dialogService.ShowModelessDialog(varieties, Arg.Do <FindViewModel>(vm => findViewModel = vm), Arg.Do <Action>(callback => closeCallback = callback)); varieties.FindCommand.Execute(null); Assert.That(findViewModel, Is.Not.Null); Assert.That(closeCallback, Is.Not.Null); // already open, shouldn't get opened twice dialogService.ClearReceivedCalls(); varieties.FindCommand.Execute(null); dialogService.DidNotReceive().ShowModelessDialog(varieties, Arg.Any <FindViewModel>(), Arg.Any <Action>()); // form searches findViewModel.Field = FindField.Form; // nothing selected, no match findViewModel.String = "fall"; findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.Empty); // nothing selected, matches findViewModel.String = "he"; findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable())); findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable())); // first word selected, matches findViewModel.String = "o"; findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable())); findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable())); // start search over findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); // last word selected, matches wordsViewModel.SelectedWords.Clear(); wordsViewModel.SelectedWords.Add(wordsViewArray[2]); findViewModel.String = "ba"; findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable())); findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable())); // switch variety, nothing selected, matches, change selected word varieties.SelectedVariety = varieties.Varieties[1]; wordsViewModel = varieties.SelectedVariety.Words; wordsViewModel.WordsView = new ListCollectionView(wordsViewModel.Words); wordsViewArray = wordsViewModel.WordsView.Cast <WordViewModel>().ToArray(); findViewModel.String = "go"; findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); wordsViewModel.SelectedWords.Clear(); wordsViewModel.SelectedWords.Add(wordsViewArray[0]); findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable())); findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable())); // gloss searches findViewModel.Field = FindField.Gloss; findViewModel.String = "gloss2"; findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); findViewModel.FindNextCommand.Execute(null); Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable())); }
public void TaskAreas() { DispatcherHelper.Initialize(); var projectService = Substitute.For <IProjectService>(); var dialogService = Substitute.For <IDialogService>(); var busyService = Substitute.For <IBusyService>(); var analysisService = Substitute.For <IAnalysisService>(); WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words); WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word); VarietiesVarietyViewModel.Factory varietyFactory = variety => new VarietiesVarietyViewModel(projectService, dialogService, wordsFactory, wordFactory, variety); var varieties = new VarietiesViewModel(projectService, dialogService, analysisService, varietyFactory); var project = new CogProject(_spanFactory) { Meanings = { new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3") }, Varieties = { new Variety("variety1"), new Variety("variety2") } }; project.Varieties[0].Words.AddRange(new[] { new Word("hello", project.Meanings[0]), new Word("good", project.Meanings[1]), new Word("bad", project.Meanings[2]) }); project.Varieties[1].Words.AddRange(new[] { new Word("help", project.Meanings[0]), new Word("google", project.Meanings[1]), new Word("goofy", project.Meanings[2]) }); projectService.Project.Returns(project); projectService.ProjectOpened += Raise.Event(); varieties.VarietiesView = new ListCollectionView(varieties.Varieties); var commonTasks = (TaskAreaItemsViewModel)varieties.TaskAreas[0]; var addVariety = (TaskAreaCommandViewModel)commonTasks.Items[0]; dialogService.ShowModalDialog(varieties, Arg.Do <EditVarietyViewModel>(vm => vm.Name = "variety3")).Returns(true); addVariety.Command.Execute(null); Assert.That(varieties.SelectedVariety.Name, Is.EqualTo("variety3")); Assert.That(varieties.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "variety1", "variety2", "variety3" })); var renameVariety = (TaskAreaCommandViewModel)commonTasks.Items[1]; dialogService.ShowModalDialog(varieties, Arg.Do <EditVarietyViewModel>(vm => vm.Name = "variety4")).Returns(true); renameVariety.Command.Execute(null); Assert.That(varieties.SelectedVariety.Name, Is.EqualTo("variety4")); Assert.That(varieties.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "variety1", "variety2", "variety4" })); var removeVariety = (TaskAreaCommandViewModel)commonTasks.Items[2]; dialogService.ShowYesNoQuestion(varieties, Arg.Any <string>(), Arg.Any <string>()).Returns(true); removeVariety.Command.Execute(null); Assert.That(varieties.SelectedVariety.Name, Is.EqualTo("variety1")); Assert.That(varieties.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "variety1", "variety2" })); varieties.SelectedVariety = varieties.Varieties.First(v => v.Name == "variety2"); WordsViewModel wordsViewModel = varieties.SelectedVariety.Words; wordsViewModel.WordsView = new ListCollectionView(wordsViewModel.Words); var sortWordsByItems = (TaskAreaItemsViewModel)commonTasks.Items[4]; var sortWordsByGroup = (TaskAreaCommandGroupViewModel)sortWordsByItems.Items[0]; // default sorting is by gloss, change to form sortWordsByGroup.SelectedCommand = sortWordsByGroup.Commands[1]; sortWordsByGroup.SelectedCommand.Command.Execute(null); Assert.That(wordsViewModel.WordsView.Cast <WordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] { "goofy", "google", "help" })); // change sorting back to gloss sortWordsByGroup.SelectedCommand = sortWordsByGroup.Commands[0]; sortWordsByGroup.SelectedCommand.Command.Execute(null); Assert.That(wordsViewModel.WordsView.Cast <WordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] { "help", "google", "goofy" })); }
//[Authorize(Roles = "Teacher")] public async Task <IActionResult> Edit(int id, WordsViewModel words) { if (id != words.Id) { return(NotFound()); } if (ModelState.IsValid) { var word = new Words { Id = words.Id, WordEnglish = words.WordEnglish, WordTurkish = words.WordTurkish, Meaning = words.Meaning }; var pathFromTable = await _context.Words .Where(b => b.Id == id) .Select(b => new SelectListItem { Value = b.Id.ToString(), Text = b.ImagePath }) .ToListAsync(); var oldPath = pathFromTable[0].Text; if (words.Image != null) { var image = words.Image; var fileName = Path.GetFileName(image.FileName); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img\\WordImg", fileName); word.ImagePath = fileName; if (fileName != oldPath && oldPath != null) { using (var fileSteam = new FileStream(filePath, FileMode.Create)) { await image.CopyToAsync(fileSteam); } oldPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img\\WordImg", oldPath); System.IO.File.Delete(oldPath); } } else { word.ImagePath = oldPath; } try { _context.Update(word); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WordsExists(words.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(words)); }