Exemplo n.º 1
0
        public async Task <ActionResult <List <HCperson> > > SearchHCperson(HCperson i_oHCperson, [FromQuery] HCparameter i_oHCparam)
        {
            if (i_oHCparam.Delay > 0)
            {
                await Task.Delay(TimeSpan.FromSeconds(i_oHCparam.Delay));
            }

            if (i_oHCperson == null)
            {
                return(NotFound());
            }

            if (String.IsNullOrEmpty(i_oHCperson.FirstName) && String.IsNullOrEmpty(i_oHCperson.LastName))
            {
                ValidationProblemDetails oValDetails = new ValidationProblemDetails();
                oValDetails.Title = "At least First Name or Last Name must be supplied.";
                return(ValidationProblem(oValDetails));
            }

            ActionResult <List <HCperson> > hcPerson = await GetHCpersonToSearch(i_oHCperson);

            if (hcPerson == null)
            {
                return(NotFound());
            }

            return(hcPerson);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Uses the whera clause to find the entry that matches exactly to the given name.  It will mtach either the FirstName, LastName or both in the search.  It uses an exact comparison for the values.
        /// </summary>
        /// <param name="i_oHCperson">Only the FirstName or LastName are requied to be populated.</param>
        /// <returns></returns>
        private async Task <ActionResult <List <HCperson> > > GetHCpersonToSearch(HCperson i_oHCperson)
        {
            List <HCperson> hcPerson;

            if (String.IsNullOrEmpty(i_oHCperson.FirstName))
            {
                hcPerson = await(m_context.HCpersons.Where(sb1 => sb1.LastName == i_oHCperson.LastName).ToListAsync <HCperson>());
            }
            else if (String.IsNullOrEmpty(i_oHCperson.LastName))
            {
                hcPerson = await(m_context.HCpersons.Where(sb2 => sb2.FirstName == i_oHCperson.FirstName).ToListAsync <HCperson>());
            }
            else
            {
                hcPerson = await(m_context.HCpersons.Where(sb3 => sb3.LastName == i_oHCperson.LastName).Where(s4 => s4.FirstName == i_oHCperson.FirstName).ToListAsync <HCperson>());
            }
            return(hcPerson);
        }
Exemplo n.º 3
0
        public async Task <ActionResult <HCperson> > CreateHCperson(HCperson i_oHCperson, [FromQuery] HCparameter i_oHCparam)
        {
            if (i_oHCparam.Delay > 0)
            {
                await Task.Delay(TimeSpan.FromSeconds(i_oHCparam.Delay));
            }

            if (String.IsNullOrEmpty(i_oHCperson.FirstName) || String.IsNullOrEmpty(i_oHCperson.LastName))
            {
                ValidationProblemDetails oValDetails = new ValidationProblemDetails();
                oValDetails.Title = "First Name and Last Name values are both required.";
                return(ValidationProblem(oValDetails));
            }
            m_context.HCpersons.Add(i_oHCperson);
            await m_context.SaveChangesAsync();

            return(CreatedAtAction(
                       nameof(GetHCperson),
                       new { id = i_oHCperson.ID },
                       i_oHCperson));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Uses the whera clause to find the entry that contains to the given name value.  It will contain either the FirstName, LastName or both in the search.  It uses a contain comparison for the values.
        /// </summary>
        /// <param name="i_oHCperson">Only the FirstName or LastName are requied to be populated.</param>
        /// <returns></returns>
        private async Task <ActionResult <List <HCperson> > > GetHCpersonToSearchContains(HCperson i_oHCperson)
        {
            List <HCperson> hcPerson;

            if (String.IsNullOrEmpty(i_oHCperson.FirstName))
            {
                hcPerson = await(m_context.HCpersons.Where(sb1 => sb1.LastName.Contains(i_oHCperson.LastName, StringComparison.OrdinalIgnoreCase)).ToListAsync <HCperson>());
            }
            else if (String.IsNullOrEmpty(i_oHCperson.LastName))
            {
                hcPerson = await(m_context.HCpersons.Where(sb2 => sb2.FirstName.Contains(i_oHCperson.FirstName, StringComparison.OrdinalIgnoreCase)).ToListAsync <HCperson>());
            }
            else
            {
                hcPerson = await(m_context.HCpersons.Where(sb3 => sb3.LastName.Contains(i_oHCperson.LastName, StringComparison.OrdinalIgnoreCase)).Where(s4 => s4.FirstName.Contains(i_oHCperson.FirstName, StringComparison.OrdinalIgnoreCase)).ToListAsync <HCperson>());
            }
            return(hcPerson);
        }