public static int?AddTerm(this IDivision division, IModelContext modelContext) { // TODO: Get vocabulary name from config var vocabularyName = "University_Structure"; var vocabulary = new VocabularyController().GetVocabularies().FirstOrDefault(v => v.Name == vocabularyName); if (vocabulary != null) { var termName = GetSafeTermName(division.ShortTitle, division.Title); try { var term = new Term(termName, string.Empty, vocabulary.VocabularyId); var parentDivision = division.GetParentDivision(modelContext); if (parentDivision != null) { term.ParentTermId = parentDivision.DivisionTermID; } return(new TermController().AddTerm(term)); } catch (Exception ex) { Exceptions.LogException(new Exception($"Error adding {termName} term to {vocabularyName} vocabulary.", ex)); } } else { Exceptions.LogException(new Exception($"Could not find vocabulary with name {vocabularyName}.")); } return(null); }
public VocabulariesController() { this._termController = new TermController(); this._vocabularyController = new VocabularyController(); this._validator = new Validator(new DataAnnotationsObjectValidator()); this._validator.Validators.Add(new VocabularyNameValidator(this._vocabularyController, this._termController)); }
private void AddRow_Click(object sender, RoutedEventArgs e) { Vocabulary row = new Vocabulary(); if (ForeignBox.Text.Length == 0 || LocalBox.Text.Length == 0) { } else { row.ForeignWord = ForeignBox.Text; row.Transcription = TransBox.Text; row.LocalWord = LocalBox.Text; row.UserID = user.Id; VocabularyController.AddRow(_vocabularyContext, row); if (Exceptions.IsError == 1) { MessageBox.Show(Exceptions.ErrorMessage); Exceptions.IsError = 0; } else { DialogResult = true; } } }
public ActionResult ChangingWord(string key, string choosedRow, Vocabulary changes) { Vocabulary changedRow = new Vocabulary(); User valueSession = (User)Session["User"]; IsUserAuth(valueSession); changedRow = VocabularyController.FindRow(choosedRow, Byte.Parse(key), _vocabularyContext); if (changedRow != null) { if (changes.ForeignWord != null && changes.ForeignWord != "") { changedRow.ForeignWord = changes.ForeignWord; } if (changes.Transcription != null && changes.Transcription != "") { changedRow.Transcription = changes.Transcription; } if (changes.LocalWord != null && changes.LocalWord != "") { changedRow.LocalWord = changes.LocalWord; } } else { throw new Exception("This translate doesn't exist!"); } VocabularyController.UpdateRow(_vocabularyContext, changedRow); return(RedirectToAction("Index", "Vocabularies")); }
// TODO: Need separate methods to get and update public static string Update(DropDownList comboWorkingHours, string workingHours, bool addToVocabulary) { workingHours = workingHours.Trim(); var workingHoursNonEmpty = !string.IsNullOrWhiteSpace(workingHours); if (comboWorkingHours.SelectedIndex <= 0 || workingHoursNonEmpty) { // TODO: Shouldn't we try to add term after updating main item? if (addToVocabulary && workingHoursNonEmpty) { // try add new term to working hours vocabulary var vocCtrl = new VocabularyController(); var voc = vocCtrl.GetVocabularies().SingleOrDefault(v => v.Name == UniversityConfig.Instance.Vocabularies.WorkingHours); if (voc != null) { var termCtrl = new TermController(); termCtrl.AddTerm(new Term(workingHours, "", voc.VocabularyId)); vocCtrl.ClearVocabularyCache(); } } return(workingHours); } // else: get working hours from a combo return(comboWorkingHours.SelectedItem.Text); }
public static int?AddOrUpdateTerm(this IDivision division, IModelContext modelContext) { var vocabularyName = UniversityConfig.Instance.Vocabularies.OrgStructure; var vocabulary = new VocabularyController().GetVocabularies().FirstOrDefault(v => v.Name == vocabularyName); if (vocabulary == null) { Exceptions.LogException(new Exception($"Could not find the {vocabularyName} vocabulary.")); return(null); } var termName = GetSafeTermName(division.ShortTitle, division.Title); var termCtrl = new TermController(); var term = default(Term); if (division.DivisionTermID == null) { term = termCtrl.GetTermsByVocabulary(vocabulary.VocabularyId).FirstOrDefault(t => t.Name == termName); if (term != null) { Exceptions.LogException(new Exception($"Could not create term {termName} in the {vocabularyName} vocabulary as it already exists.")); return(null); } term = new Term(termName, string.Empty, vocabulary.VocabularyId); } else { term = termCtrl.GetTerm(division.DivisionTermID.Value); term.Name = termName; } var parentDivision = division.GetParentDivision(modelContext); if (parentDivision != null) { term.ParentTermId = parentDivision.DivisionTermID; } else { term.ParentTermId = null; } try { if (division.DivisionTermID == null) { return(termCtrl.AddTerm(term)); } termCtrl.UpdateTerm(term); return(term.TermId); } catch (Exception ex) { Exceptions.LogException(new Exception($"Error creating/updating {termName} term in the vocabulary {vocabularyName}.", ex)); } return(null); }
public void VocabularyController_AddVocabulary_Throws_On_Null_Vocabulary() { //Arrange var mockDataService = new Mock <IDataService>(); var vocabularyController = new VocabularyController(mockDataService.Object); //Act, Arrange Assert.Throws <ArgumentNullException>(() => vocabularyController.AddVocabulary(null)); }
protected override void OnInit() { base.OnInit(); if (View.Model.Vocabulary == null) { View.Model.Vocabulary = VocabularyController.GetVocabularies().Where(v => v.VocabularyId == VocabularyId).SingleOrDefault(); View.Model.Terms = TermController.GetTermsByVocabulary(VocabularyId).ToList(); } }
public static IVocabularyController GetVocabularyController() { IVocabularyController ctl = ComponentFactory.GetComponent <IVocabularyController>(); if (ctl == null) { ctl = new VocabularyController(); ComponentFactory.RegisterComponentInstance <IVocabularyController>(ctl); } return(ctl); }
public void VocabularyController_AddVocabulary_Throws_On_Invalid_Name() { // Arrange var mockDataService = new Mock<IDataService>(); var vocabularyController = new VocabularyController(mockDataService.Object); Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary(); vocabulary.Name = Constants.VOCABULARY_InValidName; // Act, Arrange Assert.Throws<ArgumentException>(() => vocabularyController.AddVocabulary(vocabulary)); }
public void VocabularyController_DeleteVocabulary_Throws_On_Negative_VocabularyId() { // Arrange var mockDataService = new Mock<IDataService>(); var vocabularyController = new VocabularyController(mockDataService.Object); Vocabulary vocabulary = new Vocabulary(); vocabulary.VocabularyId = Null.NullInteger; // Act, Arrange Assert.Throws<ArgumentOutOfRangeException>(() => vocabularyController.DeleteVocabulary(vocabulary)); }
public void VocabularyController_AddVocabulary_Throws_On_Negative_ScopeTypeID() { // Arrange var mockDataService = new Mock<IDataService>(); var vocabularyController = new VocabularyController(mockDataService.Object); Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary(); vocabulary.ScopeTypeId = Null.NullInteger; // Act, Arrange Assert.Throws<ArgumentOutOfRangeException>(() => vocabularyController.AddVocabulary(vocabulary)); }
public void VocabularyController_GetVocabularies_Returns_List_Of_Vocabularies() { // Arrange var mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetVocabularies()).Returns(MockHelper.CreateValidVocabulariesReader(Constants.VOCABULARY_ValidCount)); var vocabularyController = new VocabularyController(mockDataService.Object); // Act IQueryable<Vocabulary> vocabularys = vocabularyController.GetVocabularies(); // Assert Assert.AreEqual(Constants.VOCABULARY_ValidCount, vocabularys.Count()); }
public void VocabularyController_AddVocabulary_Calls_DataService_On_Valid_Arguments() { //Arrange var mockDataService = new Mock <IDataService>(); var vocabularyController = new VocabularyController(mockDataService.Object); Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary(); //Act int vocabularyId = vocabularyController.AddVocabulary(vocabulary); //Assert mockDataService.Verify(ds => ds.AddVocabulary(vocabulary, It.IsAny <int>())); }
public void VocabularyController_AddVocabulary_Clears_Vocabulary_Cache_On_Valid_Vocabulary() { //Arrange var mockDataService = new Mock <IDataService>(); var vocabularyController = new VocabularyController(mockDataService.Object); Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary(); //Act vocabularyController.AddVocabulary(vocabulary); //Assert mockCache.Verify(cache => cache.Remove(Constants.VOCABULARY_CacheKey)); }
protected IEnumerable <Term> GetTerms() { var terms = new List <Term> (); var vocCtrl = new VocabularyController(); var vocs = vocCtrl.GetVocabularies(); foreach (var voc in vocs) { if (!voc.IsSystem) { terms.AddRange(voc.Terms); } } return(terms.OrderBy(t => t.Name)); }
public void VocabularyController_DeleteVocabulary_Calls_DataService_On_Valid_Arguments() { // Arrange var mockDataService = new Mock<IDataService>(); var vocabularyController = new VocabularyController(mockDataService.Object); Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary(); vocabulary.VocabularyId = Constants.VOCABULARY_ValidVocabularyId; // Act vocabularyController.DeleteVocabulary(vocabulary); // Assert mockDataService.Verify(ds => ds.DeleteVocabulary(vocabulary)); }
public static void RemoveUser(UserContext userContext, VocabularyContext vocabularyContext, ref User user) { try { VocabularyController.RemoveVocabulary(vocabularyContext, user); vocabularyContext.SaveChanges(); userContext.Users.Remove(user); userContext.SaveChanges(); user = null; } catch (Exception e) { Exceptions.Catching(e); } }
public HttpResponseMessage Exist(int vocabularyId, int termId, int parentId, string termName) { var exists = false; var controller = new TermController(); var vocabulary = new VocabularyController().GetVocabularies().FirstOrDefault(v => v.VocabularyId == vocabularyId); if (vocabulary != null && !string.IsNullOrEmpty(termName)) { var terms = controller.GetTermsByVocabulary(vocabularyId); exists = terms.Any(t => t.Name.Equals(termName.Trim(), StringComparison.InvariantCultureIgnoreCase) && t.TermId != termId && (parentId < 0 || t.ParentTermId == parentId)); } return(Request.CreateResponse(HttpStatusCode.OK, exists)); }
public void VocabularyController_AddVocabulary_Returns_ValidId_On_Valid_Vocabulary() { // Arrange var mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.AddVocabulary(It.IsAny<Vocabulary>(), It.IsAny<int>())).Returns(Constants.VOCABULARY_AddVocabularyId); var vocabularyController = new VocabularyController(mockDataService.Object); Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary(); // Act int vocabularyId = vocabularyController.AddVocabulary(vocabulary); // Assert Assert.AreEqual(Constants.VOCABULARY_AddVocabularyId, vocabularyId); }
public void SaveVocabulary(object sender, EventArgs e) { View.BindVocabulary(View.Model.Vocabulary, IsEditEnabled, IsDeleteEnabled, IsSuperUser); var result = Validator.ValidateObject(View.Model.Vocabulary); if (result.IsValid) { VocabularyController.UpdateVocabulary(View.Model.Vocabulary); Response.Redirect(Globals.NavigateURL(TabId)); } else { ShowMessage("VocabularyValidationError", ModuleMessage.ModuleMessageType.RedError); } }
public ActionResult DeleteWord(string key, string deletingData) { User valueSession = (User)Session["User"]; IsUserAuth(valueSession); var row = VocabularyController.FindRow(deletingData, Byte.Parse(key), _vocabularyContext); if (row != null) { VocabularyController.RemoveRow(_vocabularyContext, row); return(RedirectToAction("Index")); } return(View()); }
private void Update_Click(object sender, RoutedEventArgs e) { var rows = (List <VocabularyView>)TableView.ItemsSource; foreach (var row in rows) { Vocabulary updatedRow = new Vocabulary { Id = row.getID(), ForeignWord = row.ForeignWord, Transcription = row.Transcription, LocalWord = row.LocalWord, UserID = currentUser.Id }; VocabularyController.UpdateRow(_vocabularyContext, updatedRow); } }
public ActionResult AddWord(Vocabulary newWord) { User valueSession = (User)Session["User"]; IsUserAuth(valueSession); userID = valueSession.Id; newWord.UserID = userID; VocabularyController.AddRow(_vocabularyContext, newWord); if (Exceptions.IsError == 1) { Exceptions.IsError = 0; throw new Exception(Exceptions.ErrorMessage); } else { return(RedirectToAction("Index")); } }
private void TableView_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Delete) { MessageBoxResult result = MessageBox.Show("Are you sure?", "Deleting word", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { var deletedTemperyRow = (VocabularyView)TableView.SelectedItem; Vocabulary row = new Vocabulary { ForeignWord = deletedTemperyRow.ForeignWord, Transcription = deletedTemperyRow.Transcription, LocalWord = deletedTemperyRow.LocalWord, UserID = currentUser.Id }; row = VocabularyController.FindRow(row, _vocabularyContext); VocabularyController.RemoveRow(_vocabularyContext, row); LoadGrid(); } } }
public HttpResponseMessage Search(int vocabularyId, int termId, int parentId, string termName) { IList <SearchResult> results = new List <SearchResult>(); var controller = new TermController(); var vocabulary = new VocabularyController().GetVocabularies().FirstOrDefault(v => v.VocabularyId == vocabularyId); if (vocabulary != null && !string.IsNullOrEmpty(termName)) { var terms = controller.GetTermsByVocabulary(vocabularyId); var relatedTerms = terms.Where(t => t.Name.ToLowerInvariant().Contains(termName.Trim().ToLowerInvariant()) && t.TermId != termId && (parentId < 0 || t.ParentTermId == parentId)); foreach (Term term in relatedTerms) { results.Add(new SearchResult() { label = term.Name, value = term.Name }); } } return(Request.CreateResponse(HttpStatusCode.OK, results)); }
public TermsImpl(ITermController termController) { _termController = termController; _vocabularyController = new VocabularyController(); }
public void DeleteVocabulary(object sender, EventArgs e) { VocabularyController.DeleteVocabulary(View.Model.Vocabulary); Response.Redirect(Globals.NavigateURL(TabId)); }
public TermsImpl() { _termController = new TermController(); _vocabularyController = new VocabularyController(); }
public static void OpsMenu(User currentUser) { do { UsefulFunctions.PrepareForView(); string buff; byte chooseOps; for (int i = 0; i < _vocabularyMenu.Length; i++) { Console.WriteLine("{0}. {1}", i + 1, _vocabularyMenu[i]); } buff = Console.ReadLine(); if (!Byte.TryParse(buff, out chooseOps)) { continue; } if (chooseOps == 1) { Vocabulary row = createRow(currentUser); VocabularyController.AddRow(_vocabularyContext, row); Console.WriteLine("Row successfully added."); Console.ReadKey(); } else if (chooseOps == 2) { Console.WriteLine("Foreign Word\tTranscription\tLocal word"); var userVoc = _vocabularyContext.Vocabularies.ToList(); foreach (var row in userVoc) { if (row.UserID == currentUser.Id) { if (row.Transcription.Length == 0) { Console.WriteLine("{0}\t\t{1}\t\t{2}", row.ForeignWord, "-", row.LocalWord); } else { Console.WriteLine("{0}\t\t{1}\t\t{2}", row.ForeignWord, row.Transcription, row.LocalWord); } } } Console.ReadKey(); } else if (chooseOps == 3) { string key; Vocabulary editRow; string text = "Choose the key for find word: \n" + "1. Foreign word;\n2. Transcription;\n3. Local word"; byte editChoose = UsefulFunctions.Choose(text, 1, 3); key = UsefulFunctions.GetKey(); try { editRow = VocabularyController.FindRow(key, editChoose, _vocabularyContext); Console.WriteLine("Row successfully found"); string change; for (int i = 0; i < 3; i++) { if (i == 0) { Console.WriteLine("Edit foreign word. Current is {0}", editRow.ForeignWord); } else if (i == 1) { Console.WriteLine("Edit transcription. Current is {0}", editRow.Transcription); } else { Console.WriteLine("Edit local word. Current is {0}", editRow.LocalWord); } change = Console.ReadLine(); if (change.Length != 0 && i == 0) { editRow.ForeignWord = change; } else if (change.Length != 0 && i == 1) { editRow.Transcription = change; } else if (change.Length != 0 && i == 2) { editRow.LocalWord = change; } } VocabularyController.UpdateRow(_vocabularyContext, editRow); } catch (Exception e) { Exceptions.Catching(e); } if (Exceptions.IsError == EMPTY) { Console.WriteLine("Row successfully updated"); } } else if (chooseOps == 4) { string text = "Choose the key for delete word: \n" + "1. Foreign word;\n2. Transcription;\n3. Local word"; byte deleteChoose = UsefulFunctions.Choose(text, 1, 3); string key = UsefulFunctions.GetKey(); try { Vocabulary foundRow = VocabularyController.FindRow(key, deleteChoose, _vocabularyContext); VocabularyController.RemoveRow(_vocabularyContext, foundRow); } catch (Exception e) { Exceptions.Catching(e); } if (Exceptions.IsError == EMPTY) { Console.WriteLine("Row successfully deleted"); } } else if (chooseOps == 5) { //bool sure = false; Console.WriteLine("Are you sure to delete the vocabulary?\n y - yes, n - no"); var chooseDelete = Console.ReadLine(); if (chooseDelete.Length == 1 && chooseDelete == "n") { VocabularyController.RemoveVocabulary(_vocabularyContext, currentUser); } } else if (chooseOps == 6) { GameMenu(currentUser); } else if (chooseOps == 7) { currentUser = SettingMenu(currentUser); if (currentUser == null) { break; } } else if (chooseOps == 8) { break; } } while (true); }