private void SaveBtnClick(object obj) { try { if (!string.IsNullOrWhiteSpace(keyEntry.Text) && keyEntry.Text != "Yeni bir tip ekle") { var type = GetWordTypes().FirstOrDefault(i => i.ToString() == typePicker.SelectedItem.ToString()); if (type != null) { _wordService.Create(new Word() { Key = keyEntry.Text, Description = descriptionEntry.Text, Id = Guid.NewGuid().ToString(), PrefixKey = keyEntry.Text[0].ToString().ToUpper(), Type = type }); MainPage.RefreshPages(); Navigation.PopAsync(); } else { label.Text = "Kelime Tipi bulunamadı!"; } } else { label.Text = "Kelime tipi alanı boş geçilemez"; } } catch (Exception ex) { label.Text = "İstenmeyen bir durum oluştu! Lütfen tüm alanları doğru doldurduğunuzdan emin olun!"; } }
public async Task <IActionResult> Create(WordCreateModel model) { var user = await _userManager.GetUserAsync(User); await _wordService.Create(model, user.Id); return(RedirectToAction("GetAll")); }
public ActionResult <Word> Create(Word word) { _wordService.Create(word); return(CreatedAtRoute("GetWord", new Word { Id = word.Id }, word)); }
public async Task TestCreate() { //Test with empty database WordService service = ServiceBuilder; //build an empty database //TODO: Is there something to test here...? //Test with populated database string[] idList = SetUpDatabase(service).Result; //populates the database //make a couple of new words, one filled and one empty Word newWord1 = new Word(); newWord1.Vernacular = "Hello"; newWord1.Gloss = 5; newWord1.Audio = "N/A"; newWord1.Timestamp = "4:30"; Word emptyWord = new Word(); //add them newWord1 = await service.Create(newWord1); emptyWord = await service.Create(emptyWord); //let's see if everything got in there correctly Task <List <Word> > getTask = service.GetAllWords(); List <Word> getList = await getTask; Assert.AreEqual(getList.Count, 4); Word wordInDb1 = getList[2]; Word wordInDb2 = getList[3]; Assert.AreEqual(wordInDb1.Vernacular, "Hello"); Assert.AreEqual(wordInDb1.Gloss, 5); Assert.AreEqual(wordInDb1.Audio, "N/A"); Assert.AreEqual(wordInDb1.Timestamp, "4:30"); Assert.IsNull(wordInDb2.Vernacular); //there should be nothing there for the empty word Assert.IsNull(wordInDb2.Gloss); Assert.IsNull(wordInDb2.Audio); Assert.IsNull(wordInDb2.Timestamp); //TODO: Perhaps a phoney attribute? }
public async Task <string[]> SetUpDatabase(WordService service) { //if there are any words in the database, we want to delete them Task <List <Word> > getTask = service.GetAllWords(); List <Word> getList = await getTask; foreach (Word word in getList) { bool deleted = await service.Delete(word.Id); if (!deleted) { throw new System.Exception("Item not deleted!"); } } //let's always have these two words in the database Word word1 = new Word(); word1.Vernacular = "One"; word1.Gloss = 1; word1.Audio = "audio1.mp4"; word1.Timestamp = "1:00"; Word word2 = new Word(); word2.Vernacular = "Two"; word2.Gloss = 2; word2.Audio = "audio2.mp4"; word2.Timestamp = "2:00"; //since the ids will change every time, I'm going to return them for easy reference string[] idList = new string[2]; word1 = await service.Create(word1); word2 = await service.Create(word2); idList[0] = word1.Id; idList[1] = word2.Id; return(idList); }