none
how to return NotFound() result RRS feed

  • Question

  • I am trying to return NotFound() result. 

     [Route("~/api/patient/{patientId:int}/reactions/{id:int?}")]
            [ResponseType(typeof(IEnumerable<Reaction>))]
            public async Task<IHttpActionResult> GetReactionsByPatientId(int patientId, int id = 0)
            {
                return await Task.Run(() =>
                {
                    IEnumerable<Reaction> reactionsByPatient = ReactionRepo.GetReactionsByPatientId(patientId).Result;
    
                    if (reactionsByPatient == null)
                    {
                        return NotFound();
                    }
    
                    if (id != 0)
                    {
                        reactionsByPatient = reactionsByPatient.Where(I => I.Id == id);
                    }
    
                    if (reactionsByPatient == null)
                    {
                        return NotFound();
                    }
    
                    return Ok(reactionsByPatient);
                });
            }

    the error messages are

    CS0029 C# Cannot implicitly convert type to 'System.Threading.Tasks.Task'

    CS8030 C# Anonymous function converted to a void returning delegate cannot return a value

    CS1662 C# Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type

    Monday, June 11, 2018 10:06 AM

All replies