public IActionResult SearchWithBarcode(string barcode) { try { var result = api.SearchProductBarcode(barcode); if (User.Identity.IsAuthenticated) { var userId = Guid.Parse(User.FindFirstValue(ClaimTypes.Sid)); api.UpdateSearchHistory(userId, result.First().product.Name); } return(StatusCode(200, result)); } catch (Exception e) { return(StatusCode(400, e.Message)); } }
public IActionResult SearchWithBarcode(string barcode) { if (barcode == null) { barcode = String.Empty; } var result = api.SearchProductBarcode(barcode).Select(Translate); if (!result.Any()) { result = null; } if (User.Identity.IsAuthenticated && result != null) { var userId = Guid.Parse(User.FindFirstValue(ClaimTypes.Sid)); api.UpdateSearchHistory(userId, result.First().productName); } return(View("Search", result)); }