public async Task <Result> ForgotPassword(string identityNumber)
        {
            if (string.IsNullOrEmpty(identityNumber))
            {
                return(new ErrorResult("identity Number is Wrong!"));
            }

            var user = await _personRepository.GetAsync(x => x.UserName == identityNumber);

            if (user == null)
            {
                return(new ErrorResult("identity Number is not found!"));
            }


            var password = RandomHelper.Mixed(6);
            var result   = await _smsHelper.SendAsync(new List <string> {
                user.Gsm
            }, "Your new password is " + password);

            if (!result.Success)
            {
                return(result);
            }

            HashingHelper.CreatePasswordHash(password, out var passwordHash, out var passwordSalt);
            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            result            = await _personRepository.UpdateAsync(user);

            return(!result.Success ? result : new SuccessResult("Your password is sent to your gsm!"));
        }
Example #2
0
        public async Task <Result> SOSAsync(int personId, SOSDto sos)
        {
            var patient = await _repository.TableNoTracking.Include(x => x.Person).FirstOrDefaultAsync(x => x.PersonId == personId);

            var relatives = await _patientRelativeRepo.TableNoTracking.Where(x => x.PatientId == patient.Id)
                            .ToListAsync();

            var url    = $"http://maps.google.com/?q={sos.Latitude},{sos.Longitude}";
            var phones = relatives.Select(x => x.Gsm).ToList();

            return(await _smsHelper.SendAsync(phones, $"My Name is {patient.Person.FirstName} {patient.Person.LastName}, Help Me!! My Location :  " + url));
        }
        public async Task <DataResult <GetAdminDto> > InsertAsync(InsertAdminDto insertAdminDto)
        {
            var randomPass = RandomHelper.Mixed(6);

            HashingHelper.CreatePasswordHash(randomPass, out var passwordHash, out var passwordSalt);

            var admin = new Admin
            {
                Email    = insertAdminDto.Email,
                IsActive = true,
                Person   = new Person
                {
                    FirstName       = insertAdminDto.FirstName,
                    LastName        = insertAdminDto.LastName,
                    UserName        = insertAdminDto.Email,
                    Gsm             = insertAdminDto.Gsm,
                    PersonType      = PersonType.Admin,
                    CreatedUserName = "",
                    CreatedAt       = DateTime.Now,
                    PasswordHash    = passwordHash,
                    PasswordSalt    = passwordSalt,
                    RefreshToken    = RandomHelper.Mixed(32)
                }
            };

            await _repository.InsertAsync(admin);

            await _smsHelper.SendAsync(new List <string> {
                admin.Person.Gsm
            },
                                       "Welcome to the PatientTracker System. \n You are registered to patientTracker.net as Admin by " + _userService.FullName + " \n Your password is " + randomPass + "\n Wis");

            var result = await _repository.TableNoTracking.Where(x => x.Id == admin.Id)
                         .Include(x => x.Person)
                         .FirstOrDefaultAsync();

            var res = new SuccessDataResult <GetAdminDto>(new GetAdminDto
            {
                PersonId  = result.PersonId,
                UserName  = result.Person.UserName,
                FirstName = result.Person.FirstName,
                LastName  = result.Person.LastName,
                Gsm       = result.Person.Gsm,
                IsActive  = admin.IsActive
            });

            return(res);
        }
Example #4
0
        public async Task <DataResult <GetDoctorDto> > InsertAsync(InsertDoctorDto insertDoctorDto)
        {
            var randomPass = RandomHelper.Mixed(6);

            HashingHelper.CreatePasswordHash(randomPass, out var passwordHash, out var passwordSalt);

            var doctor = new Doctor
            {
                Email        = insertDoctorDto.Email,
                IsActive     = true,
                DepartmentId = insertDoctorDto.DepartmentId,
                DegreeId     = insertDoctorDto.DegreeId,
                Person       = new Person
                {
                    FirstName               = insertDoctorDto.FirstName,
                    LastName                = insertDoctorDto.LastName,
                    Gsm                     = insertDoctorDto.Gsm,
                    CreatedAt               = DateTime.Now,
                    CreatedUserName         = _userService.FullName,
                    PersonType              = PersonType.Doctor,
                    UserName                = insertDoctorDto.Email,
                    PasswordHash            = passwordHash,
                    PasswordSalt            = passwordSalt,
                    RefreshToken            = RandomHelper.Mixed(32),
                    RefreshTokenExpiredDate = DateTime.Now.AddDays(-1)
                }
            };

            await _doctorRepo.InsertAsync(doctor);

            var hospital = await _doctorRepo.TableNoTracking
                           .Include(x => x.Department)
                           .Where(x => x.PersonId == doctor.PersonId)
                           .Select(x => x.Department.Hospital.Description)
                           .FirstOrDefaultAsync();


            await _smsHelper.SendAsync(new List <string> {
                doctor.Person.Gsm
            },
                                       "Welcome to the " + hospital + " \n You are registered to patracker as Doctor by " + _userService.FullName + " \n Your password is " + randomPass);


            var result = await _doctorRepo.TableNoTracking.Where(x => x.PersonId == doctor.PersonId)
                         .Include(x => x.Person)
                         .Include(x => x.Department)
                         .Include(x => x.Degree)
                         .FirstOrDefaultAsync();

            var res = new SuccessDataResult <GetDoctorDto>(new GetDoctorDto
            {
                Id             = result.Id,
                Email          = result.Email,
                FirstName      = result.Person.FirstName,
                LastName       = result.Person.LastName,
                Gsm            = result.Person.Gsm,
                DepartmentName = result.Department.Description,
                DegreeName     = result.Degree.Description
            });

            return(res);
        }