Пример #1
0
        /// <summary>
        /// Inserts a tree to the database
        /// </summary>
        /// <param name="newTree">New tree object</param>
        /// <returns>True if insert is successfull</returns>
        public int InsertTree(Tree newTree)
        {
            if (newTree == null)
            {
                return 0;
            }

            int newTreeId = 0;
            try
            {
                newTree.TreeId = 0;//ensures that the treeid is new
                newTree.CreationDate = DateTime.UtcNow;
                using (var context = new PlantATreeEntities())
                {
                    context.Trees.AddObject(newTree);
                    context.SaveChanges();

                    newTreeId = newTree.TreeId;
                }
                return newTreeId;
            }
            catch(Exception e)
            {
                return 0;
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Trees EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTrees(Tree tree)
 {
     base.AddObject("Trees", tree);
 }
 /// <summary>
 /// Create a new Tree object.
 /// </summary>
 /// <param name="treeId">Initial value of the TreeId property.</param>
 public static Tree CreateTree(global::System.Int32 treeId)
 {
     Tree tree = new Tree();
     tree.TreeId = treeId;
     return tree;
 }