public static Vocabulary FindRow(string key, byte foundChoose, VocabularyContext vocabularyContext) { Vocabulary foundRow = null; foreach (var vocabulary in vocabularyContext.Vocabularies.ToList()) { switch (foundChoose) { case 1: if (vocabulary.ForeignWord == key) { foundRow = vocabulary; } break; case 2: if (vocabulary.Transcription == key) { foundRow = vocabulary; } break; case 3: if (vocabulary.LocalWord == key) { foundRow = vocabulary; } break; } } return(foundRow); }
protected void fvMessage_DataBound(object sender, EventArgs e) { if (fvMessage.DataItem != null) { Message message = (Message)fvMessage.DataItem; VocabularyContext context = new VocabularyContext(); if (message.SenderID != message.RecipientID) { if (currentUser.ID == message.SenderID) { Label lblSender = (Label)fvMessage.FindControl("lblSender"); lblSender.Text = GetLocalResourceObject("from").ToString() + " " + currentUser.Name; Label lblRecipient = (Label)fvMessage.FindControl("lblRecipient"); lblRecipient.Text = GetLocalResourceObject("to").ToString() + " " + context.Users.SingleOrDefault(u => u.ID == message.RecipientID).Name; } if (currentUser.ID == message.RecipientID) { Label lblRecipient = (Label)fvMessage.FindControl("lblRecipient"); lblRecipient.Text = GetLocalResourceObject("to").ToString() + " " + currentUser.Name; Label lblSender = (Label)fvMessage.FindControl("lblSender"); lblSender.Text = GetLocalResourceObject("from").ToString() + " " + context.Users.SingleOrDefault(u => u.ID == message.SenderID).Name; } } } }
public SettingGame(VocabularyContext vocabulary) { TYPE_GAME = new string[COUNT_GAMES] { "Write translation", "One from 4th", "Matching translation" }; isIncludeToTable = true; var listCount = vocabulary.Vocabularies.ToList().Count; if (listCount < FIRST_LEVEL) { countPoints = 2; } else if (listCount < SECOND_LEVEL) { countPoints = 4; } else if (listCount < THIRD_LEVEL) { countPoints = 6; } else if (listCount < FOURTH_LEVEL) { countPoints = 8; } else { countPoints = 10; } }
protected void PrepareAnswerMessage() { if (Request.QueryString["p"] != null) { int messageID; if (int.TryParse(Request.QueryString["p"].ToString(), out messageID)) { VocabularyContext context = new VocabularyContext(); Message message = context.Messages.SingleOrDefault(m => m.ID == messageID); if (message != null) { if (currentUser.Role == "admin") { if (currentUser.ID != message.RecipientID) { //current user is the sender (this is from message object) and send message to the recipient again tbRecipient.Text = context.Users.SingleOrDefault(u => u.ID == message.RecipientID).Name; } else { //current user is the recipient (this is from message object) and send back message to the sender tbRecipient.Text = context.Users.SingleOrDefault(u => u.ID == message.SenderID).Name; } } tbMessageText.Text = System.Environment.NewLine + message.Content; tbMessageText.Focus(); } } } }
public Setting(User user, UserContext context, VocabularyContext vocabularyContext) { InitializeComponent(); currentUser = user; _userContext = context; _vocabularyContext = vocabularyContext; ShowUserData(); }
public Table(User sessionUser, UserContext userContext) { InitializeComponent(); currentUser = sessionUser; _vocabularyContext = new VocabularyContext(); _userContext = userContext; LoadGrid(); }
protected void Page_Load(object sender, EventArgs e) { VocabularyContext context = new VocabularyContext(); int currentLanguageID = context.Languages.SingleOrDefault(l => l.Name == CultureInfo.CurrentUICulture.Name).ID; lvCategories.DataSource = context.Categories.Where(c => c.LanguageID == currentLanguageID).ToList(); lvCategories.DataBind(); }
string LoadUsers(string partOfName) { VocabularyContext ctx = new VocabularyContext(); List <User> userList = ctx.Users.Where(u => u.Name.StartsWith(partOfName) == true).ToList(); JavaScriptSerializer js = new JavaScriptSerializer(); return(js.Serialize(userList)); }
string LoadWords(string partOfName) { VocabularyContext ctx = new VocabularyContext(); List <Word> wordList = ctx.Word.Where(w => w.Name.StartsWith(partOfName) == true).ToList(); JavaScriptSerializer js = new JavaScriptSerializer(); return(js.Serialize(wordList)); }
protected void ibtnDeleteWord_Command(object sender, CommandEventArgs e) { VocabularyContext context = new VocabularyContext(); Word word = context.Word.SingleOrDefault(w => w.ID == (int)e.CommandArgument); if (word != null) { context.Word.Remove(word); context.SaveChanges(); } }
protected void btnSearchUsers_Click(object sender, EventArgs e) { VocabularyContext context = new VocabularyContext(); List <User> userList = context.Users.ToList(); lvUserList.DataSource = userList.FindAll(u => u.Name.Contains(tbUserName.Text)); RequestedUserName = tbUserName.Text; lvUserList.DataBind(); divContainerBorder.Visible = true; tbUserName.Text = string.Empty; }
protected void btnAddWord_Click(object sender, EventArgs e) { Page.Validate("AddWord"); if (Page.IsValid) { try { Word word = new Word(); //fill word data on english word.Name = tbWordEn.Text; word.Description = ftbMeaningEn.Text; word.LanguageID = Helpers.EnLangID; int resultID; if (int.TryParse(ddlCategoriesEn.SelectedValue, out resultID)) { word.CategoryID = resultID; } VocabularyContext context = new VocabularyContext(); context.Word.Add(word); context.SaveChanges(); //////////////////////////////////// //fill word data on bulgarian word = new Word(); word.Name = tbWordBg.Text; word.Description = ftbMeaningBg.Text; word.LanguageID = Helpers.BgLangID; resultID = 0; if (int.TryParse(ddlCategoriesBg.SelectedValue, out resultID)) { word.CategoryID = resultID; } context.Word.Add(word); context.SaveChanges(); tbWordEn.Text = string.Empty; ftbMeaningEn.Text = string.Empty; tbWordBg.Text = string.Empty; ftbMeaningBg.Text = string.Empty; hfResult.Value = "1"; pnlDialog.Visible = true; litResult.Text = GetLocalResourceObject("Success").ToString(); } catch (Exception ex) { string s = ex.Message; hfResult.Value = "0"; pnlDialog.Visible = true; litResult.Text = GetLocalResourceObject("Fail").ToString(); } } }
private ValueSetRepository CreateSUT() { var dbOptions = new DbContextOptionsBuilder <VocabularyContext>() .UseInMemoryDatabase(databaseName: "vocabulary1") .Options; var context = new VocabularyContext(dbOptions); context.EnsureSeedDataForContext(); return(new ValueSetRepository(context)); }
// The id parameter should match the DataKeyNames value set on the control // or be decorated with a value provider attribute, e.g. [QueryString]int id public WebVocabulary2.Models.Word fvWord_GetItem([QueryString("pid")] int id) { VocabularyContext context = new VocabularyContext(); int languageID = context.Languages.SingleOrDefault(l => l.Name == currentLanguage).ID; Word word = context.Word.SingleOrDefault(w => w.ID == id && w.LanguageID == languageID); string resultContent = PrepareWordMeaning(word); word.Description = Server.HtmlDecode(resultContent); Page.Title = word.Name; return(word); }
public static void UpdateRow(VocabularyContext vocabularyContext, Vocabulary newRow) { try { vocabularyContext.Vocabularies.AddOrUpdate(newRow); vocabularyContext.SaveChanges(); } catch (Exception e) { Exceptions.Catching(e); } }
public static void RemoveRow(VocabularyContext vocabularyContext, Vocabulary row) { try { vocabularyContext.Vocabularies.Remove(row); vocabularyContext.SaveChanges(); } catch (Exception e) { Exceptions.Catching(e); } }
protected void lvCateories_ItemDataBound(object sender, ListViewItemEventArgs e) { Category category = (e.Item.DataItem as Category); if (category != null) { VocabularyContext context = new VocabularyContext(); int wordCount = context.Word.Count(w => w.CategoryID == category.ID); Label lblWordCountInCategory = e.Item.FindControl("lblWordCountInCategory") as Label; lblWordCountInCategory.Text = wordCount.ToString(); } }
protected void lvReceivedMessages_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.DataItem != null) { VocabularyContext context = new VocabularyContext(); Message message = (Message)e.Item.DataItem; Label lblSender = e.Item.FindControl("lblSender") as Label; if (lblSender != null) { lblSender.Text = context.Users.SingleOrDefault(u => u.ID == message.SenderID).Name; } } }
public static Vocabulary FindRow(Vocabulary row, VocabularyContext vocabularyContext) { foreach (var vocabulary in vocabularyContext.Vocabularies.ToList()) { if (vocabulary.ForeignWord == row.ForeignWord && vocabulary.Transcription == row.Transcription && vocabulary.LocalWord == row.LocalWord && vocabulary.UserID == row.UserID) { return(vocabulary); } } return(null); }
private int GetRecipientID(string recipientName)// call when send { VocabularyContext context = new VocabularyContext(); User user = context.Users.SingleOrDefault(u => u.Name == recipientName); if (user != null) { return(user.ID); } else { return(0); } }
public WriteTransWin(VocabularyContext vocabularyContext, User user) { InitializeComponent(); currentUser = user; _vocabularyContext = vocabularyContext; words = UserVocabulary(_vocabularyContext.Vocabularies.ToList()); settingGame = new SettingGame(_vocabularyContext); gameController = new GameController(); tm = new TimerCallback(gameController.TimerOver); currentPoints = 0; StartGame(); }
protected void cvExistingCategory_ServerValidate(object source, ServerValidateEventArgs args) { VocabularyContext context = new VocabularyContext(); Category category = context.Categories.SingleOrDefault(c => c.Name == args.Value); if (category == null) { args.IsValid = true; } else { args.IsValid = false; } }
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); } }
protected void lvResults_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.DataItem != null) { VocabularyContext context = new VocabularyContext(); int languageID = Helpers.GetCurrentLanguageID(); Word word = (Word)e.Item.DataItem; Label lblCategory = e.Item.FindControl("lblCategory") as Label; if (lblCategory != null) { lblCategory.Text = context.Categories.SingleOrDefault(c => c.ID == word.CategoryID).Name; } } }
public OneFromTheFouthWin(VocabularyContext vocabularyContext, User user) { InitializeComponent(); currentUser = user; _vocabularyContext = vocabularyContext; words = UserVocabulary(_vocabularyContext.Vocabularies.ToList()); //settingGame = new SettingGame(_vocabularyContext); gameController = new GameController(); tm = new TimerCallback(gameController.TimerOver); currentPoints = 0; buttons = InittializeButton(); settingGame = new SettingGame(_vocabularyContext); StartGame(); }
protected void ibtnDeleteUser_Command(object sender, CommandEventArgs e) { VocabularyContext context = new VocabularyContext(); int userID = Convert.ToInt32(e.CommandArgument); User user = context.Users.SingleOrDefault(u => u.ID == userID); if (user != null) { context.Users.Remove(user); context.SaveChanges(); List <User> userList = context.Users.ToList(); lvUserList.DataSource = userList.FindAll(u => u.Name.Contains(RequestedUserName)); lvUserList.DataBind(); } }
protected void btnSend_Click(object sender, EventArgs e) { if (Session["currentUser"] != null) { VocabularyContext context = new VocabularyContext(); User currentUser = (User)Session["currentUser"]; Message newMessage = new Message(); newMessage.MessageDate = DateTime.Now; newMessage.Content = tbMessageText.Text; newMessage.UserDeletedThis = 0; newMessage.SenderID = currentUser.ID; newMessage.RecipientID = GetRecipientID(tbRecipient.Text); context.Messages.Add(newMessage); context.SaveChanges(); } }
protected void btnLogin_Click(object sender, EventArgs e) { VocabularyContext context = new VocabularyContext(); User user = context.Users.SingleOrDefault(u => u.Name == tbUserName.Text && u.Password == tbPassword.Text); if (user != null) { Session["currentUser"] = user; Response.Redirect("~/Default.aspx"); } else { lblFail.Text = GetLocalResourceObject("fail").ToString(); lblFail.ForeColor = System.Drawing.Color.Red; lblFail.Visible = true; } }
public static void RemoveVocabulary(VocabularyContext vocabularyContext, User user) { try { var rows = vocabularyContext.Vocabularies.ToList(); foreach (var row in rows) { if (row.UserID == user.Id) { vocabularyContext.Vocabularies.Remove(row); } } } catch (Exception e) { Exceptions.Catching(e); } }
private string PrepareWordMeaning(Word word) { VocabularyContext context = new VocabularyContext(); List <Word> wordList = context.Word.Where(w => w.CategoryID == word.CategoryID).ToList(); string wordMeaning = word.Description; if (wordList.Count > 0) { for (int i = 0; i < wordList.Count; i++) { wordMeaning = Regex.Replace(wordMeaning, wordList[i].Name, new MatchEvaluator(delegate(Match match){ return(GetRightReplacementString(match, wordList[i].ID)); }), RegexOptions.IgnoreCase); } } return(wordMeaning); }