public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ICatalogRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); switch (action) { case ImportAction.Insert: var addItem = InitializeItem(null, systemValues); _repository.Add(addItem); break; case ImportAction.InsertAndReplace: var itemR = systemValues.FirstOrDefault(y => y.Name == "TaxCategoryId"); if (itemR != null) { var originalItem = _repository.TaxCategories.Where(x => x.TaxCategoryId == itemR.Value).SingleOrDefault(); if (originalItem != null) { _repository.Remove(originalItem); } } var replaceItem = InitializeItem(null, systemValues); _repository.Add(replaceItem); break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "TaxCategoryId"); if (itemU != null) { var origItem = _repository.TaxCategories.Where(x => x.TaxCategoryId == itemU.Value).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var itemD = systemValues.FirstOrDefault(y => y.Name == "TaxCategoryId"); if (itemD != null) { var deleteItem = _repository.TaxCategories.Where(x => x.TaxCategoryId == itemD.Value).SingleOrDefault(); if (deleteItem != null) { _repository.Remove(deleteItem); } } break; } return(_error); }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ICatalogRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); switch (action) { case ImportAction.Insert: var addItem = InitializeItem(null, systemValues); _repository.Add(addItem); break; case ImportAction.InsertAndReplace: var itemR = systemValues.FirstOrDefault(y => y.Name == "TaxCategoryId"); if (itemR != null) { var originalItem = _repository.TaxCategories.Where(x => x.TaxCategoryId == itemR.Value).SingleOrDefault(); if (originalItem != null) _repository.Remove(originalItem); } var replaceItem = InitializeItem(null, systemValues); _repository.Add(replaceItem); break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "TaxCategoryId"); if (itemU != null) { var origItem = _repository.TaxCategories.Where(x => x.TaxCategoryId == itemU.Value).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var itemD = systemValues.FirstOrDefault(y => y.Name == "TaxCategoryId"); if (itemD != null) { var deleteItem = _repository.TaxCategories.Where(x => x.TaxCategoryId == itemD.Value).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); } break; } return _error; }
public void AddTestCatalogs() { if (_catalogRepository.GetAll().Count() > 0) { return; } var john = _userManager.FindByNameAsync("*****@*****.**").Result; var jane = _userManager.FindByNameAsync("*****@*****.**").Result; var johnCatalog1 = CreateTestCatalog(john, "My First Library"); var janeCatalog1 = CreateTestCatalog(jane, "Random Nonsense"); _catalogRepository.Add(johnCatalog1); _catalogRepository.Add(janeCatalog1); }
protected void CreateFullGraphCatalog(ICatalogRepository client, ref Item[] items, string catalogId) { var catalogBuilder = CatalogBuilder.BuildCatalog(catalogId).WithCategory("category").WithProducts(2); var catalog = catalogBuilder.GetCatalog(); items = catalogBuilder.GetItems(); client.Add(catalog); foreach (var item in items) { client.Add(item); } client.UnitOfWork.Commit(); }
public ActionResult Add(CatalogVM model) { try { var modelAdd = model.search.GetEntity(); var msgValid = ValidateModel(modelAdd); if (string.IsNullOrEmpty(msgValid)) { var obj = _userRepository.Add(modelAdd); if (obj) { return(Json(new { status = true })); } else { return(Json(new { status = false, msg = "Thêm thất bại" })); } } else { return(Json(new { status = false, msg = msgValid })); } } catch (Exception ex) { // chuyển sang page ERR return(RedirectToAction("Index", "Error")); } }
private static string SetupCategoryRelation(string categoryId, string catalogId, ICatalogRepository repository, Item item) { var retVal = string.Empty; if (categoryId != null) { var category = repository.Categories.Where( cat => cat.CatalogId == catalogId && (cat.CategoryId == categoryId || cat.Code == categoryId)) .FirstOrDefault(); if (category != null) { var relation = new CatalogEntityFactory().CreateEntity <CategoryItemRelation>(); relation.CatalogId = catalogId; relation.ItemId = item.ItemId; relation.CategoryId = category.CategoryId; repository.Add(relation); } else { retVal = string.Format(noCategoryError, categoryId, item.Code); } } return(retVal); }
/// <summary> /// Registers the new shard and add tenant details to Tenants table in catalog /// </summary> /// <param name="tenantId">The tenant identifier.</param> /// <param name="databaseServerPort">The database server port.</param> /// <param name="servicePlan">The service plan.</param> /// <param name="shard">The shard which needs to be registered.</param> /// <returns></returns> public static async Task <bool> RegisterNewShard(int tenantId, string servicePlan, Shard shard) { try { // Register the mapping of the tenant to the shard in the shard map. // After this step, DDR on the shard map can be used PointMapping <int> mapping; if (!ShardMap.TryGetMappingForKey(tenantId, out mapping)) { var pointMapping = ShardMap.CreatePointMapping(tenantId, shard); //convert from int to byte[] as tenantId has been set as byte[] in Tenants entity var key = _utilities.ConvertIntKeyToBytesArray(pointMapping.Value); //get tenant's venue name var venueDetails = await _tenantRepository.GetVenueDetails(tenantId); //add tenant to Tenants table var tenant = new Tenants { ServicePlan = servicePlan, TenantId = key, TenantName = venueDetails.VenueName }; _catalogRepository.Add(tenant); } return(true); } catch (Exception exception) { Trace.TraceError(exception.Message, "Error in registering new shard."); return(false); } }
public async Task CreateCatalogAsync(CatalogDto catalogDto) { Catalog catalog = _mapper.Map <Catalog>(catalogDto); _repository.Add(catalog); await _context.SaveChangesAsync(); }
public CatalogRepositoryTests() { //var mockCatalogRepo = new Mock<ICatalogRepository>(); //mockCatalogRepo.Setup(repo => repo.GetAllTenantsAsync()).Returns(GetAllTenants()); //mockCatalogRepo.Setup(repo => repo.GetTenantAsync("tenantName")).Returns(GetTenantModel()); _catalogRepository = new MockCatalogRepository(); _catalogRepository.Add(SetTenant()); }
public void Init() { items[0] = UnitFactory.CreateBook(); items[1] = UnitFactory.CreateBook(); items[2] = UnitFactory.CreateNewsPaper(); items[3] = UnitFactory.CreatePatent(); for (var i = 0; i < items.Length; i++) { catalogRepository.Add(items[i]); } }
/// <summary> /// Registers the new shard. /// Verify if shard exists for the tenant. If not then create new shard and add tenant details to Tenants table in catalog /// </summary> /// <param name="tenantName">Name of the tenant.</param> /// <param name="tenantId">The tenant identifier.</param> /// <param name="tenantServer">The tenant server.</param> /// <param name="databaseServerPort">The database server port.</param> /// <param name="servicePlan">The service plan.</param> /// <returns></returns> public static async Task <bool> RegisterNewShard(string tenantName, int tenantId, string tenantServer, int databaseServerPort, string servicePlan) { try { Shard shard; ShardLocation shardLocation = new ShardLocation(tenantServer, tenantName, SqlProtocol.Tcp, databaseServerPort); if (!ShardMap.TryGetShard(shardLocation, out shard)) { //create shard if it does not exist shard = ShardMap.CreateShard(shardLocation); } // Register the mapping of the tenant to the shard in the shard map. // After this step, DDR on the shard map can be used PointMapping <int> mapping; if (!ShardMap.TryGetMappingForKey(tenantId, out mapping)) { var pointMapping = ShardMap.CreatePointMapping(tenantId, shard); //convert from int to byte[] as tenantId has been set as byte[] in Tenants entity var key = _utilities.ConvertIntKeyToBytesArray(pointMapping.Value); //get tenant's venue name var venueDetails = await _tenantRepository.GetHotelDetailsAsync(tenantId); //add tenant to Tenants table var tenant = new Tenants { ServicePlan = servicePlan, TenantId = key, TenantName = venueDetails.HotelName, RecoveryState = "n/a", LastUpdated = DateTime.Now }; _catalogRepository.Add(tenant); } return(true); } catch (Exception exception) { Trace.TraceError(exception.Message, "Error in registering new shard."); return(false); } }
public async Task <ServiceResponse <CatalogDto> > CreateCatalogAsync(CatalogDto catalogDto) { ServiceResponse <CatalogDto> serviceResponse = new ServiceResponse <CatalogDto>(); Catalog catalog = _mapper.Map <Catalog>(catalogDto); if (await _repository.HasChildWithNameAsync(catalog)) { serviceResponse.Success = false; serviceResponse.Message = $"The catalog with a name {catalogDto.Name} already exists"; return(serviceResponse); } _repository.Add(catalog); await _context.SaveChangesAsync(); serviceResponse.Data = catalogDto; return(serviceResponse); }
public IActionResult CreatePolicy([FromBody] PolicyDto dto) { if (!this.ModelState.IsValid) { return(BadRequest()); } CatalogPolicy policy = dto.ToPolicy(); if (_policyRepository.Get(policy.Number) != null) { return(Conflict()); } _policyRepository.Add(policy); CatalogPolicy p = _policyRepository.Get(policy.Number); return(Ok(p.ToDto())); }
public async Task <bool> Handle(AddCatalogCommand request, CancellationToken cancellationToken) { _catalogRepository.ValidateAddCatalogCommand(request); // TODO: save picture and return url var catalog = new DataLayer.DatabaseModels.Catalog { CatalogTypeId = request.CatalogTypeId, CatalogBrandId = request.CatalogBrandId, Name = request.Name, AvailableStock = request.AvailableStock, Description = request.Description, Price = request.Price, Status = CatalogStatus.Active }; _catalogRepository.Add(catalog); return(await _catalogRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken)); }
public Catalog Add(Catalog catalog) { return(_catalogRepository.Add(catalog)); }
public override string Import(string containerId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ICatalogRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); var taxCategory = systemValues.SingleOrDefault(x => x.Name == "TaxCategory") != null?systemValues.Single(x => x.Name == "TaxCategory").Value : null; var categoryId = systemValues.SingleOrDefault(x => x.Name == "CategoryId") != null?systemValues.Single(x => x.Name == "CategoryId").Value : null; var itemCode = systemValues.SingleOrDefault(x => x.Name == "Code") != null?systemValues.Single(x => x.Name == "Code").Value : null; var availability = systemValues.SingleOrDefault(x => x.Name == "AvailabilityRule") != null?systemValues.Single(x => x.Name == "AvailabilityRule").Value : null; if (availability != null) { var number = (int)((AvailabilityRule)Enum.Parse(typeof(AvailabilityRule), availability)); systemValues.SingleOrDefault(x => x.Name == "AvailabilityRule").Value = number.ToString(); } switch (action) { case ImportAction.Insert: if (_repository.Items.Where(item => item.CatalogId == containerId && item.Code == itemCode).FirstOrDefault() != null) { _error = string.Format("Item with the code {0} already exist", itemCode); } else { var addItem = SetupItem(null, containerId, propertySetId, systemValues, customValues, _repository, taxCategory); _repository.Add(addItem); _error = SetupCategoryRelation(categoryId, containerId, _repository, addItem); } break; case ImportAction.InsertAndReplace: if (itemCode != null) { var originalItem = _repository.Items.Where(i => i.CatalogId == containerId && i.Code == itemCode).Expand(x => x.CategoryItemRelations).FirstOrDefault(); if (originalItem != null) { originalItem = SetupItem(originalItem, containerId, propertySetId, systemValues, customValues, _repository, taxCategory); _repository.Update(originalItem); if (originalItem.CategoryItemRelations.All(rel => rel.CategoryId != categoryId)) { _error = SetupCategoryRelation(categoryId, containerId, _repository, originalItem); } } else { var newItem = SetupItem(null, containerId, propertySetId, systemValues, customValues, _repository, taxCategory); _repository.Add(newItem); _error = SetupCategoryRelation(categoryId, containerId, _repository, newItem); } } break; case ImportAction.Update: if (itemCode != null) { var origItem = _repository.Items.FirstOrDefault(i => i.CatalogId == containerId && i.Code == itemCode); if (origItem != null) { SetupItem(origItem, containerId, propertySetId, systemValues, customValues, _repository, taxCategory); _repository.Update(origItem); } } break; case ImportAction.Delete: if (itemCode != null) { var deleteItem = _repository.Items.Where(i => i.CatalogId == containerId && i.Code == itemCode).SingleOrDefault(); if (deleteItem != null) { _repository.Remove(deleteItem); } } break; } return(_error); }
private static string SetupCategoryRelation(string categoryId, string catalogId, ICatalogRepository repository, Item item) { var retVal = string.Empty; if (categoryId != null) { var category = repository.Categories.Where( cat => cat.CatalogId == catalogId && (cat.CategoryId == categoryId || cat.Code == categoryId)) .FirstOrDefault(); if (category != null) { var relation = new CatalogEntityFactory().CreateEntity<CategoryItemRelation>(); relation.CatalogId = catalogId; relation.ItemId = item.ItemId; relation.CategoryId = category.CategoryId; repository.Add(relation); } else { retVal = string.Format(noCategoryError, categoryId, item.Code); } } return retVal; }
public override string Import(string containerId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ICatalogRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); var taxCategory = systemValues.SingleOrDefault(x => x.Name == "TaxCategory") != null ? systemValues.Single(x => x.Name == "TaxCategory").Value : null; var categoryId = systemValues.SingleOrDefault(x => x.Name == "CategoryId") != null ? systemValues.Single(x => x.Name == "CategoryId").Value : null; var itemCode = systemValues.SingleOrDefault(x => x.Name == "Code") != null ? systemValues.Single(x => x.Name == "Code").Value : null; var availability = systemValues.SingleOrDefault(x => x.Name == "AvailabilityRule") != null ? systemValues.Single(x => x.Name == "AvailabilityRule").Value : null; if (availability != null) { var number = (int)((AvailabilityRule)Enum.Parse(typeof(AvailabilityRule), availability)); systemValues.SingleOrDefault(x => x.Name == "AvailabilityRule").Value = number.ToString(); } switch (action) { case ImportAction.Insert: if (_repository.Items.Where(item => item.CatalogId == containerId && item.Code == itemCode).FirstOrDefault() != null) { _error = string.Format("Item with the code {0} already exist", itemCode); } else { var addItem = SetupItem(null, containerId, propertySetId, systemValues, customValues, _repository, taxCategory); _repository.Add(addItem); _error = SetupCategoryRelation(categoryId, containerId, _repository, addItem); } break; case ImportAction.InsertAndReplace: if (itemCode != null) { var originalItem = _repository.Items.Where(i => i.CatalogId == containerId && i.Code == itemCode).Expand(x => x.CategoryItemRelations).FirstOrDefault(); if (originalItem != null) { originalItem = SetupItem(originalItem, containerId, propertySetId, systemValues, customValues, _repository, taxCategory); _repository.Update(originalItem); if (originalItem.CategoryItemRelations.All(rel => rel.CategoryId != categoryId)) _error = SetupCategoryRelation(categoryId, containerId, _repository, originalItem); } else { var newItem = SetupItem(null, containerId, propertySetId, systemValues, customValues, _repository, taxCategory); _repository.Add(newItem); _error = SetupCategoryRelation(categoryId, containerId, _repository, newItem); } } break; case ImportAction.Update: if (itemCode != null) { var origItem = _repository.Items.FirstOrDefault(i => i.CatalogId == containerId && i.Code == itemCode); if (origItem != null) { SetupItem(origItem, containerId, propertySetId, systemValues, customValues, _repository, taxCategory); _repository.Update(origItem); } } break; case ImportAction.Delete: if (itemCode != null) { var deleteItem = _repository.Items.Where(i => i.CatalogId == containerId && i.Code == itemCode).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); } break; } return _error; }
// ============ Methods to CREATE something ============ /** * Method that will validate and create a new catalog in the database. * * Validations performed: * 1. Validation of the new catalog's reference (business rules); * 2. Validation of the new catalog's reference (database); * 3. Validation of the received info. (name, description) (business rules) * 4. The received CatalogProductCollection list has 1 or more elements. * FOREACH RECEIVED CatalogProductCollection { * 5. Validation of the collection's reference in ProductCollection of current CatalogProductCollection (database); * 6. Validation of the configured product's reference in ProductCollection of current CatalogProductCollection (database); * 7. Validation to assert whether the indicated configured product actually belongs to the indicated collection (ProductCollection in current CatalogProductCollection) * 8. Validation for duplication between each CatalogProductCollection * } */ public ValidationOutput Register(CatalogDto dto) { //1. ValidationOutput validationOutput = _catalogDTOValidator.DTOReferenceIsValid(dto.Reference); if (validationOutput.HasErrors()) { return(validationOutput); } //2. validationOutput = new ValidationOutputBadRequest(); if (CatalogExists(dto.Reference)) { validationOutput.AddError("Reference of catalog", "A catalog with the reference '" + dto.Reference + "' already exists in the system!"); return(validationOutput); } //3. validationOutput = _catalogDTOValidator.DTOIsValidForRegister(dto); if (validationOutput.HasErrors()) { return(validationOutput); } //4. validationOutput = new ValidationOutputBadRequest(); /*if (dto.CatalogProductCollectionList.Count == 0) * { * validationOutput.AddError("Selected 'configured product - collection' items", "No 'configured product - collection' items were selected!"); * return validationOutput; * }*/ if (dto.CatalogProductCollectionList.Count > 0) { List <ProductCollection> productCollectionListToAdd = new List <ProductCollection>(); foreach (var currentCatalogProductCollectionDto in dto.CatalogProductCollectionList) { ProductCollectionDto productCollectionDto = currentCatalogProductCollectionDto.ProductCollection; //Just to simplify the code //5. validationOutput = new ValidationOutputNotFound(); if (!CollectionExists(productCollectionDto.CollectionReference)) { validationOutput.AddError("Reference of collection of a 'configured product - collection' item", "No collection with the reference '" + productCollectionDto.CollectionReference + "' exists in the system."); return(validationOutput); } //6. if (!ConfiguredProductExists(productCollectionDto.ConfiguredProductReference)) { validationOutput.AddError( "Reference of configured product of a 'configured product - collection' item", "No configured product with the reference '" + productCollectionDto.ConfiguredProductReference + "' exists in the system."); return(validationOutput); } Collection currentCollection = _collectionRepository.GetByReference(productCollectionDto.CollectionReference); //7. validationOutput = new ValidationOutputBadRequest(); if (!currentCollection.ConfiguredProductIsInCollection(productCollectionDto .ConfiguredProductReference)) { validationOutput.AddError("'Configured product - collection' item", "The configured product with reference '" + productCollectionDto.ConfiguredProductReference + "' does not belong to the collection with reference '" + productCollectionDto.ConfiguredProductReference + "'."); return(validationOutput); } ProductCollection currentProdCollection = _mapper.Map <ProductCollection>(productCollectionDto); //8. if (productCollectionListToAdd.Contains(currentProdCollection)) { validationOutput.AddError("'Configured product - collection' item", "'Configured product - collection' item with configured product '" + currentProdCollection.ConfiguredProductReference + "' that is associated with the collection '" + currentProdCollection.CollectionReference + "' is duplicated in the list of selected 'configured product - collection' items!"); return(validationOutput); } productCollectionListToAdd.Add(currentProdCollection); } } Catalog catalogToRegister = _mapper.Map <Catalog>(dto); validationOutput.DesiredReturn = _mapper.Map <CatalogDto>(_catalogRepository.Add(catalogToRegister)); return(validationOutput); }
public async void AddCatalog() { if (!ValidateUrl()) { return; } try { StartBusiness(); var catalogModel = await _dataGateway.GetCatalogInfo(CatalogUrl); if (catalogModel == null) { return; } try { if (string.IsNullOrEmpty(catalogModel.SearchUrl)) { if (!string.IsNullOrEmpty(catalogModel.OpenSearchDescriptionUrl)) { var openSearchDescription = await _dataGateway.GetOpenSearchDescriptionModel(catalogModel.OpenSearchDescriptionUrl, catalogModel.Url); if (openSearchDescription != null && !string.IsNullOrEmpty(openSearchDescription.SearchTemplateUrl)) { catalogModel.SearchUrl = openSearchDescription.SearchTemplateUrl; } } } } catch { catalogModel.SearchUrl = string.Empty; } var catalogs = _catalogRepository.GetAll(); if (catalogs.Any(c => !string.IsNullOrEmpty(c.Url) && c.Url.Equals(_catalogUrl))) { _notificationsService.ShowAlert(UINotifications.General_AttentionCaption, UINotifications.AddCatalogPage_CatalogAlreadyExists); return; } catalogModel.Type = CatalogType.OPDS; _catalogRepository.Add(catalogModel); _notificationsService.ShowAlert(UINotifications.General_AttentionCaption, UINotifications.AddCatalogPage_CatalogAddedSuccess); _navigationService.GoBack(); } catch (DataCorruptedException) { AddCatalog(); } catch (Exception exception) { _errorHandler.Handle(exception); } finally { StopBusiness(); } }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ICatalogRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); var itemCode = systemValues.SingleOrDefault(y => y.Name == "Code") != null ? systemValues.Single(y => y.Name == "Code").Value : null; var parentCategoryCode = systemValues.SingleOrDefault(val => val.Name == "ParentCategoryId") != null ? systemValues.Single(val => val.Name == "ParentCategoryId").Value : null; var parentCategory = _repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == parentCategoryCode).FirstOrDefault(); //if action is not delete and parent category code provided is not null and there is no category with the code in repository return error if (action != ImportAction.Delete && !string.IsNullOrEmpty(parentCategoryCode) && parentCategory == null) { _error = string.Format("Parent category with the code {0} does not exist", parentCategoryCode); } else { switch (action) { case ImportAction.Insert: //if there is already category with the same code - return error if (_repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == itemCode).FirstOrDefault() != null) { _error = string.Format("Category with the code {0} already exist", itemCode); } else { var addItem = InitializeItem(null, systemValues); addItem.ParentCategoryId = !string.IsNullOrEmpty(parentCategoryCode) ? parentCategory.CategoryId : null; addItem.CatalogId = catalogId; addItem.PropertySetId = propertySetId; _repository.Add(addItem); var propSet = _repository.PropertySets.Expand("PropertySetProperties/Property/PropertyValues") .Where(x => x.PropertySetId == propertySetId) .SingleOrDefault(); if (propSet != null) { var resProps = InitializeProperties(propSet.PropertySetProperties.ToArray(), customValues, addItem.CategoryId); resProps.ForEach(_repository.Add); } } break; case ImportAction.InsertAndReplace: if (itemCode != null) { var originalItem = _repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == itemCode).FirstOrDefault(); if (originalItem != null) { InitializeItem((Category)originalItem, systemValues); originalItem.ParentCategoryId = !string.IsNullOrEmpty(parentCategoryCode) ? parentCategory.CategoryId : null; _repository.Update(originalItem); } else { var addItem = InitializeItem(null, systemValues); addItem.ParentCategoryId = !string.IsNullOrEmpty(parentCategoryCode) ? parentCategory.CategoryId : null; addItem.CatalogId = catalogId; addItem.PropertySetId = propertySetId; _repository.Add(addItem); var propSet = _repository.PropertySets.Expand("PropertySetProperties/Property/PropertyValues") .Where(x => x.PropertySetId == propertySetId) .SingleOrDefault(); if (propSet != null) { var resProps = InitializeProperties(propSet.PropertySetProperties.ToArray(), customValues, addItem.CategoryId); resProps.ForEach(_repository.Add); } } } break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "Code"); if (itemU != null) { var origItem = _repository.Categories.Where(x => x.CategoryId == itemU.Value).SingleOrDefault(); if (origItem != null) { InitializeItem((Category) origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var deleteItem = _repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == itemCode).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); break; } } return _error; }
public void Add(CatalogEntry entry) { _catalogRepository.Add(entry); }
public void Setup() { _catalogRepository = new MockCatalogRepository(); _catalogRepository.Add(SetTenant()); }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ICatalogRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); var itemCode = systemValues.SingleOrDefault(y => y.Name == "Code") != null?systemValues.Single(y => y.Name == "Code").Value : null; var parentCategoryCode = systemValues.SingleOrDefault(val => val.Name == "ParentCategoryId") != null?systemValues.Single(val => val.Name == "ParentCategoryId").Value : null; var parentCategory = _repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == parentCategoryCode).FirstOrDefault(); //if action is not delete and parent category code provided is not null and there is no category with the code in repository return error if (action != ImportAction.Delete && !string.IsNullOrEmpty(parentCategoryCode) && parentCategory == null) { _error = string.Format("Parent category with the code {0} does not exist", parentCategoryCode); } else { switch (action) { case ImportAction.Insert: //if there is already category with the same code - return error if (_repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == itemCode).FirstOrDefault() != null) { _error = string.Format("Category with the code {0} already exist", itemCode); } else { var addItem = InitializeItem(null, systemValues); addItem.ParentCategoryId = !string.IsNullOrEmpty(parentCategoryCode) ? parentCategory.CategoryId : null; addItem.CatalogId = catalogId; addItem.PropertySetId = propertySetId; _repository.Add(addItem); var propSet = _repository.PropertySets.Expand("PropertySetProperties/Property/PropertyValues") .Where(x => x.PropertySetId == propertySetId) .SingleOrDefault(); if (propSet != null) { var resProps = InitializeProperties(propSet.PropertySetProperties.ToArray(), customValues, addItem.CategoryId); resProps.ForEach(_repository.Add); } } break; case ImportAction.InsertAndReplace: if (itemCode != null) { var originalItem = _repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == itemCode).FirstOrDefault(); if (originalItem != null) { InitializeItem((Category)originalItem, systemValues); originalItem.ParentCategoryId = !string.IsNullOrEmpty(parentCategoryCode) ? parentCategory.CategoryId : null; _repository.Update(originalItem); } else { var addItem = InitializeItem(null, systemValues); addItem.ParentCategoryId = !string.IsNullOrEmpty(parentCategoryCode) ? parentCategory.CategoryId : null; addItem.CatalogId = catalogId; addItem.PropertySetId = propertySetId; _repository.Add(addItem); var propSet = _repository.PropertySets.Expand("PropertySetProperties/Property/PropertyValues") .Where(x => x.PropertySetId == propertySetId) .SingleOrDefault(); if (propSet != null) { var resProps = InitializeProperties(propSet.PropertySetProperties.ToArray(), customValues, addItem.CategoryId); resProps.ForEach(_repository.Add); } } } break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "Code"); if (itemU != null) { var origItem = _repository.Categories.Where(x => x.CategoryId == itemU.Value).SingleOrDefault(); if (origItem != null) { InitializeItem((Category)origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var deleteItem = _repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == itemCode).SingleOrDefault(); if (deleteItem != null) { _repository.Remove(deleteItem); } break; } } return(_error); }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ICatalogRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); switch (action) { case ImportAction.Insert: var group = systemValues.First(y => y.Name == "GroupName").Value; var target = systemValues.First(y => y.Name == "TargetId").Value; var source = systemValues.First(y => y.Name == "ItemId").Value; var sourceItems = _repository.Items.Where(x => x.ItemId == source || x.Code == source).ToList(); Item sourceItem; //aa: below condition checks if more than 1 item found - catalogId should be provided and item of the catalog selected, otherwise return error if (sourceItems.Count() > 1) { var sourceCatName = systemValues.First(y => y.Name == "SourceCatalogId").Value; if (!string.IsNullOrEmpty(sourceCatName)) catalogId = _repository.Catalogs.Where(cat => cat.Name == sourceCatName).First().CatalogId; if (!string.IsNullOrEmpty(catalogId)) sourceItem = sourceItems.FirstOrDefault(x => x.CatalogId == catalogId); else { var catNames = string.Empty; sourceItems.ForEach(x => catNames = catNames + x.CatalogId + ", "); _error = string.Format(notUniqueSourceError, source, catNames); return _error; } } //aa: if 1 item found set it to sourceItem and go further else { sourceItem = sourceItems.FirstOrDefault(); } var targetItems = _repository.Items.Where(x => x.ItemId == target || x.Code == target).ToList(); Item targetItem; //aa: below condition checks if more than 1 item found - catalogId should be provided and item of the catalog selected, otherwise return error if (targetItems.Count() > 1) { var targetCatName = systemValues.First(y => y.Name == "TargetCatalogId").Value; if (!string.IsNullOrEmpty(targetCatName)) catalogId = _repository.Catalogs.Where(cat => cat.Name == targetCatName).First().CatalogId; if (!string.IsNullOrEmpty(catalogId)) targetItem = targetItems.FirstOrDefault(x => x.CatalogId == catalogId); else { var catNames = string.Empty; targetItems.ForEach(x => catNames = catNames + x.CatalogId + ", "); _error = string.Format(notUniqueTargetError, target, catNames); return _error; } } //aa: if 1 item found set it to sourceItem and go further else { targetItem = targetItems.FirstOrDefault(); } if (!string.IsNullOrEmpty(group) && targetItem != null && sourceItem != null) { var associationGroup = _repository.Associations.Where(x => x.AssociationGroup.Name == group && x.ItemId == targetItem.ItemId).SingleOrDefault(); string groupId; if (associationGroup == null) { var addGroup = new AssociationGroup() { ItemId = targetItem.ItemId, Name = group }; _repository.Add(addGroup); groupId = addGroup.AssociationGroupId; } else { groupId = associationGroup.AssociationGroupId; } var addItem = InitializeItem(null, systemValues); ((Association)addItem).AssociationGroupId = groupId; ((Association)addItem).ItemId = sourceItem.ItemId; _repository.Add(addItem); } else { _error = "Not all required data provided"; } break; case ImportAction.InsertAndReplace: var itemR = systemValues.FirstOrDefault(y => y.Name == "AssociationId"); if (itemR != null) { var originalItem = _repository.Associations.Where(x => x.ItemId == itemR.Value).SingleOrDefault(); if (originalItem != null) repository.Remove(originalItem); } var replaceItem = InitializeItem(null, systemValues); repository.Add(replaceItem); break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "AssociationId"); if (itemU != null) { var origItem = _repository.Associations.Where(x => x.ItemId == itemU.Value).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var itemD = systemValues.FirstOrDefault(y => y.Name == "AssociationId"); if (itemD != null) { var deleteItem = _repository.Associations.Where(x => x.ItemId == itemD.Value).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); } break; } return _error; }
public void AddTenantTest() { var result = _catalogRepository.Add(SetTenant()); Assert.IsTrue(result); }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ICatalogRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); switch (action) { case ImportAction.Insert: var group = systemValues.First(y => y.Name == "GroupName").Value; var child = systemValues.First(y => y.Name == "ChildId").Value; var parent = systemValues.First(y => y.Name == "ParentId").Value; var sourceItems = _repository.Items.Where(x => x.ItemId == parent || x.Code == parent).ToList(); Item sourceItem; //aa: below condition checks if more than 1 item found - catalogId should be provided and item of the catalog selected, otherwise return error if (sourceItems.Count() > 1) { var sourceCatName = systemValues.First(y => y.Name == "SourceCatalogId").Value; if (!string.IsNullOrEmpty(sourceCatName)) { catalogId = _repository.Catalogs.Where(cat => cat.Name == sourceCatName).First().CatalogId; } if (!string.IsNullOrEmpty(catalogId)) { sourceItem = sourceItems.FirstOrDefault(x => x.CatalogId == catalogId); } else { var catNames = string.Empty; sourceItems.ForEach(x => catNames = catNames + x.CatalogId + ", "); _error = string.Format(notUniqueSourceError, parent, catNames); return(_error); } } //aa: if 1 item found set it to sourceItem and go further else { sourceItem = sourceItems.FirstOrDefault(); } var targetItems = _repository.Items.Where(x => x.ItemId == child || x.Code == child).ToList(); Item targetItem; //aa: below condition checks if more than 1 item found - catalogId should be provided and item of the catalog selected, otherwise return error if (targetItems.Count() > 1) { var targetCatName = systemValues.First(y => y.Name == "TargetCatalogId").Value; if (!string.IsNullOrEmpty(targetCatName)) { catalogId = _repository.Catalogs.Where(cat => cat.Name == targetCatName).First().CatalogId; } if (!string.IsNullOrEmpty(catalogId)) { targetItem = targetItems.FirstOrDefault(x => x.CatalogId == catalogId); } else { var catNames = string.Empty; targetItems.ForEach(x => catNames = catNames + x.CatalogId + ", "); _error = string.Format(notUniqueTargetError, child, catNames); return(_error); } } //aa: if 1 item found set it to sourceItem and go further else { targetItem = targetItems.FirstOrDefault(); } if (!string.IsNullOrEmpty(group) && targetItem != null && sourceItem != null) { var addItem = InitializeItem(null, systemValues); ((ItemRelation)addItem).GroupName = group; ((ItemRelation)addItem).ParentItemId = sourceItem.ItemId; ((ItemRelation)addItem).ChildItemId = targetItem.ItemId; _repository.Add(addItem); } else { _error = "Not all required data provided"; } break; case ImportAction.InsertAndReplace: var itemR = systemValues.FirstOrDefault(y => y.Name == "ItemRelationId"); if (itemR != null) { var originalItem = _repository.Associations.Where(x => x.ItemId == itemR.Value).SingleOrDefault(); if (originalItem != null) { repository.Remove(originalItem); } } var replaceItem = InitializeItem(null, systemValues); repository.Add(replaceItem); break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "ItemRelationId"); if (itemU != null) { var origItem = _repository.ItemRelations.Where(x => x.ItemRelationId == itemU.Value).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var itemD = systemValues.FirstOrDefault(y => y.Name == "ItemRelationId"); if (itemD != null) { var deleteItem = _repository.ItemRelations.Where(x => x.ItemRelationId == itemD.Value).SingleOrDefault(); if (deleteItem != null) { _repository.Remove(deleteItem); } } break; } return(_error); }