public async Task <OrderServiceModel> GetAsync(GetOrderServiceModel model) { var orders = from c in this.context.Orders join os in this.context.OrderStatuses on c.OrderStatusId equals os.Id join ost in this.context.OrderStatusTranslations on os.Id equals ost.OrderStatusId where c.Id == model.Id && ost.Language == model.Language && c.IsActive select new OrderServiceModel { Id = c.Id, SellerId = c.SellerId, ClientId = c.ClientId.Value, ClientName = c.ClientName, BillingAddressId = c.BillingAddressId, BillingCity = c.BillingCity, BillingCompany = c.BillingCompany, BillingCountryCode = c.BillingCountryCode, BillingFirstName = c.BillingFirstName, BillingLastName = c.BillingLastName, BillingPhone = c.BillingPhone, BillingPhonePrefix = c.BillingPhonePrefix, BillingPostCode = c.BillingPostCode, BillingRegion = c.BillingRegion, BillingStreet = c.BillingStreet, ShippingAddressId = c.ShippingAddressId, ShippingCity = c.ShippingCity, ShippingCompany = c.ShippingCompany, ShippingCountryCode = c.ShippingCountryCode, ShippingFirstName = c.ShippingFirstName, ShippingLastName = c.ShippingLastName, ShippingPhone = c.ShippingPhone, ShippingPhonePrefix = c.ShippingPhonePrefix, ShippingPostCode = c.ShippingPostCode, ShippingRegion = c.ShippingRegion, ShippingStreet = c.ShippingStreet, ExternalReference = c.ExternalReference, ExpectedDeliveryDate = c.ExpectedDeliveryDate, MoreInfo = c.MoreInfo, Reason = c.Reason, OrderStateId = c.OrderStateId, OrderStatusId = c.OrderStatusId, OrderStatusName = ost.Name, OrderItems = c.OrderItems.Select(x => new OrderItemServiceModel { ProductId = x.ProductId, ProductSku = x.ProductSku, ProductName = x.ProductName, PictureUrl = x.PictureUrl, Quantity = x.Quantity, ExternalReference = x.ExternalReference, ExpectedDeliveryFrom = x.ExpectedDeliveryFrom, ExpectedDeliveryTo = x.ExpectedDeliveryTo, MoreInfo = x.MoreInfo, LastModifiedDate = x.LastModifiedDate, CreatedDate = x.CreatedDate }), LastModifiedDate = c.LastModifiedDate, CreatedDate = c.CreatedDate }; if (model.IsSeller is false) { orders = orders.Where(x => x.SellerId == model.OrganisationId.Value); } return(await orders.FirstOrDefaultAsync()); }
public async Task <IActionResult> Get(Guid?id) { var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim); var serviceModel = new GetOrderServiceModel { Id = id, Language = CultureInfo.CurrentCulture.Name, OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value), IsSeller = this.User.IsInRole("Seller") }; var validator = new GetOrderModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { var order = await this.ordersService.GetAsync(serviceModel); if (order != null) { var response = new OrderResponseModel { Id = order.Id, ClientId = order.ClientId, ClientName = order.ClientName, BillingAddressId = order.BillingAddressId, BillingCity = order.BillingCity, BillingCompany = order.BillingCompany, BillingCountryCode = order.BillingCountryCode, BillingFirstName = order.BillingFirstName, BillingLastName = order.BillingLastName, BillingPhone = order.BillingPhone, BillingPhonePrefix = order.BillingPhonePrefix, BillingPostCode = order.BillingPostCode, BillingRegion = order.BillingRegion, BillingStreet = order.BillingStreet, ShippingAddressId = order.ShippingAddressId, ShippingCity = order.ShippingCity, ShippingCompany = order.ShippingCompany, ShippingCountryCode = order.ShippingCountryCode, ShippingFirstName = order.ShippingFirstName, ShippingLastName = order.ShippingLastName, ShippingPhone = order.ShippingPhone, ShippingPhonePrefix = order.ShippingPhonePrefix, ShippingPostCode = order.ShippingPostCode, ShippingRegion = order.ShippingRegion, ShippingStreet = order.ShippingStreet, ExpectedDeliveryDate = order.ExpectedDeliveryDate, MoreInfo = order.MoreInfo, Reason = order.Reason, OrderStateId = order.OrderStateId, OrderStatusId = order.OrderStatusId, OrderStatusName = order.OrderStatusName, OrderItems = order.OrderItems.Select(x => new OrderItemResponseModel { ProductId = x.ProductId, ProductSku = x.ProductSku, ProductName = x.ProductName, PictureUrl = x.PictureUrl, Quantity = x.Quantity, ExternalReference = x.ExternalReference, ExpectedDeliveryFrom = x.ExpectedDeliveryFrom, ExpectedDeliveryTo = x.ExpectedDeliveryTo, MoreInfo = x.MoreInfo, LastModifiedDate = x.LastModifiedDate, CreatedDate = x.CreatedDate }), LastModifiedDate = order.LastModifiedDate, CreatedDate = order.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); }