public async Task <WarehouseServiceModel> GetAsync(GetWarehouseServiceModel model) { var warehouse = from c in this.context.Warehouses where c.SellerId == model.OrganisationId.Value && c.Id == model.Id && c.IsActive select new WarehouseServiceModel { Id = c.Id, Name = c.Name, Location = c.Location, LastModifiedDate = c.LastModifiedDate, CreatedDate = c.CreatedDate }; return(await warehouse.FirstOrDefaultAsync()); }
public async Task <IActionResult> Get(Guid?id) { var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim); var serviceModel = new GetWarehouseServiceModel { Id = id, Language = CultureInfo.CurrentCulture.Name, OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value) }; var validator = new GetWarehouseModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { var warehouse = await this.warehouseService.GetAsync(serviceModel); if (warehouse != null) { var response = new WarehouseResponseModel { Id = warehouse.Id, Name = warehouse.Name, Location = warehouse.Location, LastModifiedDate = warehouse.LastModifiedDate, CreatedDate = warehouse.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); }