示例#1
0
        public int Create(Text text)
        {
            using (var db = new DbSocialReader())
            {
                var query = from a in db.Text
                            where a.Id == text.Id
                            select a;

                if (query.Any())
                {
                    return(-1);
                }
                db.Insert(text);
                // Apply Id on account object.
                var lastId = (from a in db.Text orderby a.Id select a.Id).Max();

                text.Id = lastId;

                // To-Do: Apply Bulk insert
                if (text.GetAuthors().Count > 0)
                {
                    foreach (var author in text.GetAuthors())
                    {
                        var textToAuthor = new TextToAuthor {
                            TextId = text.Id, AuthorId = author.Id
                        };
                        db.Insert(textToAuthor);
                    }
                }

                // To-Do: Apply Bulk insert
                if (text.GetGenres().Count > 0)
                {
                    foreach (var genre in text.GetGenres())
                    {
                        var textToGenre = new TextToGenre {
                            TextId = text.Id, GenreId = genre.Id
                        };
                        db.Insert(textToGenre);
                    }
                }

                return(lastId);
            }
        }
示例#2
0
        public void Create(User user)
        {
            using (var db = new DbSocialReader())
            {
                var query = from u in db.User
                            where u.Id == user.Id || u.Name == user.Name
                            select u;

                if (query.Any())
                {
                    return;
                }
                db.Insert(user);
                // Apply Id on account object.
                var lastId = (from u in db.User orderby u.Id select u.Id).Max();
                user.Id = lastId;
            }
        }
示例#3
0
        public void Create(Score score)
        {
            using (var db = new DbSocialReader())
            {
                var query = from s in db.Score
                            where s.Id == score.Id
                            select s;

                if (query.Any())
                {
                    return;
                }
                db.Insert(score);
                // Apply Id on note object.
                var lastId = (from s in db.Score orderby s.Id select s.Id).Max();
                score.Id = lastId;
            }
        }
示例#4
0
        public void Create(Note note)
        {
            using (var db = new DbSocialReader())
            {
                var query = from a in db.Note
                            where a.Id == note.Id
                            select a;

                if (query.Any())
                {
                    return;
                }
                db.Insert(note);
                // Apply Id on note object.
                var lastId = (from a in db.Note orderby a.Id select a.Id).Max();
                note.Id = lastId;
            }
        }
示例#5
0
        /*
         * Returns id of inserted account.
         * Returns -1 if failed.
         */
        public int Create(Account account)
        {
            using (var db = new DbSocialReader())
            {
                var query = from a in db.Account
                            where a.Id == account.Id
                            select a;

                if (query.Any())
                {
                    return(-1);
                }
                db.Insert(account);
                // Apply Id on account object.
                var lastId = (from a in db.Account orderby a.Id select a.Id).Max();

                account.Id = lastId;
                return(lastId);
            }
        }