Exemplo n.º 1
0
        public async Task <bool> Update(Goods goods, IEnumerable <GoodsAttr> attrs, IEnumerable <GoodsAttach> downloads)
        {
            var trans = sqlExecutor.BeginTransaction();

            try
            {
                int result = await sqlExecutor.ExecuteAsync("update goods set \"Name\"=@Name,\"Picture\"=@Picture,\"Info\"=@Info,\"Description\"=@Description,\"DisplayOrder\"=@DisplayOrder,\"Status\"=@Status where id=@id", new
                {
                    id           = goods.id,
                    Name         = goods.Name,
                    Picture      = goods.Picture,
                    Info         = goods.Info,
                    Description  = goods.Description,
                    DisplayOrder = goods.DisplayOrder,
                    Status       = goods.Status
                }, System.Data.CommandType.Text, trans);

                var items = await sqlExecutor.FindAsync <GoodsAttr>(new { GoodsId = goods.id }, trans);

                foreach (var item in items)
                {
                    await sqlExecutor.DeleteAsync(item);
                }
                foreach (var attr in attrs)
                {
                    attr.GoodsId = goods.id;
                }
                await sqlExecutor.BulkInsertAsync <GoodsAttr>(attrs, trans);

                var rs = await sqlExecutor.FindAsync <GoodsAttach>(new { GoodsId = goods.id }, trans);

                foreach (var r in rs)
                {
                    await sqlExecutor.DeleteAsync(r);
                }
                foreach (var attach in downloads)
                {
                    attach.GoodsId = goods.id;
                }
                await sqlExecutor.BulkInsertAsync <GoodsAttach>(downloads, trans);

                trans.Commit();
                return(true);
            }
            catch
            {
                trans.Rollback();
                return(false);
            }
        }
Exemplo n.º 2
0
 public async Task <bool> AddAsync(IEnumerable <TEntity> entities)
 {
     return(await sqlExecutor.BulkInsertAsync <TEntity>(entities.ToArray()));
 }