Ejemplo n.º 1
0
        }     // End Index

        /*
         * Name: SearchLogs
         * Parametor: [POST] dateInput(string), message(string)
         * Author: Namchok Singhachai
         * Description: Searching a log.
         */
        public async Task <JsonResult> Search(string messageInput, string dateInput)
        {
            try
            {
                _logger.LogTrace("Start searching a logs.");
                if ((dateInput == null && messageInput == null) || (dateInput == "" && messageInput == ""))
                {
                    throw new Exception("Please input information for searching."); // End if param both is null
                }
                _logger.LogDebug("Input Date Input: " + ((dateInput != null && dateInput != "") ? dateInput : "-"));
                _logger.LogDebug("Input Message: " + ((messageInput != null && messageInput != "") ? messageInput : "-"));
                _logger.LogDebug($"Getting log by {(dateInput ?? "")}{(messageInput == null ? "" : messageInput != null && dateInput == null ? messageInput : " or " + messageInput)}.");
                _logger.LogTrace("End searching a logs.");
                return(new JsonResult(await _logs.SearchAsync(messageInput, dateInput))); // Return object JSON
            }
            catch (Exception e)
            {
                _logger.LogError("Error: " + e.Message.ToString());
                _logger.LogTrace("End searching a logs.");
                return(new JsonResult(new ObjectJSON
                {
                    condition = "error",
                    messages = @"Swal.fire({ icon: 'error', title: 'ERROR!', text: `" + e.Message.Replace("\\", "/").Replace("`", "'") + @"`, showConfirmButton: true });",
                    text = e.Message.Replace("\\", "/").Replace("`", "'")
                }));
            } // End try catch
        }     // End searchLogs