public async Task <IActionResult> Get(Guid?id) { var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim); var serviceModel = new GetInventoryServiceModel { Id = id.Value, Language = CultureInfo.CurrentCulture.Name, OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value) }; var validator = new GetInventoryModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { var inventoryProduct = await this.inventoriesService.GetAsync(serviceModel); if (inventoryProduct != null) { var response = new InventoryResponseModel { Id = inventoryProduct.Id, ProductId = inventoryProduct.ProductId, ProductName = inventoryProduct.ProductName, ProductSku = inventoryProduct.ProductSku, WarehouseId = inventoryProduct.WarehouseId.Value, WarehouseName = inventoryProduct.WarehouseName, Quantity = inventoryProduct.Quantity, AvailableQuantity = inventoryProduct.AvailableQuantity, RestockableInDays = inventoryProduct.RestockableInDays, ExpectedDelivery = inventoryProduct.ExpectedDelivery, LastModifiedDate = inventoryProduct.LastModifiedDate, CreatedDate = inventoryProduct.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); }
public async Task <InventoryServiceModel> GetAsync(GetInventoryServiceModel model) { var inventoryProduct = from c in this.context.Inventory join warehouse in this.context.Warehouses on c.WarehouseId equals warehouse.Id where c.Id == model.Id.Value && c.IsActive select new InventoryServiceModel { Id = c.Id, ProductId = c.ProductId, ProductName = c.ProductName, ProductSku = c.ProductSku, WarehouseId = c.WarehouseId, WarehouseName = warehouse.Name, Quantity = c.Quantity, AvailableQuantity = c.AvailableQuantity.Value, RestockableInDays = c.RestockableInDays.Value, ExpectedDelivery = c.ExpectedDelivery.Value, LastModifiedDate = c.LastModifiedDate, CreatedDate = c.CreatedDate }; return(await inventoryProduct.FirstOrDefaultAsync()); }