예제 #1
0
        /// <summary>
        /// возвращает рандомный перевод из MyWord
        /// </summary>
        /// <param name="mw"></param>
        /// <returns></returns>
        public static string GetTranslate(MyWord mw)
        {
            int count             = mw.MyTranslates.Count;
            List <MyTranslate> lt = mw.MyTranslates.ToList();
            MyTranslate        tr = lt[App.random.Next(count)];

            return(tr.Translate);
        }
예제 #2
0
 public static int AddNewTranslate(string str, int wordid)
 {
     using (var context = new ApplicationContext())
     {
         try
         {
             var tr = new MyTranslate()
             {
                 Translate = str, WordId = wordid
             };
             context.MyTranslates.Add(tr);
             context.SaveChanges();
             return(tr.TranslateId);
         }
         catch (Exception e)
         {
             MessageBox.Show(e.Message + " " + MethodBase.GetCurrentMethod().DeclaringType.FullName, "Внимание!", MessageBoxButton.OK, MessageBoxImage.Error);
             return(0);
         }
     }
 }