public ProductRoutes(IProductService productSvc, IDestinationService destinationSvc) : base("v1") { this.RequiresAuthentication(); Get("/products", _ => { this.RequiresClaims(c => c.Type == HttpMethod.Get.Verb()); var tagParameter = (DynamicDictionaryValue)Request.Query["tags"]; var tags = ConvertParameterToTags(tagParameter); var products = (tagParameter.HasValue) ? productSvc.GetByTags(tags).ToViewModel <List <Product>, List <RQModel.Product> >() : productSvc.GetAll().ToViewModel <List <Product>, List <RQModel.Product> >(); return(products); }); Get("/product/{productId}/destinations", _ => { this.RequiresClaims(c => c.Type == HttpMethod.Get.Verb()); var destinations = destinationSvc .GetByProductId((Guid)_.productId) .ToViewModel <List <Destination>, List <ADModel.Destination> >(); return(destinations); }); Get("/product/mapping/{mappingId}/destinations", _ => { this.RequiresClaims(c => c.Type == HttpMethod.Get.Verb()); var destinations = destinationSvc .GetByMappingId((int)_.mappingId) .ToViewModel <List <Destination>, List <ADModel.Destination> >(); return(destinations); }); }
public string ImportCategory([FromBody] CategoryImportViewModel viewModel) { foreach (var category in viewModel.Categories) { category.Id = Guid.NewGuid().ToString(); } var destinations = _destinationSvc.GetByMappingId(viewModel.MappingId); foreach (var destination in destinations) { bool hasChanges = false; foreach (var category in viewModel.Categories) { if (!destination.Categories.Any(e => e.Name == category.Name)) { hasChanges = true; var newCategory = new Business.Modules.Destination.Model.Category { Name = category.Name, Brands = category.Brands, TitleIds = category.TitleIds }; destination.Categories.Add(newCategory); } } if (hasChanges) { _destinationSvc.Save(destination); } } return("Success"); }