Exemplo n.º 1
0
        public async Task <IActionResult> GetById(Guid?id)
        {
            var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim);

            var serviceModel = new GetProductByIdServiceModel
            {
                Id             = id.Value,
                Username       = this.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value,
                OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value),
                Language       = CultureInfo.CurrentCulture.Name
            };

            var validator = new GetProductByIdModelValidator();

            var validationResult = await validator.ValidateAsync(serviceModel);

            if (validationResult.IsValid)
            {
                var product = await this.productService.GetByIdAsync(serviceModel);

                if (product != null)
                {
                    return(this.StatusCode((int)HttpStatusCode.OK, MapProductServiceModelToProductResponseModel(product)));
                }
                else
                {
                    return(this.StatusCode((int)HttpStatusCode.NotFound));
                }
            }

            return(this.StatusCode((int)HttpStatusCode.UnprocessableEntity));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetInventoryByProductId(Guid?id)
        {
            var sellerClaim  = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim);
            var serviceModel = new GetInventoryByProductIdServiceModel
            {
                ProductId = id.Value,
            };

            var validator        = new GetProductByIdModelValidator();
            var validationResult = await validator.ValidateAsync(serviceModel);

            if (validationResult.IsValid)
            {
                var inventoryProduct = await this.inventoriesService.GetInventoryByProductId(serviceModel);

                if (inventoryProduct != null)
                {
                    var response = new InventorySumResponseModel
                    {
                        ProductId         = inventoryProduct.ProductId,
                        AvailableQuantity = inventoryProduct.AvailableQuantity,
                        Quantity          = inventoryProduct.Quantity,
                        ProductName       = inventoryProduct.ProductName,
                        ProductSku        = inventoryProduct.ProductSku,
                        RestockableInDays = inventoryProduct.RestockableInDays,
                        ExpectedDelivery  = inventoryProduct.ExpectedDelivery,
                        Details           = inventoryProduct.Details.Select(item => new InventoryDetailsResponseModel
                        {
                            Id                = item.Id,
                            ProductId         = item.ProductId,
                            ProductName       = item.ProductName,
                            Quantity          = item.Quantity,
                            AvailableQuantity = item.AvailableQuantity,
                            ExpectedDelivery  = item.ExpectedDelivery,
                            ProductSku        = item.ProductSku,
                            WarehouseId       = item.WarehouseId,
                            WarehouseName     = item.WarehouseName,
                            RestockableInDays = item.RestockableInDays,
                            LastModifiedDate  = item.LastModifiedDate,
                            CreatedDate       = item.CreatedDate
                        })
                    };

                    return(this.StatusCode((int)HttpStatusCode.OK, response));
                }
                else
                {
                    return(this.StatusCode((int)HttpStatusCode.NotFound));
                }
            }

            throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity);
        }