public void AddTOBookMarks(int OrderId) { User us = Initialize().Result; if (us == null) { return; } List <BookMarks> lb = db.BookMarks.Where(b => b.UserId == us.Id && b.OrderId == OrderId).ToList(); if (lb.Count() == 0) { //db.Users.Include(i => i.BookMarks).First(s => s.Id == id); BookMarks b = new BookMarks { OrderId = OrderId, UserId = us.Id }; db.BookMarks.Add(b); } else { db.BookMarks.Remove(lb[0]); } db.SaveChanges(); }
/// <summary> /// Chargé le fichier dans l'objet /// </summary> /// <returns>Retoune vrai si le fichier est bien charger</returns> private bool Load() { //Vide la collection _DTEList.Clear(); //ouverture du fichier if (!File.Exists(_FileName)) { FileStream fs = File.Create(_FileName); fs.Close(); } StreamReader TBLFile; try { TBLFile = new StreamReader(_FileName, Encoding.ASCII); } catch { return(false); } if (TBLFile.BaseStream.CanRead) { //lecture du fichier jusqua la fin et séparation par ligne char[] sepEndLine = { '\n' }; //Fin de ligne char[] sepEqual = { '=' }; //Fin de ligne //build strings line StringBuilder textFromFile = new StringBuilder(TBLFile.ReadToEnd()); textFromFile.Insert(textFromFile.Length, '\r'); textFromFile.Insert(textFromFile.Length, '\n'); string[] lines = textFromFile.ToString().Split(sepEndLine); //remplir la collection de DTE : this._DTE foreach (string line in lines) { string[] info = line.Split(sepEqual); //ajout a la collection (ne prend pas encore en charge le Japonais) DTE dte = new DTE(); try { switch (info[0].Length) { case 2: if (info[1].Length == 2) { dte = new DTE(info[0], info[1].Substring(0, info[1].Length - 1), DTEType.ASCII); } else { dte = new DTE(info[0], info[1].Substring(0, info[1].Length - 1), DTEType.DualTitleEncoding); } break; case 4: // >2 dte = new DTE(info[0], info[1].Substring(0, info[1].Length - 1), DTEType.MultipleTitleEncoding); break; default: continue; } } catch (IndexOutOfRangeException) { switch (info[0].Substring(0, 1)) { case @"/": dte = new DTE(info[0].Substring(0, info[0].Length - 1), "", DTEType.EndBlock); break; case @"*": dte = new DTE(info[0].Substring(0, info[0].Length - 1), "", DTEType.EndLine); break; //case @"\": default: continue; } } catch (ArgumentOutOfRangeException) { //Du a une entre qui a 2 = de suite... EX: XX== dte = new DTE(info[0], "=", DTEType.DualTitleEncoding); } _DTEList.Add(dte); } //Load bookmark BookMarks.Clear(); BookMark fav = null; string[] lineSplited; foreach (string line in lines) { try { if (line.Substring(0, 1) == "(") { fav = new BookMark(); lineSplited = line.Split(new char[] { ')' }); fav.Description = lineSplited[1].Substring(0, lineSplited[1].Length - 1); lineSplited = line.Split(new char[] { 'h' }); fav.BytePositionInFile = ByteConverters.HexLiteralToLong(lineSplited[0].Substring(1, lineSplited[0].Length - 1)).position; fav.Marker = ScrollMarker.TBLBookmark; BookMarks.Add(fav); } } catch { } //Nothing to add if error } TBLFile.Close(); return(true); } else { return(false); } }