示例#1
0
 public void EmptyModel_ConstructorDefault()
 {
     JapaneseWord jpw = new JapaneseWord();
     Assert.AreEqual(0,jpw.EntryID,"Entry ID" +NOTNULLOREMPTY);
     Assert.AreEqual("",jpw.Hiragana, "Hiragana "+NOTNULLOREMPTY );
     Assert.AreEqual("", jpw.Kanji, "Kanji "+NOTNULLOREMPTY);
     Assert.AreEqual("", jpw.Romaji, "Romaji "+NOTNULLOREMPTY);
     Assert.AreEqual("", jpw.AdditionalText, "Additional Text "+ NOTNULLOREMPTY);
     Assert.AreEqual("",jpw.MotherTongueTranslation,"Mother Tongue Translation "+ NOTNULLOREMPTY);
     Assert.AreEqual("",jpw.MotherTongueTranslationLabel,"Mother Tongue Translation Label"+NOTNULLOREMPTY);
 }
示例#2
0
        /// <summary>
        /// Add 1 entry to the table
        /// </summary>
        public void AddEntry(JapaneseWord model)
        {
            try
            {
                JapaneseWordEntry jpwe = new JapaneseWordEntry
                {
                    Hiragana = model.Hiragana,
                    Kanji = model.Kanji,
                    Romaji = model.Romaji,
                    AdditionalText = model.AdditionalText,
                    MotherTongueTranslation = model.MotherTongueTranslation,
                    MotherTongueTranslationLabel = model.MotherTongueTranslationLabel
                };
                jpwe.EntryId = null; // since this is an insert, id's are auto incremented on the database side
                context.JapaneseWordEntries.InsertOnSubmit(jpwe);

                context.SubmitChanges();
            }
            catch (Exception ex)
            {
                appLog.WriteEntry(ex.Message);
            }
        }
示例#3
0
 public void EditModel_SecondConstructor()
 {
     JapaneseWord jpw = new JapaneseWord();
     JapaneseWordEntry jpwe = new JapaneseWordEntry();
 }
示例#4
0
        /// <summary>
        /// Edit entry
        /// Retrieve model from database, overwrite the properties if the query if found
        /// </summary>
        public void EditEntry(JapaneseWord model)
        {
            try
            {
                var query = (from entry in context.JapaneseWordEntries
                            where entry.EntryId == model.EntryID
                            select entry).FirstOrDefault();
                if (query != null)
                {

                    query.Romaji = model.Romaji;
                    query.Hiragana = model.Hiragana;
                    query.Kanji = model.Kanji;
                    query.AdditionalText = model.AdditionalText;
                    query.MotherTongueTranslation = model.MotherTongueTranslation;
                    query.MotherTongueTranslationLabel = model.MotherTongueTranslationLabel;

                    context.SubmitChanges();
                }
                else
                {
                    throw new NullReferenceException("Entry model is null");
                }

            }
            catch (Exception ex)
            {
                appLog.WriteEntry(ex.Message);
            }
        }
示例#5
0
        /// <summary>
        /// Get one entry from the table
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JapaneseWord GetEntry(int id)
        {
            JapaneseWord emptyModel = new JapaneseWord ();

            try
            {

                var query = (from entry in context.JapaneseWordEntries
                            where entry.EntryId == id
                            select entry).FirstOrDefault();
                JapaneseWord model = new JapaneseWord(query);

                return model;
            }
            catch (Exception ex)
            {
                appLog.WriteEntry(ex.Message);
            }

            return emptyModel;
        }