public async Task <IActionResult> GetByName(string name) { if (String.IsNullOrEmpty(name)) { return(StatusCode(400, "Invalid parameter(s).")); } //Get data var data = await _repo.GetByName(name); if (data == null) { return(StatusCode(500, "Invoice item named '" + name + "' could not be found.")); } //Convert to viewmodel var result = new InvoiceItemViewModel { InvoiceNumber = data.InvoiceNumber, Name = data.Name, Price = data.Price, Description = data.Description, Tax = data.Tax, Quantity = data.Quantity, ItemNumber = data.ItemNumber }; return(Ok(result)); }