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); }
public async Task <IActionResult> GetWarehouseByName(string name) { var serviceModel = new GetWarehouseByNameServiceModel { Name = name, }; var validator = new GetWarehouseByNameModelValidator(); 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); }