Пример #1
0
        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);
        }
Пример #2
0
        public async Task <Result> UpdateAsync(int adminId, InsertAdminDto insertAdminDto)
        {
            var admin = await _repository.GetAsync(adminId);

            admin.Email = insertAdminDto.Email;

            var result = await _repository.UpdateAsync(admin);

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

            var person = await _personRepo.GetAsync(x => x.Id == admin.PersonId);

            admin.Person.FirstName = insertAdminDto.FirstName;
            admin.Person.LastName  = insertAdminDto.LastName;
            admin.Person.Gsm       = insertAdminDto.Gsm;
            return(await _personRepo.UpdateAsync(person));
        }
 public async Task <IActionResult> Update([FromQuery] int adminId, [FromBody] InsertAdminDto admin)
 {
     return(Ok(await _adminService.UpdateAsync(adminId, admin)));
 }
 public async Task <IActionResult> Post([FromBody] InsertAdminDto dto)
 {
     return(Ok(await _adminService.InsertAsync(dto)));
 }