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)); }
public async Task <ProductServiceModel> GetByIdAsync(GetProductByIdServiceModel model) { var searchResultItem = await this.productSearchRepository.GetByIdAsync(model.Id.Value, model.Language, model.OrganisationId); if (searchResultItem != null) { var productSearchModel = this.MapProductSearchModelToProductResult(searchResultItem); if (!searchResultItem.PrimaryProductIdHasValue) { var productVariants = await this.productSearchRepository.GetProductVariantsAsync(searchResultItem.ProductId, model.Language, model.OrganisationId); productSearchModel.ProductVariants = productVariants?.Data?.Select(x => x.ProductId); } return(productSearchModel); } return(default);