public IActionResult SearchWithName(string name) { if (name == null) { name = String.Empty; } var result = api.SearchProductName(name).Select(Translate); if (!result.Any()) { result = null; } if (User.Identity.IsAuthenticated && result != null) { var userId = Guid.Parse(User.FindFirstValue(ClaimTypes.Sid)); api.UpdateSearchHistory(userId, name); } return(View("search", result)); }
public IActionResult SearchWithName(string name) { try { var result = api.SearchProductName(name); if (User.Identity.IsAuthenticated) { var userId = Guid.Parse(User.FindFirstValue(ClaimTypes.Sid)); api.UpdateSearchHistory(userId, name); } return(StatusCode(200, Json(result))); } catch (Exception e) { return(StatusCode(400, e.Message)); } }