public IActionResult GetOrderByOrderGuid(string orderGuid, string fields = "")
        {
            if (string.IsNullOrWhiteSpace(orderGuid))
            {
                return Error(HttpStatusCode.BadRequest, "orderGuid", "orderGuid");
            }

            var order = _orderApiService.GetOrderByOrderGuid(orderGuid);

            if (order == null)
            {
                return Error(HttpStatusCode.NotFound, "order", "not found");
            }

            var ordersRootObject = new OrdersRootObject();

            string decryptedCardNumber = _encryptionService.DecryptText(order.MaskedCreditCardNumber);
            if (!string.IsNullOrWhiteSpace(decryptedCardNumber))
            {
                order.CardNumber = decryptedCardNumber;
            }

            var orderDto = _dtoHelper.PrepareOrderDTO(order);
            ordersRootObject.Orders.Add(orderDto);

            var json = JsonFieldsSerializer.Serialize(ordersRootObject,fields);

            return new RawJsonActionResult(json);
        }
Ejemplo n.º 2
0
        public IActionResult GetCategories(CategoriesParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter"));
            }

            var allCategories = _categoryApiService.GetCategories(parameters.Ids, parameters.CreatedAtMin, parameters.CreatedAtMax,
                                                                  parameters.UpdatedAtMin, parameters.UpdatedAtMax,
                                                                  parameters.Limit, parameters.Page, parameters.SinceId,
                                                                  parameters.ProductId, parameters.PublishedStatus)
                                .Where(c => StoreMappingService.Authorize(c));

            IList <CategoryDto> categoriesAsDtos = allCategories.Select(category =>
            {
                return(_dtoHelper.PrepareCategoryDTO(category));
            }).ToList();

            var categoriesRootObject = new CategoriesRootObject()
            {
                Categories = categoriesAsDtos
            };

            var json = JsonFieldsSerializer.Serialize(categoriesRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
        public IActionResult GetProducts(ProductsParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "invalid page parameter"));
            }

            var allProducts = _productApiService.GetProducts(parameters.Ids, parameters.Skus, parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.UpdatedAtMin,
                                                             parameters.UpdatedAtMax, parameters.Limit, parameters.Page, parameters.SinceId, parameters.CategoryId, parameters.IncludeChildren,
                                                             parameters.VendorName, parameters.PublishedStatus)
                              .Where(p => StoreMappingService.Authorize(p));

            IList <ProductDto> productsAsDtos = allProducts.Select(product => _dtoHelper.PrepareProductDTO(product)).ToList();

            var productsRootObject = new ProductsRootObjectDto()
            {
                Products = productsAsDtos
            };

            var json = JsonFieldsSerializer.Serialize(productsRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 4
0
        public IActionResult GetProductReviews(ProductReviewsParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter"));
            }

            var allReviews = _productReviewApiService.GetProductReviews(parameters.CustomerId,
                                                                        parameters.ProductId,
                                                                        parameters.Ids, parameters.CreatedAtMin, parameters.CreatedAtMax,
                                                                        parameters.Limit, parameters.Page, parameters.SinceId)
                             .OrderByDescending(pr => pr.Id);

            IList <ProductReviewDto> productReviewsAsDtos = allReviews.Select(pr =>
            {
                return(_dtoHelper.PrepareProductReviewDTO(pr));
            }).ToList();

            var productReviewsRootObject = new ProductReviewsRootObject()
            {
                ProductReviews = productReviewsAsDtos
            };

            var json = JsonFieldsSerializer.Serialize(productReviewsRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
        public void WhenInValidFieldsParameterPassed_ShouldSerializeTheseFieldsJson_ComplexDummyObject()
        {
            var complexDummySerializableObject = new SerializableDummyObjectWithComplexTypes();

            complexDummySerializableObject.Items.Add(new DummyObjectWithComplexTypes
            {
                StringProperty             = "string value",
                DummyObjectWithSimpleTypes = new DummyObjectWithSimpleTypes
                {
                    FirstProperty  = "first property value",
                    SecondProperty = "second property value"
                },
                ListOfDummyObjectWithSimpleTypes = new List <DummyObjectWithSimpleTypes>
                {
                    new DummyObjectWithSimpleTypes()
                    {
                        FirstProperty  = "first property of list value",
                        SecondProperty = "second property of list value"
                    }
                }
            });

            // Arange
            IJsonFieldsSerializer cut = new JsonFieldsSerializer();

            // Act
            string json = cut.Serialize(complexDummySerializableObject, "invalid field");

            // Assert
            SerializableDummyObjectWithComplexTypes complexDummySerializableObjectFromJson =
                JsonConvert.DeserializeObject <SerializableDummyObjectWithComplexTypes>(json);

            Assert.AreEqual(0, complexDummySerializableObjectFromJson.Items.Count);
        }
Ejemplo n.º 6
0
        public IActionResult GetShoppingCartItems(ShoppingCartItemsParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "invalid page parameter"));
            }

            IList <ShoppingCartItem> shoppingCartItems = _shoppingCartItemApiService.GetShoppingCartItems(customerId: null,
                                                                                                          createdAtMin: parameters.CreatedAtMin,
                                                                                                          createdAtMax: parameters.CreatedAtMax,
                                                                                                          updatedAtMin: parameters.UpdatedAtMin,
                                                                                                          updatedAtMax: parameters.UpdatedAtMax,
                                                                                                          limit: parameters.Limit,
                                                                                                          page: parameters.Page);

            var shoppingCartItemsDtos = shoppingCartItems.Select(shoppingCartItem =>
            {
                return(_dtoHelper.PrepareShoppingCartItemDTO(shoppingCartItem));
            }).ToList();

            var shoppingCartsRootObject = new ShoppingCartItemsRootObject()
            {
                ShoppingCartItems = shoppingCartItemsDtos
            };

            var json = JsonFieldsSerializer.Serialize(shoppingCartsRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
        public IActionResult GetOrderItems(int orderId, OrderItemsParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid request parameters"));
            }

            var order = _orderApiService.GetOrderById(orderId);

            if (order == null)
            {
                return(Error(HttpStatusCode.NotFound, "order", "not found"));
            }

            var allOrderItemsForOrder =
                _orderItemApiService.GetOrderItemsForOrder(order, parameters.Limit, parameters.Page,
                                                           parameters.SinceId);

            var orderItemsRootObject = new OrderItemsRootObject
            {
                OrderItems = allOrderItemsForOrder.Select(item => _dtoHelper.PrepareOrderItemDTO(item)).ToList()
            };

            var json = JsonFieldsSerializer.Serialize(orderItemsRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        public IActionResult GetProductSpecificationAttributes(ProductSpecifcationAttributesParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "invalid page parameter"));
            }

            var productSpecificationAttribtues = _specificationAttributeApiService.GetProductSpecificationAttributes(productId: parameters.ProductId, specificationAttributeOptionId: parameters.SpecificationAttributeOptionId, allowFiltering: parameters.AllowFiltering, showOnProductPage: parameters.ShowOnProductPage, limit: parameters.Limit, page: parameters.Page, sinceId: parameters.SinceId);

            var productSpecificationAttributeDtos = productSpecificationAttribtues.Select(x => _dtoHelper.PrepareProductSpecificationAttributeDto(x)).ToList();

            var productSpecificationAttributesRootObject = new ProductSpecificationAttributesRootObjectDto()
            {
                ProductSpecificationAttributes = productSpecificationAttributeDtos
            };

            var json = JsonFieldsSerializer.Serialize(productSpecificationAttributesRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
        public IActionResult GetProvince()
        {
            try
            {
                var state = _stateProvinceService.GetStateProvincesByCountryId(134);

                //return Ok(state.ToList());

                var provinceRootObject = new ProvinceRootObject
                {
                    Provinces = state.Select(
                        s => new ProvinceDTO
                    {
                        Name = s.Name,
                        Id   = s.Id
                    }
                        ).ToList()
                };

                var json = JsonFieldsSerializer.Serialize(provinceRootObject, string.Empty);

                return(new RawJsonActionResult(json));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 11
0
        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 GetCategories(TopicsParametersModel parameters)
        {
            if (parameters.Limit < Constants.Configurations.MinLimit || parameters.Limit > Constants.Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter"));
            }

            if (parameters.Page < Constants.Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter"));
            }

            var allTopics = _topicApiService.GetTopics(parameters.Ids, parameters.CreatedAtMin, parameters.CreatedAtMax,
                                                       parameters.UpdatedAtMin, parameters.UpdatedAtMax,
                                                       parameters.Limit, parameters.Page, parameters.SinceId)
                            .Where(c => StoreMappingService.Authorize(c));

            IList <TopicDto> topicsAsDtos = allTopics.Select(topic => _dtoHelper.PrepareTopicToDTO(topic)).ToList();

            var topicsRootObject = new TopicsRootObject
            {
                Topics = topicsAsDtos
            };

            var json = JsonFieldsSerializer.Serialize(topicsRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
        public IActionResult GetCustomers(CustomersParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid request parameters"));
            }

            try
            {
                var allCustomers = _customerApiService.GetCustomersDtos(parameters.CreatedAtMin,
                                                                        parameters.CreatedAtMax,
                                                                        parameters.Limit,
                                                                        parameters.Page,
                                                                        parameters.SinceId);

                var customersRootObject = new CustomersRootObject()
                {
                    Customers = allCustomers
                };

                var json = JsonFieldsSerializer.Serialize(customersRootObject, parameters.Fields);

                return(new RawJsonActionResult(json));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 14
0
        public IActionResult GetOrders(OrdersParametersModel parameters)
        {
            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter"));
            }

            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid limit parameter"));
            }

            var storeId = _storeContext.CurrentStore.Id;

            var orders = _orderApiService.GetOrders(parameters.Ids, parameters.CreatedAtMin,
                                                    parameters.CreatedAtMax,
                                                    parameters.Limit, parameters.Page, parameters.SinceId,
                                                    parameters.Status, parameters.PaymentStatus, parameters.ShippingStatus,
                                                    parameters.CustomerId, storeId);

            IList <OrderDto> ordersAsDtos = orders.Select(x => _dtoHelper.PrepareOrderDTO(x)).ToList();

            var ordersRootObject = new OrdersRootObject()
            {
                Orders = ordersAsDtos
            };

            var json = JsonFieldsSerializer.Serialize(ordersRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> GetManufacturers(ManufacturersParametersModel parameters)
        {
            if (parameters.Limit < Constants.Configurations.MinLimit || parameters.Limit > Constants.Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter"));
            }

            if (parameters.Page < Constants.Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter"));
            }

            var allManufacturers = _manufacturerApiService.GetManufacturers(parameters.Ids, parameters.CreatedAtMin, parameters.CreatedAtMax,
                                                                            parameters.UpdatedAtMin, parameters.UpdatedAtMax,
                                                                            parameters.Limit, parameters.Page, parameters.SinceId,
                                                                            parameters.ProductId, parameters.PublishedStatus, parameters.LanguageId)
                                   .WhereAwait(async c => await StoreMappingService.AuthorizeAsync(c));

            IList <ManufacturerDto> manufacturersAsDtos = await allManufacturers.SelectAwait(async manufacturer => await _dtoHelper.PrepareManufacturerDtoAsync(manufacturer)).ToListAsync();

            var manufacturersRootObject = new ManufacturersRootObject
            {
                Manufacturers = manufacturersAsDtos
            };

            var json = JsonFieldsSerializer.Serialize(manufacturersRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> CreateShelfLocation([ModelBinder(typeof(JsonModelBinder <ShelfLocationDto>))] Delta <ShelfLocationDto> shelfLocationDelta)
        {
            if (!ModelState.IsValid)
            {
                return(await Error());
            }

            var newShelfLocation = new ShelfLocation();

            shelfLocationDelta.Merge(newShelfLocation);

            await _shelfLocationRepository.InsertAsync(newShelfLocation);

            await UserActivityService.InsertActivityAsync("AddNewShelfLocation", $"Added a new shelf location (ID = {newShelfLocation.Id})", newShelfLocation);

            var newShelfLocationDto = newShelfLocation.ToDto();

            var rootObject = new ShelfLocationRootObject();

            rootObject.ShelfLocation.Add(newShelfLocationDto);

            var json = JsonFieldsSerializer.Serialize(rootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 17
0
        public IActionResult UpdateShoppingCartItem([ModelBinder(typeof(JsonModelBinder <ShoppingCartItemDto>))] Delta <ShoppingCartItemDto> shoppingCartItemDelta)
        {
            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }

            // We kno that the id will be valid integer because the validation for this happens in the validator which is executed by the model binder.
            var shoppingCartItemForUpdate = _shoppingCartItemApiService.GetShoppingCartItem(shoppingCartItemDelta.Dto.Id);

            if (shoppingCartItemForUpdate == null)
            {
                return(Error(HttpStatusCode.NotFound, "shopping_cart_item", "not found"));
            }

            shoppingCartItemDelta.Merge(shoppingCartItemForUpdate);

            if (!shoppingCartItemForUpdate.Product.IsRental)
            {
                shoppingCartItemForUpdate.RentalStartDateUtc = null;
                shoppingCartItemForUpdate.RentalEndDateUtc   = null;
            }

            if (shoppingCartItemDelta.Dto.Attributes != null)
            {
                shoppingCartItemForUpdate.AttributesXml = _productAttributeConverter.ConvertToXml(shoppingCartItemDelta.Dto.Attributes, shoppingCartItemForUpdate.Product.Id);
            }

            // The update time is set in the service.
            var warnings = _shoppingCartService.UpdateShoppingCartItem(shoppingCartItemForUpdate.Customer, shoppingCartItemForUpdate.Id,
                                                                       shoppingCartItemForUpdate.AttributesXml, shoppingCartItemForUpdate.CustomerEnteredPrice,
                                                                       shoppingCartItemForUpdate.RentalStartDateUtc, shoppingCartItemForUpdate.RentalEndDateUtc,
                                                                       shoppingCartItemForUpdate.Quantity);

            if (warnings.Count > 0)
            {
                foreach (var warning in warnings)
                {
                    ModelState.AddModelError("shopping cart item", warning);
                }

                return(Error(HttpStatusCode.BadRequest));
            }
            else
            {
                shoppingCartItemForUpdate = _shoppingCartItemApiService.GetShoppingCartItem(shoppingCartItemForUpdate.Id);
            }

            // Preparing the result dto of the new product category mapping
            var newShoppingCartItemDto = _dtoHelper.PrepareShoppingCartItemDTO(shoppingCartItemForUpdate);

            var shoppingCartsRootObject = new ShoppingCartItemsRootObject();

            shoppingCartsRootObject.ShoppingCartItems.Add(newShoppingCartItemDto);

            var json = JsonFieldsSerializer.Serialize(shoppingCartsRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> UpdateShelfLocation([ModelBinder(typeof(JsonModelBinder <ShelfLocationDto>))] Delta <ShelfLocationDto> shelfLocationDelta)
        {
            if (!ModelState.IsValid)
            {
                return(await Error());
            }

            var currentShelfLocation = _shelfLocationApiService.GetShelfLocationById(shelfLocationDelta.Dto.Id);

            if (currentShelfLocation == null)
            {
                return(await Error(HttpStatusCode.NotFound, "shelf_location", "not found"));
            }

            shelfLocationDelta.Merge(currentShelfLocation);

            await _shelfLocationRepository.UpdateAsync(currentShelfLocation);

            await UserActivityService.InsertActivityAsync("EditShelfLocation", $"Edited a shelf location (ID = {currentShelfLocation.Id})", currentShelfLocation);

            var shelfLocationDto = currentShelfLocation.ToDto();

            var rootObject = new ShelfLocationRootObject();

            rootObject.ShelfLocation.Add(shelfLocationDto);

            var json = JsonFieldsSerializer.Serialize(rootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
        public IActionResult GetOrderItemByIdForOrder(int orderId, int orderItemId, string fields = "")
        {
            var order = _orderApiService.GetOrderById(orderId);

            if (order == null)
            {
                return(Error(HttpStatusCode.NotFound, "order", "not found"));
            }

            var orderItem = _orderService.GetOrderItemById(orderItemId);

            if (orderItem == null)
            {
                return(Error(HttpStatusCode.NotFound, "order_item", "not found"));
            }

            var orderItemDtos = new List <OrderItemDto> {
                _dtoHelper.PrepareOrderItemDTO(orderItem)
            };

            var orderItemsRootObject = new OrderItemsRootObject
            {
                OrderItems = orderItemDtos
            };

            var json = JsonFieldsSerializer.Serialize(orderItemsRootObject, fields);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> GetShelfLocation(ShelfLocationParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(await Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(await Error(HttpStatusCode.BadRequest, "page", "Invalid request parameters"));
            }

            var shelfLocationDto = _shelfLocationApiService.GetShelfLocation(
                parameters.Ids,
                parameters.Limit,
                parameters.Page,
                parameters.SinceId,
                parameters.CreatedAtMin,
                parameters.CreatedAtMax)
                                   .Select(trans => trans.ToDto()).ToList();

            var rootObject = new ShelfLocationRootObject {
                ShelfLocation = shelfLocationDto
            };

            var json = JsonFieldsSerializer.Serialize(rootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> GetProfileFields(int id, string fields = "")
        {
            if (id <= 0)
            {
                return(await Error(HttpStatusCode.BadRequest, "profile_id", "profile_id is required."));
            }

            var profileFieldDto = await _mediator.Send(new GetProfileFields.Query {
                ProfileId = id, Fields = fields
            });

            if (profileFieldDto == null)
            {
                return(await Error(HttpStatusCode.NotFound, "profile_fields", "not found"));
            }

            var rootObject = new ProfileFieldsRootObject
            {
                ProfileFields = profileFieldDto
            };

            var json = JsonFieldsSerializer.Serialize(rootObject, fields);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 22
0
        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 void WhenEmptyFieldsParameterPassed_ShouldSerializeEverythingFromThePassedObject(string emptyFieldsParameter)
        {
            //Arange
            IJsonFieldsSerializer cut = new JsonFieldsSerializer();

            var serializableObject = new SerializableDummyObjectWithSimpleTypes();

            serializableObject.Items.Add(new DummyObjectWithSimpleTypes()
            {
                FirstProperty  = "first property value",
                SecondProperty = "second property value"
            });

            //Act
            string serializedObjectJson = cut.Serialize(serializableObject, emptyFieldsParameter);

            //Assert
            SerializableDummyObjectWithSimpleTypes dummySerializableObjectFromJson =
                JsonConvert.DeserializeObject <SerializableDummyObjectWithSimpleTypes>(serializedObjectJson);

            Assert.AreEqual(serializableObject.Items.Count, dummySerializableObjectFromJson.Items.Count);
            Assert.AreEqual(serializableObject.Items[0], dummySerializableObjectFromJson.Items[0]);
            Assert.AreEqual("first property value", dummySerializableObjectFromJson.Items[0].FirstProperty);
            Assert.AreEqual("second property value", dummySerializableObjectFromJson.Items[0].SecondProperty);
        }
Ejemplo n.º 24
0
        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));
        }
Ejemplo n.º 25
0
        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));
        }
Ejemplo n.º 26
0
        public IActionResult GetProductAttributes(ProductAttributesParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "invalid page parameter"));
            }

            var allProductAttributes = _productAttributesApiService.GetProductAttributes(parameters.Limit, parameters.Page, parameters.SinceId);

            IList <CustomeProductAttributes> productAttributesAsDtos = allProductAttributes.Select(productAttribute => _dtoHelper.PrepareProductAttributeDTO(productAttribute)).ToList();

            var productAttributesRootObject = new CustomeProductAttributesRootObjectDto()
            {
                ProductAttributes = productAttributesAsDtos
            };

            var json = JsonFieldsSerializer.Serialize(productAttributesRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 27
0
        public IActionResult GetMappings(ProductCategoryMappingsParametersModel parameters)
        {
            if (parameters.Limit < Constants.Configurations.MinLimit || parameters.Limit > Constants.Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "invalid limit parameter"));
            }

            if (parameters.Page < Constants.Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "invalid page parameter"));
            }

            IList <ProductCategoryMappingDto> mappingsAsDtos =
                _productCategoryMappingsService.GetMappings(parameters.ProductId,
                                                            parameters.CategoryId,
                                                            parameters.Limit,
                                                            parameters.Page,
                                                            parameters.SinceId).Select(x => x.ToDto()).ToList();

            var productCategoryMappingRootObject = new ProductCategoryMappingsRootObject
            {
                ProductCategoryMappingDtos = mappingsAsDtos
            };

            var json = JsonFieldsSerializer.Serialize(productCategoryMappingRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 28
0
        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));
        }
Ejemplo n.º 29
0
        public IActionResult GetNewsLetterSubscriptions(NewsLetterSubscriptionsParametersModel parameters)
        {
            if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter"));
            }

            if (parameters.Page < Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter"));
            }

            var newsLetterSubscriptions = _newsLetterSubscriptionApiService.GetNewsLetterSubscriptions(parameters.CreatedAtMin, parameters.CreatedAtMax,
                                                                                                       parameters.Limit, parameters.Page, parameters.SinceId,
                                                                                                       parameters.OnlyActive);

            var newsLetterSubscriptionsDtos = newsLetterSubscriptions.Select(nls => nls.ToDto()).ToList();

            var newsLetterSubscriptionsRootObject = new NewsLetterSubscriptionsRootObject()
            {
                NewsLetterSubscriptions = newsLetterSubscriptionsDtos
            };

            var json = JsonFieldsSerializer.Serialize(newsLetterSubscriptionsRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
        public IActionResult GetProductById(int id, string fields = "")
        {
            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 productDto = _dtoHelper.PrepareProductDTO(product);

            productDto.AdmindId = _genericAttributeService.GetAttribute <int>(product, "nop.product.admindid");

            var productsRootObject = new ProductsRootObjectDto();

            productsRootObject.Products.Add(productDto);

            var json = JsonFieldsSerializer.Serialize(productsRootObject, fields);

            return(new RawJsonActionResult(json));
        }