Inheritance: System.Data.Objects.DataClasses.EntityObject
コード例 #1
0
ファイル: DataManager.cs プロジェクト: sagioto/forum
        public bool AddPost(Post post, string subforum)
        {
            //Getting last id:
            IEnumerable<int> postKeysList = (from m in ForumContext.PostKeyEntities
                                             select m.PostKeyId);
            int lastId = 0;
            if (postKeysList.Count() != 0)
            {
                lastId = postKeysList.Max();
            }
            currentPostKeyId = lastId + 1;

            PostKeyEntity pke = new PostKeyEntity();
            pke.PostKeyId = currentPostKeyId;
            pke.Username = post.Key.Username;
            pke.Time = post.Key.Time;

            PostEntity pe = new PostEntity();
            pe.PostKeyId = currentPostKeyId;
            pe.ParentPostKeyId = -1;
            pe.Title = post.Title;
            pe.Body = post.Body;
            pe.SubforumName = subforum; //TODO - Why do we need 'subforum'?
            try
            {
                ForumContext.AddToPostKeyEntities(pke);
                ForumContext.AddToPostEntities(pe);
                ForumContext.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                //TODO
                throw;
            }
        }
コード例 #2
0
ファイル: ForumModel.Designer.cs プロジェクト: sagioto/forum
 /// <summary>
 /// Create a new PostKeyEntity object.
 /// </summary>
 /// <param name="postKeyId">Initial value of the PostKeyId property.</param>
 /// <param name="username">Initial value of the Username property.</param>
 /// <param name="time">Initial value of the Time property.</param>
 public static PostKeyEntity CreatePostKeyEntity(global::System.Int32 postKeyId, global::System.String username, global::System.DateTime time)
 {
     PostKeyEntity postKeyEntity = new PostKeyEntity();
     postKeyEntity.PostKeyId = postKeyId;
     postKeyEntity.Username = username;
     postKeyEntity.Time = time;
     return postKeyEntity;
 }
コード例 #3
0
ファイル: DataManager.cs プロジェクト: sagioto/forum
        public bool AddReply(Post reply, Postkey postKey)
        {
            try
            {
                // Find parent postkey:
                IEnumerable<PostKeyEntity> postkeyQuery = GetPostKeyEntity(postKey);
                IEnumerable<PostEntity> postQuery = GetPostEntity(postKey);

                //Getting last id:
                IEnumerable<int> postKeysList = (from m in ForumContext.PostKeyEntities
                                                 select m.PostKeyId);
                int lastId = 0;
                if (postKeysList.Count() != 0)
                {
                    lastId = postKeysList.Max();
                }
                currentPostKeyId = lastId + 1;

                PostKeyEntity pke = new PostKeyEntity();
                pke.PostKeyId = currentPostKeyId;
                pke.Username = reply.Key.Username;
                pke.Time = reply.Key.Time;
                ForumContext.AddToPostKeyEntities(pke);
                PostEntity pe = new PostEntity();

                pe.PostKeyId = currentPostKeyId;
                //currentPostKeyId++;
                pe.ParentPostKeyId = postkeyQuery.ElementAt(0).PostKeyId;
                pe.Title = reply.Title;
                pe.Body = reply.Body;
                pe.SubforumName = postQuery.ElementAt(0).SubforumName;

                ForumContext.AddToPostEntities(pe);
                ForumContext.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                //TODO
                throw;
            }
        }
コード例 #4
0
ファイル: ForumModel.Designer.cs プロジェクト: sagioto/forum
 /// <summary>
 /// Deprecated Method for adding a new object to the PostKeyEntities EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPostKeyEntities(PostKeyEntity postKeyEntity)
 {
     base.AddObject("PostKeyEntities", postKeyEntity);
 }