1

May I know why that error keeps pointing to "String isEmailVerified ...."?

public JsonResult GetMemberCounts([FromBody] ChartFilterRequest filter)
        {
            DateTime startDate = DateTime.Parse(filter.MainFilter.First(m => m.Name == "startDate").Value as string);
            DateTime endDate = DateTime.Parse(filter.MainFilter.First(m => m.Name == "endDate").Value as string);
            String isEmailVerified = filter.MainFilter.First(m => m.Name == "isEmailVerified").Value as string;


            var data = _dashboardComponent.GetMemberCount(startDate, endDate, isEmailVerified);

            return new JsonResult(data);
        }

1
  • 1
    One of your filter.MainFilter.First(...) is failing because no according element can be found ... Commented May 24, 2022 at 8:16

1 Answer 1

1

Try using FirstOrDefault and LastOrDefault instead of First and Last, these methods will return the default value of the type they are invoked for if no elements match the lambda expression you provide as a parameter.

In your project, You just use filter.MainFilter.First(xxxx) to select the data, So if no elements match the lambda expression you provide as a parameter,First() will throw an exception, So here will report this error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.