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 axe = new List();
axe = result.ToList();
ValidateRecipientList _ValidateRecipientList = new ValidateRecipientList();
try
{
// string strRegex = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,10})+)$";
string strRegex = @"^(?("")("".+?(? new { grp.EmailAddress, grp.EmployeeID, grp.FirstName, grp.LastName })
.Where(g => g.Count() > 1)
.Select(grp => grp.FirstOrDefault())
.ToList();
_ValidateRecipientList.DistinctRecords = _SurveyRecipientViewList.SurveyRecipientView
.GroupBy(grp => new { grp.EmailAddress, grp.EmployeeID, grp.FirstName, grp.LastName })
.Select(grp => grp.FirstOrDefault())
.ToList();
_ValidateRecipientList.InvalidEmailAddress = _ValidateRecipientList.DistinctRecords
.Where(t => !EmailRegEx.IsMatch(t.EmailAddress))
.ToList();
_ValidateRecipientList.DistinctRecords = _ValidateRecipientList.DistinctRecords.Except(_ValidateRecipientList.InvalidEmailAddress).ToList();
_ValidateRecipientList.InvalidEmployeeNo = _ValidateRecipientList.DistinctRecords
.Where(t => !NumericRegEx.IsMatch(t.EmployeeID.Trim() == "" ? "00000" : t.EmployeeID))
.ToList();
_ValidateRecipientList.DistinctRecords = _ValidateRecipientList.DistinctRecords.Except(_ValidateRecipientList.InvalidEmployeeNo).ToList();
Amit MohantyPosted May 26, 2023, 1:51 PM
I think the issue lies in the regular expression used to validate the employee ID. The regex pattern
@"^[0-9]{5}$"matches exactly 5 digits. However, you mentioned that the employee ID can have a length between 4 and 14. Try this once:Rajkiran SwainPosted May 26, 2023, 10:43 AM