Exemplo n.º 1
0
        public async Task AddAsync(BasicData entity, string userId)
        {
            var db   = _databaseLocator.GetProductCenterManagementDatabase();
            var tran = _databaseLocator.GetDbTransaction(db);

            StringBuilder sql = new StringBuilder();

            sql.Append($" INSERT INTO {_TABLE} ");
            sql.Append("   (Id, Code, Name, ParentId, SortOrder, Enabled, CreatedAt, CreatedById) ");
            sql.Append($" VALUES ");
            sql.Append("   (nextval('DT'), @Code, @Name, @ParentId, @SortOrder, @Enabled, @CreatedAt, @CreatedById) ");

            await db.ExecuteAsync(
                sql.ToString(),
                new
            {
                entity.Code,
                entity.Name,
                entity.ParentId,
                entity.SortOrder,
                entity.Enabled,
                entity.CreatedAt,
                CreatedById = userId,
            },
                tran);
        }
Exemplo n.º 2
0
        public async Task AddAsync(ProductInfo entity, string userId)
        {
            var db   = _databaseLocator.GetProductCenterManagementDatabase();
            var tran = _databaseLocator.GetDbTransaction(db);

            StringBuilder sql = new StringBuilder();

            sql.Append($" INSERT INTO {_TABLE} ");
            sql.Append("   ( Id, ProdCode, ProdName, ProdFullName, ProdTypeId,");
            sql.Append("     ProdTypeCode, ProdTypeName, AuditState, CreatedById, CreatedAt ) ");
            sql.Append(" VALUES ");
            sql.Append("   ( nextval('PI'), @ProdCode, @ProdName, @ProdFullName, @ProdTypeId,");
            sql.Append("     @ProdTypeCode, @ProdTypeName, 0, @CreatedById, NOW() ); ");
            var result = await db.ExecuteAsync(
                sql.ToString(),
                new
            {
                entity.ProdCode,
                entity.ProdName,
                entity.ProdFullName,
                entity.ProdTypeId,
                entity.ProdTypeCode,
                entity.ProdTypeName,
                entity.AuditState,
                CreatedById = userId,
            },
                tran);
        }
Exemplo n.º 3
0
        public async Task AddPictureResourcesAsync(string productId, List <ProductPicture> pictures, string userId)
        {
            if (pictures != null)
            {
                var db   = _databaseLocator.GetProductCenterManagementDatabase();
                var tran = _databaseLocator.GetDbTransaction(db);

                await AddAsync(productId, pictures, userId, db, tran);
            }
        }
        public async Task AddAsync(MaterialType entity)
        {
            var db   = _databaseLocator.GetProductCenterManagementDatabase();
            var tran = _databaseLocator.GetDbTransaction(db);

            await db.ExecuteAsync(
                @"INSERT INTO tb_materialtype (Id, ParentId, TypeCode, TypeName, LevelCode, SortOrder, CreatedById, CreatedAt)
                 VALUES(nextval('MT'), @ParentId, @TypeCode, @TypeName,  @LevelCode, @SortOrder, @CreatedById, NOW())",
                entity,
                tran);
        }
