/// <summary> /// Deletes a composite symbol and it's rows in /// CompositeOf table. Takes a CompositeSymbols /// row as inn parameter /// </summary> /// <param name="compSymbol"></param> /// <returns>true or false depending on success</returns> internal bool DeleteCompositeSymbolByRow(CompositeSymbols compSymbol) { if (compSymbol == null) { return false; } else { using (var db = new BlissBaseContext(testing)) { try { db.CompositeSymbols.Attach(compSymbol); db.Entry(compSymbol).State = EntityState.Deleted; db.SaveChanges(); return true; } catch (Exception e) { Debug.WriteLine("Exception when removing symbol: " + compSymbol.CompID); Debug.WriteLine(e.StackTrace); return false; } } } }
/// <summary> /// Method accepts a Row from CompositeSymbols table, and a /// list of Symbol Models. The ComposedOf table is updated /// to keep track of the relation between the composit symbol /// and it's base symbols /// </summary> /// <param name="compositeRow"></param> /// <param name="composedOf"></param> /// <returns>true or false depending on success</returns> internal bool SetCompositeOfRow(CompositeSymbols compositeRow, List<Symbol> composedOf) { CompositeSymbols inn = compositeRow; return SetCompositeOfSymbol(new CompositeSymbol() { compId = inn.CompID, compName = inn.CompName, compJpeg = inn.CompJPEG }, composedOf); }
/// <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; } }
/// <summary> /// Deletes all rows in CompositesOf table by CompID /// "Same as DeleteByCompositeSymbol but takes a row from /// CompositeSymbols table instead of a Model of /// CompositeSymbol /// </summary> /// <param name="composit"></param> /// <returns>true or false depending on success</returns> internal bool DeleteByCompositeRow(CompositeSymbols composit) { return DeleteByCompositeSymbol(new CompositeSymbol() { compId = composit.CompID, compName = composit.CompName, compJpeg = composit.CompJPEG }); }