public async Task <IActionResult> Get() { var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim); var serviceModel = new GetOrderStatusesServiceModel { Language = CultureInfo.CurrentCulture.Name, Username = this.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value, OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value) }; var validator = new GetOrderStatusesModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { var orders = await this.ordersService.GetOrderStatusesAsync(serviceModel); if (orders != null) { var response = orders.Select(x => new OrderStatusResponseModel { Id = x.Id, Name = x.Name, LastModifiedDate = x.LastModifiedDate, CreatedDate = x.CreatedDate }); return(this.StatusCode((int)HttpStatusCode.OK, response)); } } throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity); }
public async Task <IEnumerable <OrderStatusServiceModel> > GetOrderStatusesAsync(GetOrderStatusesServiceModel serviceModel) { var orderStatuses = from orderstatus in this.context.OrderStatuses join orderstate in this.context.OrderStates on orderstatus.OrderStateId equals orderstate.Id join orderstatustranslation in this.context.OrderStatusTranslations on orderstatus.Id equals orderstatustranslation.OrderStatusId where orderstatustranslation.Language == serviceModel.Language && orderstatus.IsActive orderby orderstatus.Order select new OrderStatusServiceModel { Id = orderstatus.Id, OrderStateId = orderstate.Id, Name = orderstatustranslation.Name, LastModifiedDate = orderstatus.LastModifiedDate, CreatedDate = orderstatus.CreatedDate }; return(orderStatuses); }