Пример #1
0
        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);
            }
        }
Пример #2
0
        public async Task <IHttpActionResult> CheckEmailAvailability(string email)
        {
            if (!Utilities.IsValidEmailAddress(email))
            {
                return(BadRequest("Invalid email address."));
            }
            var response = await _dobiRepository.IsEmailAvailable(email);

            return(Ok(new GenericResponse <bool>(true, response)));
        }