Exemplo n.º 1
0
        public static DataTable ImportAssetsApi(Guid organizationId, int departmentId, int? userId, string userName, bool isInsertOnly, bool insertMissedValues, DataTable dtAssets, ref int insertedObjectsCount, ref int updatedObjectsCount)
        {
            ImportAssets importAssets = new ImportAssets(organizationId, departmentId);
            ImportCustomProperty importCustomProperty = new ImportCustomProperty();

            importAssets.Validate(ref importCustomProperty, dtAssets);

            if (insertMissedValues)
            {
                DataTable dtNewAssetTypes = importAssets.GetCommonNewAssetTypes(isInsertOnly);
                DataTable dtNewAssetVendors = importAssets.GetCommonNewAssetVendors(isInsertOnly);

                if ((dtNewAssetTypes != null && dtNewAssetTypes.Rows.Count > 0) || (dtNewAssetVendors != null && dtNewAssetVendors.Rows.Count > 0))
                {
                    if (dtNewAssetTypes != null)
                        foreach (DataRow drAssetType in dtNewAssetTypes.Rows)
                            ImportAssets.AddType(organizationId, departmentId, drAssetType["AssetCategoryName"].ToString(), drAssetType["AssetTypeName"].ToString(), drAssetType["AssetMakeName"].ToString(), drAssetType["AssetModelName"].ToString());

                    if (dtNewAssetVendors != null)
                        foreach (DataRow drAssetVendor in dtNewAssetVendors.Rows)
                            ImportAssets.AddVendor(organizationId, departmentId, drAssetVendor["VendorName"].ToString());

                    importAssets.GetImportLog().Clear();
                    importAssets.Validate(ref importCustomProperty, dtAssets);
                }
            }

            importAssets.GetCommonNewAssets(userId, userName, isInsertOnly, ref insertedObjectsCount, ref updatedObjectsCount);

            return importAssets.GetImportLog();
        }