Exemplo n.º 5
0
        public async Task AddAsync(ProducType entity, string userId)
        {
            var db   = _databaseLocator.GetProductCenterManagementDatabase();
            var tran = _databaseLocator.GetDbTransaction(db);

            StringBuilder sql = new StringBuilder();

            sql.Append($" INSERT INTO {_TABLE} ");
            sql.Append("   (Id, ParentId, LevelCode, TypeName, TypeCode, SortOrder, CreatedById, CreatedAt) ");
            sql.Append($" VALUES ");
            sql.Append("   (nextval('PT'), @ParentId, @LevelCode, @TypeName, @TypeCode, @SortOrder, @CreatedById, NOW()) ");

            await db.ExecuteAsync(sql.ToString(), new { entity.ParentId, entity.LevelCode, entity.TypeCode, entity.TypeName, entity.SortOrder, CreatedById = userId }, tran);
        }
        public async Task AddAsync(List <Trade> tradeinfos)
        {
            var db   = _databaseLocator.GetProductCenterManagementDatabase();
            var tran = _databaseLocator.GetDbTransaction(db);

            StringBuilder sql = new StringBuilder();

            sql.Append($@" INSERT INTO {_TABLE}   
                                (Id, ProdMaterId, TradeId, TradeName, CreatedAt)  
                           VALUES 
                                (nextval('TI'), @ProdMaterId, @TradeId, @TradeName ,NOW())");

            var result = await db.ExecuteAsync(sql.ToString(), tradeinfos, tran);
        }
        public async Task AddAsync(List <ProductVehicle> entities)
        {
            var db   = _databaseLocator.GetProductCenterManagementDatabase();
            var tran = _databaseLocator.GetDbTransaction(db);

            StringBuilder sql = new StringBuilder();

            sql.Append($" INSERT INTO {_TABLE} ");
            sql.Append(@"   ( Id, VehicleId, ProductId, BrandId, BrandName, ChildBrandId, ChildBrandName,
                              SeriesId, SeriesName, ModelId, ModelName, Year, Displacement, DisplacementText,
                              Horsepower, IntakeType, GearboxName, CreatedAt) ");
            sql.Append($" VALUES ");
            sql.Append(@"   ( nextval('PV'), @VehicleId, @ProductId, @BrandId, @BrandName, @ChildBrandId, @ChildBrandName,
                              @SeriesId, @SeriesName, @ModelId, @ModelName, @Year, @Displacement, @DisplacementText, 
                              @Horsepower, @IntakeType, @GearboxName, NOW()) ");

            await db.ExecuteAsync(sql.ToString(), entities, tran);
        }
        public async Task AddAsync(Property entity, string userId)
        {
            var db   = _databaseLocator.GetProductCenterManagementDatabase();
            var tran = _databaseLocator.GetDbTransaction(db);

            StringBuilder sql = new StringBuilder();

            sql.Append($" INSERT INTO {_TABLE} ");
            sql.Append("   ( Id, PropName, DisplayName, IsDisable, CreatedById, CreatedAt) ");
            sql.Append($" VALUES ");
            sql.Append("   ( nextval('PR'), @PropName, @DisplayName, @IsDisable, @CreatedById, NOW()) ");

            await db.ExecuteAsync(
                sql.ToString(),
                new
            {
                entity.PropName,
                entity.DisplayName,
                entity.IsDisable,
                CreatedById = userId,
            }, tran);
        }
Exemplo n.º 9
0
        public async Task AddAsync(ProductDetail entity, string userId)
        {
            var db   = _databaseLocator.GetProductCenterManagementDatabase();
            var tran = _databaseLocator.GetDbTransaction(db);

            StringBuilder sql = new StringBuilder();

            sql.Append($@" INSERT INTO {_TABLE}
                               (Id, ProductId, MaterialId, Quantity, CreatedById, CreatedAt) 
                           VALUES 
                               (nextval('PD'), @ProductId, @MaterialId, @Quantity, @CreatedById, NOW()) ");

            var result = await db.ExecuteAsync(
                sql.ToString(),
                new
            {
                entity.ProductId,
                entity.MaterialId,
                entity.Quantity,
                CreatedById = userId,
            },
                tran);
        }
        /// <summary>
        /// 同级移动
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="moveAfterPosition">移动之后的位置</param>
        /// <param name="moveId">当前Id</param>
        /// <param name="parentId">移动后的ParentId</param>
        /// <param name="tbName">表名</param>
        /// <returns>返回值</returns>
        public async Task <int> MovePosition <T>(int moveAfterPosition, string moveId, string parentId, string tbName)
            where T : MoveBaseModel
        {
            int result = -1;
            var db     = _databaseLocator.GetProductCenterManagementDatabase();
            var tran   = _databaseLocator.GetDbTransaction(db);

            var atInfo = await db.QueryMultipleAsync(
                $"SELECT SortOrder FROM {tbName} " +
                "WHERE Id = @Id AND Deleted = 0",
                new
            {
                Id = moveId,
            },
                tran);

            int?atSortOrder = atInfo.Read <T>().First().SortOrder;

            result = await db.ExecuteAsync(
                $"UPDATE {tbName} SET " +
                "SortOrder = @SortOrder WHERE Id = @Id AND Deleted = 0",
                new
            {
                SortOrder = moveAfterPosition,
                Id        = moveId,
            },
                tran);

            string symbol   = string.Empty;
            int    initSort = -1;

            if (moveAfterPosition < atSortOrder)
            {
                symbol = ">=";
            }
            else
            {
                symbol = "<=";
            }

            string sql = $"SELECT Id,SortOrder FROM {tbName} ";

            if (parentId == null || parentId == string.Empty || parentId == "-1")
            {
                sql += $"WHERE ParentId IS NULL AND Deleted = 0 AND SortOrder {symbol} @SortOrder ";
            }
            else
            {
                sql += $"WHERE ParentId = @ParentId AND Deleted = 0 AND SortOrder {symbol} @SortOrder ";
            }

            var updateInfo = await db.QueryMultipleAsync(
                sql +
                "ORDER BY SortOrder ASC ",
                new
            {
                ParentId  = parentId,
                SortOrder = moveAfterPosition,
            },
                tran);

            if (symbol == "<=")
            {
                moveAfterPosition = initSort;
            }

            foreach (var item in updateInfo.Read <T>())
            {
                if (item.Id != moveId)
                {
                    moveAfterPosition += 1;
                    var resInfo = await db.ExecuteAsync(
                        $"UPDATE {tbName} SET " +
                        "SortOrder = @SortOrder WHERE Id = @Id AND Deleted = 0",
                        new
                    {
                        SortOrder = moveAfterPosition,
                        Id        = item.Id,
                    },
                        tran);
                }
            }

            return(result);
        }