Basit Nisar

Basit Nisar

  • 1.7k
  • 84
  • 11k

getting records in invalidemployeenumber list

May 26 2023 10:36 AM

Here is my PUT Method i have to update the list I have emplyeeID as String which has values from [4-14] in length but my method is throwing error when i pass employeeID below 5 or greater than 5 let me know where I am missing 

Put(SurveyRecipientViewList _SurveyRecipientViewList)
{
    if (!ModelState.IsValid)
    {
    }
    ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;
    Int32 LogedInID = Convert.ToInt32(principal.Claims.FirstOrDefault(t => t.Type == "LogedInID").Value);
    //    RecipientRecords _RecipientRecords = new RecipientRecords();
    var result = from c in db.Contacts
                 join cm in db.ContactEmails on c.ContactID equals cm.ContactID
                 select new SurveyRecipientView
                 {
                     EmployeeID = c.EmployeeNumber,
                     FirstName = c.FirstName,
                     LastName = c.LastName,
                     EmailAddress = cm.EmailAddress
                 };
    List<SurveyRecipientView> axe = new List<SurveyRecipientView>();
    axe = result.ToList<SurveyRecipientView>();
    ValidateRecipientList _ValidateRecipientList = new ValidateRecipientList();
    try
    {
        //  string strRegex = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,10})+)$";
        string strRegex = @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
          @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$";
        string numericRegex = @"^[0-9]{5}$";
        var NumericRegEx = new Regex(numericRegex, RegexOptions.IgnoreCase);
        var EmailRegEx = new Regex(strRegex, RegexOptions.IgnoreCase);
        _ValidateRecipientList.DuplicateRecords = _SurveyRecipientViewList.SurveyRecipientView
            .GroupBy(grp => new { grp.EmailAddress, grp.EmployeeID, grp.FirstName, grp.LastName })
           .Where(g => g.Count() > 1)
            .Select(grp => grp.FirstOrDefault())
           .ToList<SurveyRecipientView>();
        _ValidateRecipientList.DistinctRecords = _SurveyRecipientViewList.SurveyRecipientView
           .GroupBy(grp => new { grp.EmailAddress, grp.EmployeeID, grp.FirstName, grp.LastName })
           .Select(grp => grp.FirstOrDefault())
          .ToList<SurveyRecipientView>();
        _ValidateRecipientList.InvalidEmailAddress = _ValidateRecipientList.DistinctRecords
         .Where(t => !EmailRegEx.IsMatch(t.EmailAddress))
         .ToList<SurveyRecipientView>();
        _ValidateRecipientList.DistinctRecords = _ValidateRecipientList.DistinctRecords.Except(_ValidateRecipientList.InvalidEmailAddress).ToList<SurveyRecipientView>();
        _ValidateRecipientList.InvalidEmployeeNo = _ValidateRecipientList.DistinctRecords
            .Where(t => !NumericRegEx.IsMatch(t.EmployeeID.Trim() == "" ? "00000" : t.EmployeeID))
            .ToList<SurveyRecipientView>();
        _ValidateRecipientList.DistinctRecords = _ValidateRecipientList.DistinctRecords.Except(_ValidateRecipientList.InvalidEmployeeNo).ToList<SurveyRecipientView>();


Answers (2)