private async Task <bool> isEmployeeNameAlreadyExisted(EmployeeSaveDto resourceSave) { return(await _context.Employees .AnyAsync(x => x.FirstName.ToLower() == resourceSave.FirstName.ToLower() && x.MiddleName.ToLower() == resourceSave.MiddleName.ToLower() && x.LastName.ToLower() == resourceSave.LastName.ToLower())); }
public async Task <ErrorValidator> Validate(Employee entity, EmployeeSaveDto resourceSave) { if (entity.FirstName != resourceSave.FirstName || entity.MiddleName != resourceSave.MiddleName || entity.LastName != resourceSave.LastName) { if (await isEmployeeNameAlreadyExisted(resourceSave)) { return(new ErrorValidator("Employee Name Already Existed")); } } if (entity.EmailAddress != resourceSave.EmailAddress) { if (await isEmailAddressTaken(resourceSave.EmailAddress)) { return(new ErrorValidator("Email Already Taken")); } } if (entity.ContactNumber != resourceSave.ContactNumber) { if (await isContactNumberTaken(resourceSave.ContactNumber)) { return(new ErrorValidator("Contact Number Already Existed")); } } if (entity.WorkLocationId != resourceSave.WorkLocationId) { if (!await isWorkLocationExisted(resourceSave.WorkLocationId)) { return(new ErrorValidator("Work Location Selected Doesn't Existed")); } } return(new ErrorValidator()); }
public async Task <ErrorValidator> Validate(EmployeeSaveDto resourceSave) { if (await isEmployeeNameAlreadyExisted(resourceSave)) { return(new ErrorValidator("Employee Name Already Existed")); } if (await isEmailAddressTaken(resourceSave.EmailAddress)) { return(new ErrorValidator("Email Already Taken")); } if (await isContactNumberTaken(resourceSave.ContactNumber)) { return(new ErrorValidator("Contact Number Already Existed")); } if (!await isWorkLocationExisted(resourceSave.WorkLocationId)) { return(new ErrorValidator("Work Location Selected Doesn't Existed")); } return(new ErrorValidator()); }