public static bool AddText(Infor tx) { using (var _context = new DBMindMapEntities()) { try { _context.Infors.AddOrUpdate(tx); _context.SaveChanges(); return(true); } catch (DbEntityValidationException e) { StringBuilder sb = new StringBuilder(); foreach (var eve in e.EntityValidationErrors) { sb.AppendLine(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State)); foreach (var ve in eve.ValidationErrors) { sb.AppendLine(string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage)); } } throw new DbEntityValidationException(sb.ToString(), e); } } }
public static bool AddShape(Shape sp) { using (var _context = new DBMindMapEntities()) { try { _context.Shapes.AddOrUpdate(sp); _context.SaveChanges(); return(true); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } } }
public static bool AddProject(ProjectShape project) { using (var _context = new DBMindMapEntities()) { try { //MessageBox.Show("Successful!!"); _context.ProjectShapes.AddOrUpdate(project); _context.SaveChanges(); return(true); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } } }
public static bool DeleteProject(int id) { using (var _context = new DBMindMapEntities()) { try { var lstidShape = (from t in _context.Shapes where t.IDPro == id select t.ID).ToList(); foreach (var x in lstidShape) { var infor = (from z in _context.Infors where z.ID == x select z).SingleOrDefault(); if (infor != null) { _context.Infors.Remove(infor); } } foreach (var x in lstidShape) { var sh = (from s in _context.Shapes where s.ID == x select s).SingleOrDefault(); _context.Shapes.Remove(sh); } var pr = (from q in _context.ProjectShapes where q.IDPro == id select q).SingleOrDefault(); _context.ProjectShapes.Remove(pr); _context.SaveChanges(); return(false); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } } }