public IActionResult CreateSpecificationAttribute([ModelBinder(typeof(JsonModelBinder <SpecificationAttributeDto>))] Delta <SpecificationAttributeDto> specificaitonAttributeDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } // Inserting the new product var specificationAttribute = new SpecificationAttribute(); specificaitonAttributeDelta.Merge(specificationAttribute); _specificationAttributeService.InsertSpecificationAttribute(specificationAttribute); UpdateLocalesSpecificationAttribute(specificationAttribute, specificaitonAttributeDelta.Dto.LocalizedNames); CustomerActivityService.InsertActivity("AddNewSpecAttribute", LocalizationService.GetResource("ActivityLog.AddNewSpecAttribute"), specificationAttribute); // Preparing the result dto of the new product var specificationAttributeDto = _dtoHelper.PrepareSpecificationAttributeDto(specificationAttribute); var specificationAttributesRootObjectDto = new SpecificationAttributesRootObjectDto(); specificationAttributesRootObjectDto.SpecificationAttributes.Add(specificationAttributeDto); var json = JsonFieldsSerializer.Serialize(specificationAttributesRootObjectDto, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult UpdateVendor([ModelBinder(typeof(JsonModelBinder <VendorDto>))] Delta <VendorDto> vendorDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var vendor = _vendorApiService.GetVendorById(vendorDelta.Dto.Id); if (vendor == null) { return(Error(HttpStatusCode.NotFound, "Vendor", "not found")); } vendorDelta.Merge(vendor); //Vendor.UpdatedOnUtc = DateTime.UtcNow; _vendorService.UpdateVendor(vendor); UpdatePicture(vendor, vendorDelta.Dto.Image); //UpdateVendorAttributes(Vendor, VendorDelta); //UpdateVendorPictures(Vendor, VendorDelta.Dto.Images); //UpdateVendorTags(Vendor, VendorDelta.Dto.Tags); //UpdateVendorManufacturers(Vendor, VendorDelta.Dto.ManufacturerIds); //UpdateAssociatedVendors(Vendor, VendorDelta.Dto.AssociatedVendorIds); // Update the SeName if specified //if (VendorDelta.Dto.SeName != null) //{ // var seName = _urlRecordService.ValidateSeName(Vendor, VendorDelta.Dto.SeName, Vendor.Name, true); // _urlRecordService.SaveSlug(Vendor, seName, 0); //} //UpdateDiscountMappings(Vendor, VendorDelta.Dto.DiscountIds); //UpdateStoreMappings(Vendor, VendorDelta.Dto.StoreIds); //UpdateAclRoles(Vendor, VendorDelta.Dto.RoleIds); _vendorService.UpdateVendor(vendor); CustomerActivityService.InsertActivity("UpdateVendor", LocalizationService.GetResource("ActivityLog.UpdateVendor"), vendor); // Preparing the result dto of the new Vendor var vendorDto = _dtoHelper.PrepareVendorDTO(vendor); var vendorsRootObject = new VendorsRootObjectDto(); vendorsRootObject.Vendors.Add(vendorDto); var json = JsonFieldsSerializer.Serialize(vendorsRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult UpdateProductSpecificationAttribute([ModelBinder(typeof(JsonModelBinder <ProductSpecificationAttributeDto>))] Delta <ProductSpecificationAttributeDto> productSpecificationAttributeDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } // We do not need to validate the product attribute id, because this will happen in the model binder using the dto validator. int productSpecificationAttributeId = productSpecificationAttributeDelta.Dto.Id; var productSpecificationAttribute = _specificationAttributeService.GetProductSpecificationAttributeById(productSpecificationAttributeId); if (productSpecificationAttribute == null) { return(Error(HttpStatusCode.NotFound, "product specification attribute", "not found")); } productSpecificationAttributeDelta.Merge(productSpecificationAttribute); _specificationAttributeService.UpdateProductSpecificationAttribute(productSpecificationAttribute); CustomerActivityService.InsertActivity("EditProductSpecificationAttribute", productSpecificationAttribute.Id.ToString()); // Preparing the result dto of the new product attribute var productSpecificationAttributeDto = _dtoHelper.PrepareProductSpecificationAttributeDto(productSpecificationAttribute); var productSpecificatoinAttributesRootObjectDto = new ProductSpecificationAttributesRootObjectDto(); productSpecificatoinAttributesRootObjectDto.ProductSpecificationAttributes.Add(productSpecificationAttributeDto); var json = JsonFieldsSerializer.Serialize(productSpecificatoinAttributesRootObjectDto, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult UpdateProductFiles([ModelBinder(typeof(JsonModelBinder <ProductFilesDto>))] Delta <ProductFilesDto> productDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } CustomerActivityService.InsertActivity("APIService", "Starting Product Files Update", null); var product = _productApiService.GetProductById(productDelta.Dto.Id); if (product == null) { return(Error(HttpStatusCode.NotFound, "product", "not found")); } SaveFile(productDelta.Dto.SpecificationFileName, productDelta.Dto.Specification); SaveFile(productDelta.Dto.AccessoriesFileName, productDelta.Dto.Accessories); product.SpecificationFileName = productDelta.Dto.SpecificationFileName; product.AccessoriesFileName = productDelta.Dto.AccessoriesFileName; _productService.UpdateProduct(product); CustomerActivityService.InsertActivity("APIService", $"Update product: '{product.Sku}'", product); var result = new ProductFilesRootObjectDto(); return(new RawJsonActionResult(JsonFieldsSerializer.Serialize(result, string.Empty))); }
public IActionResult DeleteProduct(int id) { if (id <= 0) { return(Error(HttpStatusCode.BadRequest, "id", "invalid id")); } var product = _productApiService.GetProductById(id); if (product == null) { return(Error(HttpStatusCode.NotFound, "product", "not found")); } var genericAttribute = _genericAttributeService.GetAttributesForEntity(product.Id, "Product").FirstOrDefault(); if (genericAttribute != null) { _genericAttributeService.DeleteAttribute(genericAttribute); } _productService.DeleteProduct(product); //activity log CustomerActivityService.InsertActivity("DeleteProduct", string.Format(LocalizationService.GetResource("ActivityLog.DeleteProduct"), product.Name), product); return(new RawJsonActionResult("{}")); }
public IActionResult DeletePicture(int id) { if (id <= 0) { return(Error(HttpStatusCode.BadRequest, "id", "invalid id")); } CustomerActivityService.InsertActivity("APIService", string.Format("Attempting delete of picture {0}.", id), null); var productPicture = _productService.GetProductPictureById(id); if (productPicture == null) { return(Error(HttpStatusCode.NotFound, "product picture", "not found")); } var picture = PictureService.GetPictureById(productPicture.PictureId); if (picture == null) { return(Error(HttpStatusCode.NotFound, "picture", "not found")); } _productService.DeleteProductPicture(productPicture); PictureService.DeletePicture(picture); CustomerActivityService.InsertActivity("APIService", string.Format("Deleted picture {0}.", picture.Id), picture); return(new RawJsonActionResult("{}")); }
public IActionResult UpdateProductAttribute([ModelBinder(typeof(JsonModelBinder <CustomeProductAttributes>))] Delta <CustomeProductAttributes> productAttributeDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var productAttribute = _productAttributesApiService.GetById(productAttributeDelta.Dto.Id); if (productAttribute == null) { return(Error(HttpStatusCode.NotFound, "product attribute", "not found")); } productAttributeDelta.Merge(productAttribute); _productAttributeService.UpdateProductAttribute(productAttribute); CustomerActivityService.InsertActivity("EditProductAttribute", LocalizationService.GetResource("ActivityLog.EditProductAttribute"), productAttribute); // Preparing the result dto of the new product attribute var productAttributeDto = _dtoHelper.PrepareProductAttributeDTO(productAttribute); var productAttributesRootObjectDto = new CustomeProductAttributesRootObjectDto(); productAttributesRootObjectDto.ProductAttributes.Add(productAttributeDto); var json = JsonFieldsSerializer.Serialize(productAttributesRootObjectDto, string.Empty); return(new RawJsonActionResult(json)); }
public async Task <IActionResult> CreateManufacturer( [ModelBinder(typeof(JsonModelBinder <ManufacturerDto>))] Delta <ManufacturerDto> manufacturerDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } //If the validation has passed the manufacturerDelta object won't be null for sure so we don't need to check for this. Picture insertedPicture = null; // We need to insert the picture before the manufacturer so we can obtain the picture id and map it to the manufacturer. if (manufacturerDelta.Dto.Image?.Binary != null) { insertedPicture = await PictureService.InsertPictureAsync(manufacturerDelta.Dto.Image.Binary, manufacturerDelta.Dto.Image.MimeType, string.Empty); } // Inserting the new manufacturer var manufacturer = await _factory.InitializeAsync(); manufacturerDelta.Merge(manufacturer); if (insertedPicture != null) { manufacturer.PictureId = insertedPicture.Id; } await _manufacturerService.InsertManufacturerAsync(manufacturer); await UpdateAclRolesAsync(manufacturer, manufacturerDelta.Dto.RoleIds); await UpdateDiscountsAsync(manufacturer, manufacturerDelta.Dto.DiscountIds); await UpdateStoreMappingsAsync(manufacturer, manufacturerDelta.Dto.StoreIds); //search engine name if (manufacturerDelta.Dto.SeName != null) { var seName = await _urlRecordService.ValidateSeNameAsync(manufacturer, manufacturerDelta.Dto.SeName, manufacturer.Name, true); await _urlRecordService.SaveSlugAsync(manufacturer, seName, 0); } await CustomerActivityService.InsertActivityAsync("AddNewManufacturer", await LocalizationService.GetResourceAsync("ActivityLog.AddNewManufacturer"), manufacturer); // Preparing the result dto of the new manufacturer var newManufacturerDto = await _dtoHelper.PrepareManufacturerDtoAsync(manufacturer); var manufacturersRootObject = new ManufacturersRootObject(); manufacturersRootObject.Manufacturers.Add(newManufacturerDto); var json = JsonFieldsSerializer.Serialize(manufacturersRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public async Task <IActionResult> CreateProductSpecificationAttribute( [ModelBinder(typeof(JsonModelBinder <ProductSpecificationAttributeDto>))] Delta <ProductSpecificationAttributeDto> productSpecificaitonAttributeDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } // Inserting the new product var productSpecificationAttribute = new ProductSpecificationAttribute(); productSpecificaitonAttributeDelta.Merge(productSpecificationAttribute); await _specificationAttributeService.InsertProductSpecificationAttributeAsync(productSpecificationAttribute); await CustomerActivityService.InsertActivityAsync("AddNewProductSpecificationAttribute", productSpecificationAttribute.Id.ToString()); // Preparing the result dto of the new product var productSpecificationAttributeDto = _dtoHelper.PrepareProductSpecificationAttributeDto(productSpecificationAttribute); var productSpecificationAttributesRootObjectDto = new ProductSpecificationAttributesRootObjectDto(); productSpecificationAttributesRootObjectDto.ProductSpecificationAttributes.Add(productSpecificationAttributeDto); var json = JsonFieldsSerializer.Serialize(productSpecificationAttributesRootObjectDto, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult CreateCategory( [ModelBinder(typeof(JsonModelBinder <CategoryDto>))] Delta <CategoryDto> categoryDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } //If the validation has passed the categoryDelta object won't be null for sure so we don't need to check for this. Picture insertedPicture = null; // We need to insert the picture before the category so we can obtain the picture id and map it to the category. if (categoryDelta.Dto.Image?.Binary != null) { insertedPicture = PictureService.InsertPicture(categoryDelta.Dto.Image.Binary, categoryDelta.Dto.Image.MimeType, string.Empty); } // Inserting the new category var category = _factory.Initialize(); categoryDelta.Merge(category); if (insertedPicture != null) { category.PictureId = insertedPicture.Id; } _categoryService.InsertCategory(category); UpdateAclRoles(category, categoryDelta.Dto.RoleIds); UpdateDiscounts(category, categoryDelta.Dto.DiscountIds); UpdateStoreMappings(category, categoryDelta.Dto.StoreIds); //search engine name if (categoryDelta.Dto.SeName != null) { var seName = _urlRecordService.ValidateSeName(category, categoryDelta.Dto.SeName, category.Name, true); _urlRecordService.SaveSlug(category, seName, 0); } CustomerActivityService.InsertActivity("AddNewCategory", LocalizationService.GetResource("ActivityLog.AddNewCategory"), category); // Preparing the result dto of the new category var newCategoryDto = _dtoHelper.PrepareCategoryDTO(category); var categoriesRootObject = new CategoriesRootObject(); categoriesRootObject.Categories.Add(newCategoryDto); var json = JsonFieldsSerializer.Serialize(categoriesRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult CreateProductAttribute([ModelBinder(typeof(JsonModelBinder <CustomeProductAttributes>))] Delta <CustomeProductAttributes> productAttributeDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } // Inserting the new product var productAttribute = new ProductAttribute(); productAttributeDelta.Merge(productAttribute); _productAttributeService.InsertProductAttribute(productAttribute); CustomerActivityService.InsertActivity("AddNewProductAttribute", LocalizationService.GetResource("ActivityLog.AddNewProductAttribute"), productAttribute); // Preparing the result dto of the new product var productAttributeDto = _dtoHelper.PrepareProductAttributeDTO(productAttribute); var productAttributesRootObjectDto = new CustomeProductAttributesRootObjectDto(); productAttributesRootObjectDto.ProductAttributes.Add(productAttributeDto); var json = JsonFieldsSerializer.Serialize(productAttributesRootObjectDto, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult CreateProductPicture([ModelBinder(typeof(JsonModelBinder <ImageMappingDto>))] Delta <ImageMappingDto> productPictureDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } CustomerActivityService.InsertActivity("APIService", string.Format("Attempting to create picture with name {0}.", productPictureDelta.Dto.SeoFilename), null); var newPicture = PictureService.InsertPicture(Convert.FromBase64String(productPictureDelta.Dto.Attachment), productPictureDelta.Dto.MimeType, productPictureDelta.Dto.SeoFilename); var productPicture = new ProductPicture() { PictureId = newPicture.Id, ProductId = productPictureDelta.Dto.ProductId, DisplayOrder = productPictureDelta.Dto.Position }; _productService.InsertProductPicture(productPicture); var product = _productService.GetProductById(productPictureDelta.Dto.ProductId); PictureService.SetSeoFilename(newPicture.Id, PictureService.GetPictureSeName(product.Name)); var productImagesRootObject = new ProductPicturesRootObjectDto(); productImagesRootObject.Image = _dtoHelper.PrepareProductPictureDTO(productPicture); var json = JsonFieldsSerializer.Serialize(productImagesRootObject, string.Empty); CustomerActivityService.InsertActivity("APIService", string.Format("Successfully created and returned image {0}.", productPictureDelta.Dto.SeoFilename), null); return(new RawJsonActionResult(json)); }
public IActionResult DeleteCustomer(int id) { if (id <= 0) { return(Error(HttpStatusCode.BadRequest, "id", "invalid id")); } var customer = _customerApiService.GetCustomerEntityById(id); if (customer == null) { return(Error(HttpStatusCode.NotFound, "customer", "not found")); } CustomerService.DeleteCustomer(customer); //remove newsletter subscription (if exists) foreach (var store in StoreService.GetAllStores()) { var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, store.Id); if (subscription != null) { _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription); } } //activity log CustomerActivityService.InsertActivity("DeleteCustomer", LocalizationService.GetResource("ActivityLog.DeleteCustomer"), customer); return(new RawJsonActionResult("{}")); }
public IActionResult UpdateProductRelations([ModelBinder(typeof(JsonModelBinder <ProductDto>))] Delta <ProductDto> productDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } CustomerActivityService.InsertActivity("APIService", "Starting Product Update", null); var product = _productApiService.GetProductById(productDelta.Dto.Id); if (product == null) { return(Error(HttpStatusCode.NotFound, "product", "not found")); } productDelta.Merge(product); UpdateAssociatedProducts(product, productDelta.Dto.AssociatedProductIds); CustomerActivityService.InsertActivity("APIService", LocalizationService.GetResource("ActivityLog.UpdateProduct"), product); // Preparing the result dto of the new product var productDto = _dtoHelper.PrepareProductDTO(product); var productsRootObject = new ProductsRootObjectDto(); productsRootObject.Products.Add(productDto); var json = JsonFieldsSerializer.Serialize(productsRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult UpdateProduct([ModelBinder(typeof(JsonModelBinder <ProductDto>))] Delta <ProductDto> productDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var product = _productApiService.GetProductById(productDelta.Dto.Id); if (product == null) { return(Error(HttpStatusCode.NotFound, "product", "not found")); } productDelta.Merge(product); product.UpdatedOnUtc = DateTime.UtcNow; _productService.UpdateProduct(product); UpdateProductAttributes(product, productDelta); UpdateProductPictures(product, productDelta.Dto.Images); UpdateProductTags(product, productDelta.Dto.Tags); UpdateProductManufacturers(product, productDelta.Dto.ManufacturerIds); UpdateAssociatedProducts(product, productDelta.Dto.AssociatedProductIds); // Update the SeName if specified if (productDelta.Dto.SeName != null) { var seName = _urlRecordService.ValidateSeName(product, productDelta.Dto.SeName, product.Name, true); _urlRecordService.SaveSlug(product, seName, 0); } UpdateDiscountMappings(product, productDelta.Dto.DiscountIds); UpdateStoreMappings(product, productDelta.Dto.StoreIds); UpdateAclRoles(product, productDelta.Dto.RoleIds); _productService.UpdateProduct(product); CustomerActivityService.InsertActivity("UpdateProduct", LocalizationService.GetResource("ActivityLog.UpdateProduct"), product); // Preparing the result dto of the new product var productDto = _dtoHelper.PrepareProductDTO(product); var productsRootObject = new ProductsRootObjectDto(); productsRootObject.Products.Add(productDto); var json = JsonFieldsSerializer.Serialize(productsRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult UpdateSpecificationAttribute([ModelBinder(typeof(JsonModelBinder <SpecificationAttributeDto>))] Delta <SpecificationAttributeDto> specificaitonAttributeDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var specificationAttribute = new SpecificationAttribute(); specificaitonAttributeDelta.Merge(specificationAttribute); if (specificationAttribute.Id <= 0) { _specificationAttributeService.InsertSpecificationAttribute(specificationAttribute); } var options = new List <SpecificationAttributeOption>(); if (specificaitonAttributeDelta.Dto.SpecificationAttributeOptions?.Any() == true) { var ix = 0; foreach (var option in specificaitonAttributeDelta.Dto.SpecificationAttributeOptions) { if (option.Id <= 0) { var opt = new SpecificationAttributeOption { Name = option.Name, SpecificationAttributeId = specificationAttribute.Id, DisplayOrder = ix }; ix++; _specificationAttributeService.InsertSpecificationAttributeOption(opt); options.Add(opt); } } } CustomerActivityService.InsertActivity("UpdateSpecAttribute", LocalizationService.GetResource("ActivityLog.AddNewSpecAttribute"), specificationAttribute); // Preparing the result dto of the new product var specificationAttributeDto = _dtoHelper.PrepareSpecificationAttributeDto(specificationAttribute); specificationAttributeDto.SpecificationAttributeOptions = new List <SpecificationAttributeOptionDto>(); foreach (var option in options) { specificationAttributeDto.SpecificationAttributeOptions.Add(_dtoHelper.PrepareSpecificationAttributeOptionDto(option)); } var specificationAttributesRootObjectDto = new SpecificationAttributesRootObjectDto(); specificationAttributesRootObjectDto.SpecificationAttributes.Add(specificationAttributeDto); var json = JsonFieldsSerializer.Serialize(specificationAttributesRootObjectDto, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult CreateProductCategoryMapping([ModelBinder(typeof(JsonModelBinder <ProductCategoryMappingDto>))] Delta <ProductCategoryMappingDto> productCategoryDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var category = _categoryApiService.GetCategoryById(productCategoryDelta.Dto.CategoryId.Value); if (category == null) { return(Error(HttpStatusCode.NotFound, "category_id", "not found")); } var product = _productApiService.GetProductById(productCategoryDelta.Dto.ProductId.Value); if (product == null) { return(Error(HttpStatusCode.NotFound, "product_id", "not found")); } var mappingsCount = _productCategoryMappingsService.GetMappingsCount(product.Id, category.Id); ProductCategory newProductCategory = new ProductCategory(); productCategoryDelta.Merge(newProductCategory); if (mappingsCount == 0) { _categoryService.InsertProductCategory(newProductCategory); CustomerActivityService.InsertActivity("AddNewProductCategoryMapping", LocalizationService.GetResource("ActivityLog.AddNewProductCategoryMapping"), newProductCategory); //return Error(HttpStatusCode.BadRequest, "product_category_mapping", "already exist"); } else { var mapping = _productCategoryMappingsService.GetMappings(product.Id, category.Id); newProductCategory.Id = mapping.FirstOrDefault().Id; } //inserting new category //_categoryService.InsertProductCategory(newProductCategory); // Preparing the result dto of the new product category mapping var newProductCategoryMappingDto = newProductCategory.ToDto(); var productCategoryMappingsRootObject = new ProductCategoryMappingsRootObject(); productCategoryMappingsRootObject.ProductCategoryMappingDtos.Add(newProductCategoryMappingDto); var json = JsonFieldsSerializer.Serialize(productCategoryMappingsRootObject, string.Empty); //activity log CustomerActivityService.InsertActivity("AddNewProductCategoryMapping", LocalizationService.GetResource("ActivityLog.AddNewProductCategoryMapping"), newProductCategory); return(new RawJsonActionResult(json)); }
public IActionResult UpdateProductManufacturerMapping( [ModelBinder(typeof(JsonModelBinder <ProductManufacturerMappingsDto>))] Delta <ProductManufacturerMappingsDto> productManufacturerDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } if (productManufacturerDelta.Dto.ManufacturerId.HasValue) { var Manufacturer = _manufacturerApiService.GetManufacturerById(productManufacturerDelta.Dto.ManufacturerId.Value); if (Manufacturer == null) { return(Error(HttpStatusCode.NotFound, "manufacturer_id", "not found")); } } if (productManufacturerDelta.Dto.ProductId.HasValue) { var product = _productApiService.GetProductById(productManufacturerDelta.Dto.ProductId.Value); if (product == null) { return(Error(HttpStatusCode.NotFound, "product_id", "not found")); } } // We do not need to validate the Manufacturer id, because this will happen in the model binder using the dto validator. var updateProductManufacturerId = productManufacturerDelta.Dto.Id; var productManufacturerEntityToUpdate = _manufacturerService.GetProductManufacturerById(updateProductManufacturerId); if (productManufacturerEntityToUpdate == null) { return(Error(HttpStatusCode.NotFound, "product_manufacturer_mapping", "not found")); } productManufacturerDelta.Merge(productManufacturerEntityToUpdate); _manufacturerService.UpdateProductManufacturer(productManufacturerEntityToUpdate); //activity log CustomerActivityService.InsertActivity("UpdateProdutManufacturerMapping", LocalizationService.GetResource("ActivityLog.UpdateProdutManufacturerMapping"), productManufacturerEntityToUpdate); var updatedProductManufacturerDto = productManufacturerEntityToUpdate.ToDto(); var productManufacturersRootObject = new ProductManufacturerMappingsRootObject(); productManufacturersRootObject.ProductManufacturerMappingsDtos.Add(updatedProductManufacturerDto); var json = JsonFieldsSerializer.Serialize(productManufacturersRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult UpdateCategory( [ModelBinder(typeof(JsonModelBinder <CategoryDto>))] Delta <CategoryDto> categoryDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var category = _categoryApiService.GetCategoryById(categoryDelta.Dto.Id); if (category == null) { return(Error(HttpStatusCode.NotFound, "category", "category not found")); } categoryDelta.Merge(category); category.UpdatedOnUtc = DateTime.UtcNow; _categoryService.UpdateCategory(category); UpdateLocales(category, categoryDelta.Dto.LocalizedNames); UpdatePicture(category, categoryDelta.Dto.Image); UpdateAclRoles(category, categoryDelta.Dto.RoleIds); UpdateDiscounts(category, categoryDelta.Dto.DiscountIds); UpdateStoreMappings(category, categoryDelta.Dto.StoreIds); //search engine name if (categoryDelta.Dto.SeName != null) { var seName = _urlRecordService.ValidateSeName(category, categoryDelta.Dto.SeName, category.Name, true); // Maybe languageid should just be 0 here ? _urlRecordService.SaveSlug(category, seName, 0); } _categoryService.UpdateCategory(category); CustomerActivityService.InsertActivity("UpdateCategory", LocalizationService.GetResource("ActivityLog.UpdateCategory"), category); var categoryDto = _dtoHelper.PrepareCategoryDTO(category); var categoriesRootObject = new CategoriesRootObject(); categoriesRootObject.Categories.Add(categoryDto); var json = JsonFieldsSerializer.Serialize(categoriesRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult CreateProduct([ModelBinder(typeof(JsonModelBinder <ProductDto>))] Delta <ProductDto> productDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } // Inserting the new product var product = _factory.Initialize(); productDelta.Merge(product); var vendor = _vendorApiService.GetVendorByName(productDelta.Dto.VName); if (vendor != null) { product.VendorId = vendor.Id; } _productService.InsertProduct(product); UpdateProductPictures(product, productDelta.Dto.Images); UpdateProductTags(product, productDelta.Dto.Tags); UpdateProductManufacturers(product, productDelta.Dto.ManufacturerIds); UpdateAssociatedProducts(product, productDelta.Dto.AssociatedProductIds); //search engine name var seName = _urlRecordService.ValidateSeName(product, productDelta.Dto.SeName, product.Name, true); _urlRecordService.SaveSlug(product, seName, 0); UpdateAclRoles(product, productDelta.Dto.RoleIds); UpdateDiscountMappings(product, productDelta.Dto.DiscountIds); UpdateStoreMappings(product, productDelta.Dto.StoreIds); _productService.UpdateProduct(product); CustomerActivityService.InsertActivity("AddNewProduct", LocalizationService.GetResource("ActivityLog.AddNewProduct"), product); // Preparing the result dto of the new product var productDto = _dtoHelper.PrepareProductDTO(product); var productsRootObject = new ProductsRootObjectDto(); productsRootObject.Products.Add(productDto); var json = JsonFieldsSerializer.Serialize(productsRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public async Task <IActionResult> UpdateProductCategoryMapping( [ModelBinder(typeof(JsonModelBinder <ProductCategoryMappingDto>))] Delta <ProductCategoryMappingDto> productCategoryDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } if (productCategoryDelta.Dto.CategoryId.HasValue) { var category = _categoryApiService.GetCategoryById(productCategoryDelta.Dto.CategoryId.Value); if (category == null) { return(Error(HttpStatusCode.NotFound, "category_id", "not found")); } } if (productCategoryDelta.Dto.ProductId.HasValue) { var product = _productApiService.GetProductById(productCategoryDelta.Dto.ProductId.Value); if (product == null) { return(Error(HttpStatusCode.NotFound, "product_id", "not found")); } } // We do not need to validate the category id, because this will happen in the model binder using the dto validator. var updateProductCategoryId = productCategoryDelta.Dto.Id; var productCategoryEntityToUpdate = await _categoryService.GetProductCategoryByIdAsync(updateProductCategoryId); if (productCategoryEntityToUpdate == null) { return(Error(HttpStatusCode.NotFound, "product_category_mapping", "not found")); } productCategoryDelta.Merge(productCategoryEntityToUpdate); await _categoryService.UpdateProductCategoryAsync(productCategoryEntityToUpdate); //activity log await CustomerActivityService.InsertActivityAsync("UpdateProdutCategoryMapping", await LocalizationService.GetResourceAsync("ActivityLog.UpdateProdutCategoryMapping"), productCategoryEntityToUpdate); var updatedProductCategoryDto = productCategoryEntityToUpdate.ToDto(); var productCategoriesRootObject = new ProductCategoryMappingsRootObject(); productCategoriesRootObject.ProductCategoryMappingDtos.Add(updatedProductCategoryDto); var json = JsonFieldsSerializer.Serialize(productCategoriesRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult CreateProduct([ModelBinder(typeof(JsonModelBinder <ProductDto>))] Delta <ProductDto> productDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } CustomerActivityService.InsertActivity("APIService", "Starting Product Create", null); // Inserting the new product var product = _factory.Initialize(); productDelta.Merge(product); product.ProductTemplateId = product.ProductType == ProductType.SimpleProduct ? 1 : 2; product.OrderMaximumQuantity = 10000; product.ManageInventoryMethod = ManageInventoryMethod.ManageStockByProps; product.CallForPrice = product.GrossPrice <= 0; //_hostEnvironment.ContentRootPath _productService.InsertProduct(product); UpdateProductPictures(product, productDelta.Dto.Images); UpdateProductTags(product, productDelta.Dto.Tags); UpdateProductManufacturers(product, productDelta.Dto.ManufacturerIds); UpdateAssociatedProducts(product, productDelta.Dto.AssociatedProductIds); //search engine name var seName = _urlRecordService.ValidateSeName(product, productDelta.Dto.SeName, product.Name, true); _urlRecordService.SaveSlug(product, seName, 0); UpdateAclRoles(product, productDelta.Dto.RoleIds); UpdateDiscountMappings(product, productDelta.Dto.DiscountIds); UpdateStoreMappings(product, productDelta.Dto.StoreIds); _productService.UpdateProduct(product); CustomerActivityService.InsertActivity("APIService", LocalizationService.GetResource("ActivityLog.AddNewProduct"), product); // Preparing the result dto of the new product var productDto = _dtoHelper.PrepareProductDTO(product); var productsRootObject = new ProductsRootObjectDto(); productsRootObject.Products.Add(productDto); var json = JsonFieldsSerializer.Serialize(productsRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public async Task <IActionResult> UpdateManufacturer( [ModelBinder(typeof(JsonModelBinder <ManufacturerDto>))] Delta <ManufacturerDto> manufacturerDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var manufacturer = _manufacturerApiService.GetManufacturerById(manufacturerDelta.Dto.Id); if (manufacturer == null) { return(Error(HttpStatusCode.NotFound, "manufacturer", "manufacturer not found")); } manufacturerDelta.Merge(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; await _manufacturerService.UpdateManufacturerAsync(manufacturer); await UpdatePictureAsync(manufacturer, manufacturerDelta.Dto.Image); await UpdateAclRolesAsync(manufacturer, manufacturerDelta.Dto.RoleIds); await UpdateDiscountsAsync(manufacturer, manufacturerDelta.Dto.DiscountIds); await UpdateStoreMappingsAsync(manufacturer, manufacturerDelta.Dto.StoreIds); //search engine name if (manufacturerDelta.Dto.SeName != null) { var seName = await _urlRecordService.ValidateSeNameAsync(manufacturer, manufacturerDelta.Dto.SeName, manufacturer.Name, true); await _urlRecordService.SaveSlugAsync(manufacturer, seName, 0); } await _manufacturerService.UpdateManufacturerAsync(manufacturer); await CustomerActivityService.InsertActivityAsync("UpdateManufacturer", await LocalizationService.GetResourceAsync("ActivityLog.UpdateManufacturer"), manufacturer); var manufacturerDto = await _dtoHelper.PrepareManufacturerDtoAsync(manufacturer); var manufacturersRootObject = new ManufacturersRootObject(); manufacturersRootObject.Manufacturers.Add(manufacturerDto); var json = JsonFieldsSerializer.Serialize(manufacturersRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult CreateProductManufacturerMapping( [ModelBinder(typeof(JsonModelBinder <ProductManufacturerMappingsDto>))] Delta <ProductManufacturerMappingsDto> productManufacturerDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var Manufacturer = _manufacturerApiService.GetManufacturerById(productManufacturerDelta.Dto.ManufacturerId.Value); if (Manufacturer == null) { return(Error(HttpStatusCode.NotFound, "manufacturer_id", "not found")); } var product = _productApiService.GetProductById(productManufacturerDelta.Dto.ProductId.Value); if (product == null) { return(Error(HttpStatusCode.NotFound, "product_id", "not found")); } var mappingsCount = _productManufacturerMappingsService.GetMappingsCount(product.Id, Manufacturer.Id); if (mappingsCount > 0) { return(Error(HttpStatusCode.BadRequest, "product_manufacturer_mapping", "already exist")); } var newProductManufacturer = new ProductManufacturer(); productManufacturerDelta.Merge(newProductManufacturer); //inserting new Manufacturer _manufacturerService.InsertProductManufacturer(newProductManufacturer); // Preparing the result dto of the new product Manufacturer mapping var newProductManufacturerMappingDto = newProductManufacturer.ToDto(); var productManufacturerMappingsRootObject = new ProductManufacturerMappingsRootObject(); productManufacturerMappingsRootObject.ProductManufacturerMappingsDtos.Add(newProductManufacturerMappingDto); var json = JsonFieldsSerializer.Serialize(productManufacturerMappingsRootObject, string.Empty); //activity log CustomerActivityService.InsertActivity("AddNewProductManufacturerMapping", LocalizationService.GetResource("ActivityLog.AddNewProductManufacturerMapping"), newProductManufacturer); return(new RawJsonActionResult(json)); }
public async Task <IActionResult> CreateProduct( [ModelBinder(typeof(JsonModelBinder <ProductDto>))] Delta <ProductDto> productDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } // Inserting the new product var product = await _factory.InitializeAsync(); productDelta.Merge(product); await _productService.InsertProductAsync(product); await UpdateProductPicturesAsync(product, productDelta.Dto.Images); await _productTagService.UpdateProductTagsAsync(product, productDelta.Dto.Tags.ToArray()); await UpdateProductManufacturersAsync(product, productDelta.Dto.ManufacturerIds); await UpdateAssociatedProductsAsync(product, productDelta.Dto.AssociatedProductIds); //search engine name var seName = await _urlRecordService.ValidateSeNameAsync(product, productDelta.Dto.SeName, product.Name, true); await _urlRecordService.SaveSlugAsync(product, seName, 0); await UpdateAclRolesAsync(product, productDelta.Dto.RoleIds); await UpdateDiscountMappingsAsync(product, productDelta.Dto.DiscountIds); await UpdateStoreMappingsAsync(product, productDelta.Dto.StoreIds); await _productService.UpdateProductAsync(product); await CustomerActivityService.InsertActivityAsync("AddNewProduct", await LocalizationService.GetResourceAsync("ActivityLog.AddNewProduct"), product); // Preparing the result dto of the new product var productDto = await _dtoHelper.PrepareProductDTOAsync(product); var productsRootObject = new ProductsRootObjectDto(); productsRootObject.Products.Add(productDto); var json = JsonFieldsSerializer.Serialize(productsRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult UpdateOrderItem( int orderId, int orderItemId, [ModelBinder(typeof(JsonModelBinder <OrderItemDto>))] Delta <OrderItemDto> orderItemDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var orderItemToUpdate = _orderService.GetOrderItemById(orderItemId); if (orderItemToUpdate == null) { return(Error(HttpStatusCode.NotFound, "order_item", "not found")); } var order = _orderApiService.GetOrderById(orderId); if (order == null) { return(Error(HttpStatusCode.NotFound, "order", "not found")); } // This is needed because those fields shouldn't be updatable. That is why we save them and after the merge set them back. int?productId = orderItemToUpdate.ProductId; var rentalStartDate = orderItemToUpdate.RentalStartDateUtc; var rentalEndDate = orderItemToUpdate.RentalEndDateUtc; orderItemDelta.Merge(orderItemToUpdate); orderItemToUpdate.ProductId = (int)productId; orderItemToUpdate.RentalStartDateUtc = rentalStartDate; orderItemToUpdate.RentalEndDateUtc = rentalEndDate; _orderService.UpdateOrder(order); CustomerActivityService.InsertActivity("UpdateOrderItem", LocalizationService.GetResource("ActivityLog.UpdateOrderItem"), orderItemToUpdate); var orderItemsRootObject = new OrderItemsRootObject(); orderItemsRootObject.OrderItems.Add(orderItemToUpdate.ToDto()); var json = JsonFieldsSerializer.Serialize(orderItemsRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult DeleteOrder(int id) { if (id <= 0) { return(Error(HttpStatusCode.BadRequest, "id", "invalid id")); } var orderToDelete = _orderApiService.GetOrderById(id); if (orderToDelete == null) { return(Error(HttpStatusCode.NotFound, "order", "not found")); } _orderProcessingService.DeleteOrder(orderToDelete); //activity log CustomerActivityService.InsertActivity("DeleteOrder", LocalizationService.GetResource("ActivityLog.DeleteOrder"), orderToDelete); return(new RawJsonActionResult("{}")); }
public IActionResult DeleteCategory(int id) { if (id <= 0) { return(Error(HttpStatusCode.BadRequest, "id", "invalid id")); } var categoryToDelete = _categoryApiService.GetCategoryById(id); if (categoryToDelete == null) { return(Error(HttpStatusCode.NotFound, "category", "category not found")); } _categoryService.DeleteCategory(categoryToDelete); //activity log CustomerActivityService.InsertActivity("DeleteCategory", LocalizationService.GetResource("ActivityLog.DeleteCategory"), categoryToDelete); return(new RawJsonActionResult("{}")); }
public async Task <IActionResult> DeleteTopic(int id) { if (id <= 0) { return(Error(HttpStatusCode.BadRequest, "id", "invalid id")); } var topicToDelete = await _topicService.GetTopicByIdAsync(id); if (topicToDelete == null) { return(Error(HttpStatusCode.NotFound, "topic", "not found")); } await _topicService.DeleteTopicAsync(topicToDelete); //activity log await CustomerActivityService.InsertActivityAsync("DeleteTopic", await LocalizationService.GetResourceAsync("ActivityLog.DeleteTopic"), topicToDelete); return(Json(new { status = "ok" })); }
public IActionResult DeleteProductManufacturerMapping(int id) { if (id <= 0) { return(Error(HttpStatusCode.BadRequest, "id", "invalid id")); } var productManufacturer = _manufacturerService.GetProductManufacturerById(id); if (productManufacturer == null) { return(Error(HttpStatusCode.NotFound, "product_manufacturer_mapping", "not found")); } _manufacturerService.DeleteProductManufacturer(productManufacturer); //activity log CustomerActivityService.InsertActivity("DeleteProductManufacturerMapping", LocalizationService.GetResource("ActivityLog.DeleteProductManufacturerMapping"), productManufacturer); return(new RawJsonActionResult("{}")); }