public async Task <Guid> AddOrGetIDItemCategoryLookup(ProductCategory sourcePC, List <WooItemWithParent> sourceCategoriesWithParents) { IAppRepository <ItemCategoryLookup> _itemCategoryLookupRepository = _AppUnitOfWork.Repository <ItemCategoryLookup>(); ItemCategoryLookup _itemCategoryLookup = await _itemCategoryLookupRepository.FindFirstAsync(ic => ic.CategoryName == sourcePC.name); if (_itemCategoryLookup == null) { ItemCategoryLookup _newItemCategoryLookup = new ItemCategoryLookup { CategoryName = sourcePC.name, // Null;? ParentCategoryId = Guid.Empty, UsedForPrediction = (sourcePC.parent == null) || (sourcePC.parent == 0), Notes = $"Imported Woo Category ID {sourcePC.id}" }; if (sourcePC.parent > 0) { sourceCategoriesWithParents.Add(new WooItemWithParent { ChildId = (int)sourcePC.id, ParentId = (int)sourcePC.parent }); } await _itemCategoryLookupRepository.AddAsync(_newItemCategoryLookup); return(_newItemCategoryLookup.ItemCategoryLookupId); } else { return(Guid.Empty); } }
async Task <Guid> AddProductAttribute(ProductAttribute pPA, WooProductAttributeMap pWooAttributeMap) { Guid _ItemAttributeId = Guid.Empty; IAppRepository <WooProductAttributeMap> _WooAttributeMapRepository = _AppUnitOfWork.Repository <WooProductAttributeMap>(); // Add Item Attribute if it does not exist _ItemAttributeId = await AddOrGetIDItemAttribute(pPA); if (pWooAttributeMap == null) { pWooAttributeMap = new WooProductAttributeMap { WooProductAttributeId = (int)pPA.id, ItemAttributeLookupId = _ItemAttributeId, CanUpdate = true }; } else { pWooAttributeMap.WooProductAttributeId = (int)pPA.id; pWooAttributeMap.ItemAttributeLookupId = _ItemAttributeId; } // return Id if we update okay return((await _WooAttributeMapRepository.AddAsync(pWooAttributeMap) != AppUnitOfWork.CONST_WASERROR) ? _ItemAttributeId : Guid.Empty); // did not updated so set _ItemAttributeId to ItemAttributeID to Guid.Empty = error== 0) }
//does not exists add and CopyWooDetails to new record increase Counter.added async Task <Guid> AddProductToItems(Product currWooProd, List <WooItemWithParent> pProductsWithParents) { Guid _itemId = Guid.Empty; IAppRepository <WooProductMap> _wooProductMapRepository = _AppUnitOfWork.Repository <WooProductMap>(); //it may not be in the map, but we may have a product with tat name so see if we do -Add Item Product if it does not exist _itemId = await AddOrGetIDItem(currWooProd, pProductsWithParents); if (_itemId != Guid.Empty) { WooProductMap _wooProductMap = new WooProductMap { WooProductId = (int)currWooProd.id, ItemId = _itemId, CanUpdate = true }; if (await _wooProductMapRepository.AddAsync(_wooProductMap) == AppUnitOfWork.CONST_WASERROR) { // did not add so set _ItemProductId to ItemProductID to Guid.Empty = error _itemId = Guid.Empty; } currImportCounters.TotalAdded++; } return(_itemId); }
async Task <Guid> AddProductAttributeTerm(ProductAttributeTerm sourcePAT, Guid sourceParentAttributeId, WooProductAttributeTermMap sourceWooAttributeTermMapsourceParentAttributeId) { Guid _itemAttributeTermId = Guid.Empty; IAppRepository <WooProductAttributeTermMap> _wooAttributeTermMapRepository = _AppUnitOfWork.Repository <WooProductAttributeTermMap>(); // Add Item AttributeTerm if it does not exist _itemAttributeTermId = await AddOrGetIDItemAttributeVariety(sourcePAT, sourceParentAttributeId); if (sourceWooAttributeTermMapsourceParentAttributeId == null) { sourceWooAttributeTermMapsourceParentAttributeId = new WooProductAttributeTermMap { WooProductAttributeTermId = (int)sourcePAT.id, ItemAttributeVarietyLookupId = _itemAttributeTermId }; } else { sourceWooAttributeTermMapsourceParentAttributeId.WooProductAttributeTermId = (int)sourcePAT.id; sourceWooAttributeTermMapsourceParentAttributeId.ItemAttributeVarietyLookupId = _itemAttributeTermId; } if (await _wooAttributeTermMapRepository.AddAsync(sourceWooAttributeTermMapsourceParentAttributeId) == AppUnitOfWork.CONST_WASERROR) { // did not add so set _ItemAttributeTermId to ItemAttributeTermID to Guid.Empty = error _itemAttributeTermId = Guid.Empty; } return(_itemAttributeTermId); }
public async void HandleValidSubmit() { if (modelWooSettings != null) { ShowSaving(); IAppRepository <WooSettings> _WooSettingsRepo = _AppUnitOfWork.Repository <WooSettings>(); // save // run this update regardless if (modelWooSettings.WooSettingsId > 0) { // it means that there was a record in the database. IsSaved = (await _WooSettingsRepo.UpdateAsync(modelWooSettings)) > 0; } else { // it means that there was a record in the database. IsSaved = (await _WooSettingsRepo.AddAsync(modelWooSettings)) > 0; } IsChanged = false; if (IsSaved) { ShowChangedStatus.UpdateModalMessage("Woo settings have been saved."); } else { ShowChangedStatus.UpdateModalMessage("Error saving Woo settings. Please check database access."); } HideSaving(); ShowChangedStatus.ShowModal(); StateHasChanged(); } }
public async Task <IActionResult> ExecuteAsync(CarSm carSm, CancellationToken cancellationToken) { Car car = _carSmToCarMapper.Map(carSm); car = await _carRepository.AddAsync(car, cancellationToken); CarVm carViewModel = _carToCarVmMapper.Map(car); return(new CreatedAtRouteResult(RouteNames.GetCar, new { carId = carViewModel.CarId }, carViewModel)); }
public async Task <ICommandResult <Car> > Handle(CreateCarCommand command, CancellationToken cancellationToken) { CarSm carSm = command.CarSm; Car car = _carSmToCarMapper.Map(carSm); car = await _carRepository.AddAsync(car, cancellationToken); return(new CommandResult <Car>(CommandStatus.Ok, car)); }
public async Task <IActionResult> Create([FromBody] App app) { _logger.Info("Creating app: {@app}", app); app.Id = DataUtil.GenerateUniqueId(); app.CreatedDate = DateTime.UtcNow; app.ModifiedDate = DateTime.UtcNow; await _appRepository.AddAsync(app); _logger.Info("Created app: {@app}", app); return(Ok(app)); }
private async Task <int> MapOurItemToWooItemSync(ProductAttribute newWooProductAttribute, ItemAttributeLookup addViewEntity) { // create a map to the woo Attribute maps using the id and the Attribute // IAppRepository <WooProductAttributeMap> _wooProductAttributeMapRepository = _AppUnitOfWork.Repository <WooProductAttributeMap>(); return(await _wooProductAttributeMapRepository.AddAsync(new WooProductAttributeMap { ItemAttributeLookupId = addViewEntity.ItemAttributeLookupId, WooProductAttributeId = Convert.ToInt32(newWooProductAttribute.id), CanUpdate = true, })); }
// Log the status of the import async Task LogImport(int?importedId, string sourceParameter, Models.WooSections importedSection) { IAppRepository <WooSyncLog> _WooSyncLogRepository = _AppUnitOfWork.Repository <WooSyncLog>(); await _WooSyncLogRepository.AddAsync(new WooSyncLog { // add the parameters WooSyncDateTime = _LogDate, Result = (importedId != null) ? Models.WooResults.Success : (importedId == null) ? Models.WooResults.none : Models.WooResults.Error, Parameters = sourceParameter, Section = importedSection, Notes = (importedId != null) && (importedId > 0) ? $"Imported id: {importedId}, DT: {DateTime.Now:d}" : $"DT: { DateTime.Now:d}" }); }
private async Task <int> MapOurItemToWooItemSync(ProductCategory newWooProductCategory, ItemCategoryLookup addViewEntity) { // create a map to the woo category maps using the id and the category // IAppRepository <WooCategoryMap> _wooCategoryMapRepository = _AppUnitOfWork.Repository <WooCategoryMap>(); return(await _wooCategoryMapRepository.AddAsync(new WooCategoryMap { ItemCategoryLookupId = addViewEntity.ItemCategoryLookupId, WooCategoryId = (int)newWooProductCategory.id, WooCategoryName = addViewEntity.CategoryName, CanUpdate = true, WooCategoryParentId = (int)newWooProductCategory.parent })); }
async Task <Guid> AddOrGetIDItemAttribute(ProductAttribute pPA) { IAppRepository <ItemAttributeLookup> _ItemAttributeRepository = _AppUnitOfWork.Repository <ItemAttributeLookup>(); ItemAttributeLookup _ItemAttribute = await _ItemAttributeRepository.FindFirstAsync(ic => ic.AttributeName == pPA.name); if (_ItemAttribute == null) { ItemAttributeLookup _newItemAttribute = new ItemAttributeLookup { AttributeName = pPA.name, Notes = $"Imported Woo Attribute ID {pPA.id}" }; return((await _ItemAttributeRepository.AddAsync(_newItemAttribute) != AppUnitOfWork.CONST_WASERROR) ? _newItemAttribute.ItemAttributeLookupId : Guid.Empty); } else { return(_ItemAttribute.ItemAttributeLookupId); // we found one with the same name so assume this is the correct one. } }
public override async Task InsertRowAsync(ItemCategoryLookupView newVeiwEntity) { IAppRepository <ItemCategoryLookup> _itemCategoryLookupRepository = _AppUnitOfWork.Repository <ItemCategoryLookup>(); // first check we do not already have a category like this. if (await _itemCategoryLookupRepository.FindFirstAsync(icl => icl.CategoryName == newVeiwEntity.CategoryName) == null) { ItemCategoryLookup _NewItemCategoryLookup = GetItemFromView(newVeiwEntity); // store this here since when it is added it will automatically update the id field int _recsAdded = await _itemCategoryLookupRepository.AddAsync(_NewItemCategoryLookup); if (_recsAdded != AppUnitOfWork.CONST_WASERROR) { _GridSettings.PopUpRef.ShowNotification(PopUpAndLogNotification.NotificationType.Success, $"{newVeiwEntity.CategoryName} - added", "Category Added"); if (newVeiwEntity.CanUpdateWooMap ?? false) { // they selected to update woo so add to Woo if (await AddWooItemAndMapAsync(_NewItemCategoryLookup) == AppUnitOfWork.CONST_WASERROR) // add if they select to update { _GridSettings.PopUpRef.ShowNotification(PopUpAndLogNotification.NotificationType.Error, $"Error adding {newVeiwEntity.CategoryName} to Woo - {_AppUnitOfWork.GetErrorMessage()}", "Error adding Woo Category"); } else { _GridSettings.PopUpRef.ShowNotification(PopUpAndLogNotification.NotificationType.Success, $"{newVeiwEntity.CategoryName} - added to Woo", "Woo Category Added"); } } } else { _GridSettings.PopUpRef.ShowNotification(PopUpAndLogNotification.NotificationType.Error, $"{newVeiwEntity.CategoryName} - {_AppUnitOfWork.GetErrorMessage()}", "Error adding Category"); } } else { _GridSettings.PopUpRef.ShowNotification(PopUpAndLogNotification.NotificationType.Error, $"{newVeiwEntity.CategoryName} already exists, so could not be added."); } //-> done in parent await LoadAllViewItemsAsync(); // reload the list so the latest item is displayed }
public async Task <bool> UpdateSysPreferencesAsync(SysPrefsModel updateSysPrefsModel) { bool updated = false; int recsUpdated = 0; if (updateSysPrefsModel.SysPrefs.SysPrefsId > 0) { // it means that there was a record in the database. recsUpdated = await _SysPrefsRepo.UpdateAsync(updateSysPrefsModel.SysPrefs); updated = (recsUpdated > 0); } else { // it means that there was a record in the database. recsUpdated = await _SysPrefsRepo.AddAsync(updateSysPrefsModel.SysPrefs); updated = recsUpdated > 0; } // run this update regardless if (updateSysPrefsModel.WooSettings.WooSettingsId > 0) { // it means that there was a record in the database. recsUpdated = await _WooSettingsRepo.UpdateAsync(updateSysPrefsModel.WooSettings); updated = updated && (recsUpdated > 0); } else { // it means that there was a record in the database. recsUpdated = await _WooSettingsRepo.AddAsync(updateSysPrefsModel.WooSettings); updated = updated && (recsUpdated > 0); } return(updated); }
// check if the a product if the name product.name exists if so get that ID (and update), or add it and return the id. async Task <Guid> AddOrGetIDItemAttributeVariety(ProductAttributeTerm sourcePAT, Guid sourceParentAttributeId) { IAppRepository <ItemAttributeVarietyLookup> _itemAttributeVarietyRepository = _AppUnitOfWork.Repository <ItemAttributeVarietyLookup>(); ItemAttributeVarietyLookup _ItemAttributeVariety = await _itemAttributeVarietyRepository.FindFirstAsync(ic => ic.VarietyName == sourcePAT.name); if (_ItemAttributeVariety == null) { ItemAttributeVarietyLookup _newItemAttributeVariety = new ItemAttributeVarietyLookup { ItemAttributeLookupId = sourceParentAttributeId, VarietyName = sourcePAT.name, Notes = $"Imported Woo Attribute Term ID {sourcePAT.id}" }; int _recsAdded = await _itemAttributeVarietyRepository.AddAsync(_newItemAttributeVariety); return((_recsAdded != AppUnitOfWork.CONST_WASERROR) ? _newItemAttributeVariety.ItemAttributeVarietyLookupId : Guid.Empty); } else { return(_ItemAttributeVariety.ItemAttributeVarietyLookupId); // we found one with the same name so assume this is the correct one. } }
public async Task InsertRowAsync(ItemCategoryLookupView newVeiwEntity) { IAppRepository <ItemCategoryLookup> _ItemCategoryLookupRepository = _appUnitOfWork.Repository <ItemCategoryLookup>(); // first check we do not already have a category like this. if (await _ItemCategoryLookupRepository.FindFirstAsync(icl => icl.CategoryName == newVeiwEntity.CategoryName) == null) { int _recsAdded = await _ItemCategoryLookupRepository.AddAsync(GetItemFromView(newVeiwEntity)); if (_recsAdded != AppUnitOfWork.CONST_WASERROR) { _gridSettings.PopUpRef.ShowNotification(PopUpAndLogNotification.NotificationType.Success, $"{newVeiwEntity.CategoryName} - {_appUnitOfWork.GetErrorMessage()}", "Category Added"); } else { _gridSettings.PopUpRef.ShowNotification(PopUpAndLogNotification.NotificationType.Error, $"{newVeiwEntity.CategoryName} - {_appUnitOfWork.GetErrorMessage()}", "Error adding Category"); } } else { _gridSettings.PopUpRef.ShowNotification(PopUpAndLogNotification.NotificationType.Error, $"{newVeiwEntity.CategoryName} already exists, so could not be added."); } await LoadAllViewItems(); // reload the list so the latest item is displayed }
async Task <Guid> AddProductCategory(ProductCategory newPC, List <WooItemWithParent> newCategoriesWithParents) { Guid _itemCategoryLookupId = Guid.Empty; IAppRepository <WooCategoryMap> _wooCategoryMapRepository = _AppUnitOfWork.Repository <WooCategoryMap>(); // Add Item Category if it does not exist _itemCategoryLookupId = await AddOrGetIDItemCategoryLookup(newPC, newCategoriesWithParents); if (_itemCategoryLookupId != Guid.Empty) { WooCategoryMap _wooCategoryMap = new WooCategoryMap { WooCategoryName = newPC.name, WooCategorySlug = newPC.slug, WooCategoryParentId = (int)newPC.parent, ItemCategoryLookupId = _itemCategoryLookupId, WooCategoryId = (int)newPC.id, CanUpdate = true }; //else was check if woomap was null //{ // _wooCategoryMap.WooCategoryName = pPC.name; // _wooCategoryMap.WooCategorySlug = pPC.slug; // _wooCategoryMap.WooCategoryParentId = pPC.parent; // _wooCategoryMap.ItemCategoryLookupId = _itemCategoryLookupId; // _wooCategoryMap.WooCategoryId = (int)pPC.id; //} if (await _wooCategoryMapRepository.AddAsync(_wooCategoryMap) == AppUnitOfWork.CONST_WASERROR) { // did not add so set _itemCategoryLookupId to ItemCategoryLookupID to Guid.Empty = error _itemCategoryLookupId = Guid.Empty; } } return(_itemCategoryLookupId); }