Пример #1
0
        public List <Organization> GetOrganizationDetails(string key, string value)
        {
            var orgDetails   = new List <Organization>();
            var titleCaseKey = TitleCaseString.ToTitleCase(key);

            using StreamReader r = new StreamReader(_filePath);
            string json = r.ReadToEnd();

            var allOrg = JsonConvert.DeserializeObject <List <Organization> >(json);

            foreach (var org in allOrg)
            {
                if (org.GetType().GetTypeInfo().GetDeclaredProperty(titleCaseKey) != null)
                {
                    if (org.GetType().GetProperty(titleCaseKey).GetValue(org)?.ToString() == value)
                    {
                        orgDetails.Add(org);
                    }
                }
                else
                {
                    Console.WriteLine("Please enter a valid search term for Organizations");
                    _logger.LogInformation($"Invalid search term {key}");
                    orgDetails = null;
                    break;
                }
            }
            return(orgDetails);
        }
Пример #2
0
        public List <UserSearchEntity> GetUserDetails(string key, string value)
        {
            var userDetails  = new List <UserSearchEntity>();
            var titleCaseKey = TitleCaseString.ToTitleCase(key);

            using StreamReader r = new StreamReader(_userFilePath);
            string json     = r.ReadToEnd();
            var    allUsers = JsonConvert.DeserializeObject <List <User> >(json);

            foreach (var user in allUsers)
            {
                var mapUser = new UserSearchEntity();
                if (user.GetType().GetTypeInfo().GetDeclaredProperty(titleCaseKey) != null)
                {
                    if (user.GetType().GetProperty(titleCaseKey).GetValue(user)?.ToString() == value)
                    {
                        if (user?.Organization_Id != 0)
                        {
                            var orgDetails           = _getOrg.GetOrganizationDetails("Id", user.Organization_Id.ToString());
                            var ticketSubjectDetails = GetTicketsSubject(user.Organization_Id);
                            mapUser.OrganizationName = orgDetails?.FirstOrDefault(r => r.Id == user?.Organization_Id).Name;
                            mapUser.User             = user;
                            mapUser.TicketSubjects   = ticketSubjectDetails;
                        }
                        userDetails.Add(mapUser);
                    }
                }
                else
                {
                    Console.WriteLine("Please enter a valid search term");
                    _logger.LogInformation($"Invalid search term {key}");
                    userDetails = null;
                    break;
                }
            }
            return(userDetails);
        }
Пример #3
0
        public List <TicketSearchEntity> GetTicketDetails(string key, string value)
        {
            var ticketDetails = new List <TicketSearchEntity>();
            var titleCaseKey  = TitleCaseString.ToTitleCase(key);

            using StreamReader r = new StreamReader(_filePath);
            string json = r.ReadToEnd();

            var allTickets = JsonConvert.DeserializeObject <List <Ticket> >(json);

            foreach (var ticket in allTickets)
            {
                var mapTicket = new TicketSearchEntity();
                if (ticket.GetType().GetTypeInfo().GetDeclaredProperty(titleCaseKey) != null)
                {
                    if (ticket.GetType().GetProperty(titleCaseKey).GetValue(ticket)?.ToString() == value)
                    {
                        if (ticket?.Organization_Id != 0)
                        {
                            var orgDetails = _getOrg.GetOrganizationDetails("Id", ticket.Organization_Id.ToString());

                            mapTicket.Ticket           = ticket;
                            mapTicket.OrganizationName = orgDetails?.FirstOrDefault(r => r.Id == ticket?.Organization_Id).Name;
                        }
                        ticketDetails.Add(mapTicket);
                    }
                }
                else
                {
                    Console.WriteLine("Please enter a valid search term for Tickets");
                    _logger.LogInformation($"Invalid search term {key}");
                    ticketDetails = null;
                    break;
                }
            }
            return(ticketDetails);
        }