public async Task <GenericResponse <string> > AddDobi(Dobi dobi) { try { if (string.IsNullOrWhiteSpace(dobi.PassportNumber) && string.IsNullOrWhiteSpace(dobi.IcNumber)) { return(new GenericResponse <string>(false, null, "Passport or IC number is required")); } if (!await _dobiRepository.IsEmailAvailable(dobi.Email)) { return(new GenericResponse <string>(false, null, "Email is not available")); } else if (!await _dobiRepository.IsPhoneNumberAvailable(dobi.Phone)) { return(new GenericResponse <string>(false, null, "Phone number is not available")); } else if (!string.IsNullOrWhiteSpace(dobi.PassportNumber)) { if (!await _dobiRepository.IsPassportNumberAvailable(dobi.PassportNumber)) { return(new GenericResponse <string>(false, null, "Passport number is not available")); } } else if (!string.IsNullOrWhiteSpace(dobi.IcNumber)) { if (!await _dobiRepository.IsIcNumberAvailable(dobi.IcNumber)) { return(new GenericResponse <string>(false, null, "IC number is not available")); } } else if (!string.IsNullOrWhiteSpace(dobi.DrivingLicense) && !await _dobiRepository.IsDrivingLicenseAvailable(dobi.DrivingLicense)) { return(new GenericResponse <string>(false, null, "Driving license is not available")); } dobi.JoinDate = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds; var response = await _dobiRepository.AddDobi(dobi); if (!response) { return(new GenericResponse <string>(false, null, "Error adding Dobi.")); } return(new GenericResponse <string>(true, null, "Dobi added successfully.")); } catch (Exception exception) { throw new Exception("Error adding dobi" + exception); } }
public async Task <IHttpActionResult> CheckIcNumberAvailability(string icnumber) { if (string.IsNullOrWhiteSpace(icnumber)) { return(BadRequest("Invalid ic number.")); } var response = await _dobiRepository.IsIcNumberAvailable(icnumber); return(Ok(new GenericResponse <bool>(true, response))); }