public async Task <WarehouseServiceModel> GetAsync(GetWarehouseByNameServiceModel model) { var warehouse = from c in this.context.Warehouses where c.Name == model.Name && 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> 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); }