public void Create(CreateAssetInput input) { var @entityAsset = Asset.Create(input.Name, input.Description, input.Code, input.Barcode, input.AdmissionDate, _dateTime.Now, input.Price, input.DepreciationMonthsQty, input.AssetType, input.CategoryId, input.CreatorGuidId, _dateTime.Now, input.Brand, input.ModelStr, input.Plate, input.Series, input.IsAToolInKit, input.CompanyName); if (@entityAsset == null) { throw new UserFriendlyException("No se pudo crear el artículo."); } if (_assetManager.AssetExist(@entityAsset.Code, input.Id, input.CompanyName)) { throw new UserFriendlyException("Existe un Artículo con el mismo Código."); } if (input.CustomFieldsDto != null && input.CustomFieldsDto.Any()) { foreach (var cf in input.CustomFieldsDto) { var entityCf = CustomField.Create(cf.Name, cf.CustomFieldType, @entityAsset.Id, cf.Value, cf.GetStringValue(), cf.GetDateValue(), cf.GetIntValue(), cf.GetDoubleValue(), input.CreatorGuidId, _dateTime.Now, input.CompanyName); @entityAsset.CustomFields.Add(entityCf); } } if (input.DetailAssetToolKitsDto != null && input.DetailAssetToolKitsDto.Any()) { foreach (var tool in input.DetailAssetToolKitsDto) { var entityTool = ToolAsset.Create(tool.Name, tool.Name, tool.Code, @entityAsset.Id, input.CreatorGuidId, _dateTime.Now, tool.Quatity, input.CompanyName); @entityAsset.ToolAssets.Add(entityTool); } } if (HasFile(input.Image)) { string folderPath = "~/AssetsImages/"; string fileName = input.Image.FileName;//input.Id + ".png" var mappedPath = HostingEnvironment.MapPath(folderPath) + fileName; var directory = new DirectoryInfo(HostingEnvironment.MapPath(folderPath)); if (directory.Exists == false) { directory.Create(); } string folderPathRelative = "../../AssetsImages/"; input.ImagePath = folderPathRelative + fileName; input.Image.SaveAs(mappedPath); @entityAsset.SetImage(input.ImagePath); } _assetManager.Create(@entityAsset); }
public void InsertAssetsDb(IList <Asset> listAssets, Guid userId, string company) { int count = 0; Cellar cellar = _cellarManager.GetAllCellars(company).FirstOrDefault(); foreach (Asset asset in listAssets) { if (count < 500) { _assetManager.Create(asset); if (asset.Price < 1) { asset.Price = 1; } Stock stock = Stock.Create(cellar.Id, asset.Id, 1, asset.Price, userId, asset.CreationTime, company); _stockManager.Create(stock); } count++; } }
public Task <long> Create(Asset entity) { return(WithConnection((connection, transaction) => _assetManager.Create(entity, connection, transaction))); }