示例#1
0
        public static void DeleteWarehouseItem(string id, string userId)
        {
            var item = GetItem(id);

            SqlHelper.StartTransaction(ConfigManager.ConnectionString, (connection, transaction) =>
            {
                var param = new[]
                {
                    new SqlParameter("@id", id),
                };
                SqlHelper.ExecuteCommand(connection, transaction, CommandType.StoredProcedure, SP_WAREHOUSEITEM_DELETE, param);

                var activity = new WarehouseActivity
                {
                    Id          = "w-" + IdHelper.Generate(),
                    Date        = DateTime.Now,
                    Name        = "Delete item '" + item.Name + "'",
                    Description = $"Remove item with Id: {item.Id}; Name: {item.Name} from warehouse",
                    WarehouseId = item.WarehouseId,
                    UserId      = userId
                };

                param = new[]
                {
                    new SqlParameter("@id", activity.Id),
                    new SqlParameter("@warehouseId", activity.WarehouseId),
                    new SqlParameter("@name", activity.Name),
                    new SqlParameter("@description", activity.Description),
                    new SqlParameter("@userId", activity.UserId),
                };
                SqlHelper.ExecuteCommand(connection, transaction, CommandType.StoredProcedure, SP_WAREHOUSEACTIVITY_INSERT, param);
            });
        }
示例#2
0
        public static WarehouseItem InsertWarehouseItem(WarehouseItem item, string userId)
        {
            item.Id = "w-" + IdHelper.Generate();
            SqlHelper.StartTransaction(ConfigManager.ConnectionString, (connection, transaction) =>
            {
                var param = new[]
                {
                    new SqlParameter("@id", item.Id),
                    new SqlParameter("@warehouseId", item.WarehouseId),
                    new SqlParameter("@condition", item.Condition),
                    new SqlParameter("@count", item.Count),
                    new SqlParameter("@name", item.Name),
                    new SqlParameter("@description", item.Description),
                };

                SqlHelper.ExecuteCommand(connection, transaction, CommandType.StoredProcedure, SP_WAREHOUSEITEM_INSERT, param);

                var activity = new WarehouseActivity
                {
                    Id          = "w-" + IdHelper.Generate(),
                    Date        = DateTime.Now,
                    Name        = "Insert item '" + item.Name + "'",
                    Description = $"Adding {item.Count} items '{item.Name}' in {item.Condition} condition",
                    WarehouseId = item.WarehouseId,
                    UserId      = userId
                };

                param = new[]
                {
                    new SqlParameter("@id", activity.Id),
                    new SqlParameter("@warehouseId", activity.WarehouseId),
                    new SqlParameter("@name", activity.Name),
                    new SqlParameter("@description", activity.Description),
                    new SqlParameter("@userId", activity.UserId),
                };
                SqlHelper.ExecuteCommand(connection, transaction, CommandType.StoredProcedure, SP_WAREHOUSEACTIVITY_INSERT, param);
            });


            return(item);
        }
示例#3
0
        public static PaginationResult <WarehouseActivity> GetWarehouseActivity(string warehouseId, int pageIndex, int pageSize)
        {
            var param = new[]
            {
                new SqlParameter("@warehouseId", warehouseId),
                new SqlParameter("@pageIndex", pageIndex),
                new SqlParameter("@pageSize", pageSize),
            };

            return(SqlHelper.ExecuteReader(SP_WAREHOUSEACTIVITY_SELECT, param, reader =>
            {
                var result = new PaginationResult <WarehouseActivity>
                {
                    Data = new List <WarehouseActivity>(),
                    Total = 0
                };
                while (reader.Read())
                {
                    var item = new WarehouseActivity
                    {
                        Id = reader["Id"].ToString(),
                        WarehouseId = warehouseId,
                        Date = Convert.ToDateTime(reader["Date"]),
                        Description = reader["Description"].ToString(),
                        Name = reader["Name"].ToString(),
                        UserId = reader["UserId"].ToString(),
                    };
                    result.Data.Add(item);
                }
                reader.NextResult();
                reader.Read();
                result.Total = Convert.ToInt32(reader["Total"].ToString());

                return result;
            }));
        }