public async Task <int> insert(DbConnectionService dbcs)
        {
            string sql = "INSERT INTO ArticleContents VALUES(:Id, :FileName, :ContentType, :ArticleId, :CreatedAt, :UpdatedAt)";

            SequenceService seq = new SequenceService();
            var             Id  = seq.getNextVal(SequenceService.seqType.ArticleContents);
            var             now = DateTime.Now;

            var result = await dbcs.GetConnection().ExecuteAsync(sql, new
            {
                Id = Id
                ,
                FileName = this.FileName
                ,
                ContentType = this.ContentType
                ,
                ArticleId = this.ArticleId
                ,
                CreatedAt = now
                ,
                UpdatedAt = now
            }, dbcs.GetTransaction());;

            return(result);
        }
Example #2
0
        public async Task <int> insert(DbConnectionService dbcs)
        {
            string sql = "INSERT INTO Article VALUES(:Id, :UserId, :PostDate, :Text, :CreatedAt, :UpdatedAt)";

            SequenceService seq    = new SequenceService();
            var             Id     = seq.getNextVal(SequenceService.seqType.Article);
            var             now    = DateTime.Now;
            var             result = await dbcs.GetConnection().ExecuteAsync(sql, new
            {
                Id = Id
                ,
                UserId = this.User.Id
                ,
                PostDate = this.PostDate
                ,
                Text = this.Text
                ,
                CreatedAt = now
                ,
                UpdatedAt = now
            }, dbcs.GetTransaction());

            if (result == 1)
            {
                this.Id = Decimal.ToInt64(Id);

                List <Task <int> > task = new List <Task <int> >();
                foreach (var artC in this.Contents)
                {
                    artC.ArticleId = this.Id;
                    task.Add(artC.insert(dbcs));
                }
                int[] retC = await Task.WhenAll(task);

                foreach (var r in retC)
                {
                    if (r == 0)
                    {
                        throw new InvalidOperationException("Error:Insert ArticleContents");
                    }
                    result += r;
                }

                return(result);
            }
            else
            {
                throw new InvalidOperationException("Error:Insert Article");
            }
        }