/// <summary> /// Deletes exacly one Symbol by id in Symbols table, /// deletes all the entries of the symbol in CompositesOf table /// </summary> /// <param name="id"></param> /// <returns>true false depending on success</returns> public bool DeleteExact(int id) { using (var db = new BlissBaseContext(testing)) { Symbols sym = db.Symbols.Find(id); try { // Deletes the relations where the symbol is a component of // a composite symbol var compOf = new CompositeOfDAL(); compOf.DeleteBySymbolID(id); // Sets the symbol as a standard type (Deletes it from // SymbolTypes table) var type = new SymbolTypeDAL(); type.SetStandardForSymID(id); // Deletes the symbol from Symbols table db.Symbols.Remove(sym); db.SaveChanges(); } catch (Exception e) { Debug.WriteLine("Exception when remowing symbol: " + id); Debug.WriteLine(e.StackTrace); return false; } } return true; }
/// <summary> /// Takes a list of Symbol Models and a name. /// Creates a CompositeSymbol by merging components JPEG's /// and adding name. Returns null if merging jpegs failed, or /// if identical CompositeSymbol exists. The returned CompositeSymbol /// should be passed to CompositeSymbolDAL.Insert if the sybol is intended /// to be saved in the database table /// </summary> /// <param name="CompositeName"></param> /// <param name="components"></param> /// <returns>BlissBase.Model.CompositeSymbol or null</returns> public CompositeSymbol CreateCompositeByComponents(String compositeName, List<Symbol> components) { List<Symbol> sortedList = components.OrderBy(s => s.symId).ToList(); CompositeSymbol nameExists = GetExactCompositeSymbolByName(compositeName); if (nameExists != null) { CompositeOfDAL composites = new CompositeOfDAL(); List<Symbol> hasComponents = composites.GetComponentsOf(nameExists); if (Enumerable.SequenceEqual(sortedList, hasComponents)) return null; } byte[] newCompJpeg = null; newCompJpeg = CombineJpegFromComponents(sortedList); CompositeSymbol newCompSymbol = null; if (newCompJpeg != null) { newCompSymbol = new CompositeSymbol() { compName = compositeName, compJpeg = newCompJpeg }; } return newCompSymbol; }
/// <summary> /// Deletes a composite symbol and it's rows in /// CompositeOf table. Takes a CompositeSymbol /// model as inn parameter /// </summary> /// <param name="compModel"></param> /// <returns>true or false depending on success</returns> public bool DeleteCompositeSymbol(CompositeSymbol compModel) { if (compModel == null) return false; CompositeOfDAL compOf = new CompositeOfDAL(); var ok = compOf.DeleteByCompositeSymbol(compModel); if (ok) { CompositeSymbols compSymbol = GetExactCompositeRowByID(compModel.compId); return DeleteCompositeSymbolByRow(compSymbol); } return false; }
/// <summary> /// Takes a CompositeSymbol Model and a list of Symbol Models. /// Inserts composite symbol and links it to the list of Symbols /// using CompositesOf /// </summary> /// <param name="innCompSymbol"></param> /// <param name="components"></param> /// <returns>Id of new BlissBase.DAL.CompositeSymbols as int, or -1 if insert failed</returns> public int Insert(CompositeSymbol innCompSymbol, List<Symbol> components) { var newCompSymbol = new CompositeSymbols() { CompName = innCompSymbol.compName, CompJPEG = innCompSymbol.compJpeg }; using (var db = new BlissBaseContext(testing)) { try { db.CompositeSymbols.Add(newCompSymbol); db.SaveChanges(); CompositeOfDAL compOf = new CompositeOfDAL(); compOf.SetCompositeOfRow(newCompSymbol, components); } catch (Exception e) { Debug.WriteLine("Error Inserting Composite symbol: " + innCompSymbol.compId); Debug.WriteLine(e.StackTrace); return -1; } return newCompSymbol.CompID; } }
public bool SetCompositeOfSymbol(CompositeSymbol compositeModel, List<Symbol> composedOf) { var CompositeOfDAL = new CompositeOfDAL(testing); return CompositeOfDAL.SetCompositeOfSymbol(compositeModel, composedOf); }
public List<Symbol> GetComponentsOf(CompositeSymbol innCompSymbol) { var CompositeOfDAL = new CompositeOfDAL(testing); return CompositeOfDAL.GetComponentsOf(innCompSymbol); }
public List<CompositeOf> getAllRelations() { var CompositeOfDAL = new CompositeOfDAL(testing); return CompositeOfDAL.getAllRelations(); }
public bool DeleteByCompositeSymbol(CompositeSymbol composit) { var CompositeOfDAL = new CompositeOfDAL(testing); return CompositeOfDAL.DeleteByCompositeSymbol(composit); }