private void LoadListHSK() { string resourceName = "DomainHSK.DataFiles.Levels.NewHSKLevel" + Level.ToString() + ".txt"; Assembly currentAssembly = Assembly.GetExecutingAssembly(); // Get all embedded resources string[] arrResources = currentAssembly.GetManifestResourceNames(); Lines = ReadLines(() => Assembly.GetExecutingAssembly() .GetManifestResourceStream(resourceName), Encoding.Unicode) .ToList(); foreach (string line in Lines) { try { if (line[0] != '#') { Word_HSK w = new Word_HSK(line); w.Level = Level; Words.Add(w); string check = w.Pinyin; } } catch (Exception ex) { string something = ex.Message; } } }
public void SaveWord(Word_HSK word) { //CREATE if (word.Id == 0) { context.Words.Add(word); } else { //TODO Pag 290 Word_HSK dbEntry = context.Words.Find(word.Id); if (dbEntry != null) { //UPDATE dbEntry.Character = word.Character; dbEntry.Description = word.Description; dbEntry.TraditionalCharacter = word.TraditionalCharacter; dbEntry.NumberPinyin = word.NumberPinyin; dbEntry.Level = word.Level; dbEntry.ImageData = word.ImageData; dbEntry.ImageMimeType = word.ImageMimeType; } } context.SaveChanges(); }
//http://jesseliberty.com/2017/07/06/learning-xamarin-forms-part-2-mvvm/ public WordView() { InitializeComponent(); word = new Word_HSK(); word.Character = "好"; viewModel = new WordViewModel(word); BindingContext = viewModel; }
public FileContentResult GetImage(int Id) { Word_HSK phrase = wordRepository.Words.FirstOrDefault(p => p.Id == Id); if (phrase != null) { FileContentResult fileContentResult = File(phrase.ImageData, phrase.ImageMimeType); return(fileContentResult); } else { return(null); } }
public ActionResult Edit(Word_HSK word, HttpPostedFileBase Image = null) { if (ModelState.IsValid) { if (Image != null) { word.ImageMimeType = Image.ContentType; word.ImageData = new byte[Image.ContentLength]; Image.InputStream.Read(word.ImageData, 0, Image.ContentLength); } wordRepository.SaveWord(word); TempData["message"] = string.Format("{0} has been saved", word.Character); return(RedirectToAction("Index")); } else { return(View(word)); } }
public ViewResult Edit(int Id) { Word_HSK word = wordRepository.Words.FirstOrDefault(p => p.Id == Id); return(View(word)); }
public WordViewModel(Word_HSK word) { Character = word.Character; }