public async Task <Admin> AddAdmin(Admin admin) { var maxtrys = _appConfig.MaxTrys; var timeTowait = TimeSpan.FromSeconds(_appConfig.Time); var retryPolly = Policy.Handle <Exception>().WaitAndRetryAsync(maxtrys, i => timeTowait); return(await retryPolly.ExecuteAsync(async() => { var data = await _adminRepository.Add(AdminMapper.Map(admin)); return AdminMapper.Map(data); })); }
public async Task <Admin> AddAdmin(Admin admin) { var maxTrys = _appConfig.MaxTrys; var timeToWait = TimeSpan.FromSeconds(_appConfig.SecondsToWait); var retryPolity = Policy.Handle <Exception>().WaitAndRetryAsync(maxTrys, i => timeToWait); // Politica para reintentar consultar llegado el caso exista un error en el servidor return(await retryPolity.ExecuteAsync(async() => { var addedEntity = await _AdminRepository.Add(AdminMapper.Map(admin)); return AdminMapper.Map(addedEntity); })); }
/// <summary> /// Abre una sesión de administrador. /// Envia al repositorio las credenciales del administrador. /// Si el repositorio reconoce las credenciales, instancia /// un token para el role Admin. /// </summary> /// <param name="admin"> /// Objeto Admin con las credenciales /// </param> /// <exception cref="WrongCredentialsException"> /// Lanza WrongCredentialsException /// </exception> /// <returns> /// retorna un objeto que contiene el token creado y /// el id del administrador /// </returns> public async Task <AdminSignInResponse> SignIn(Admin admin)//Throw WrongCredentialsException { AdminEntity adminEntity = AdminMapper.Map(admin); var signedInAdmin = await _adminRepository.Exists(adminEntity); string token = _authService .GenerateToken(signedInAdmin.AdminName + signedInAdmin.Password, Role.ADMIN); AdminSignInResponse response = new AdminSignInResponse { Id = adminEntity.Id, Token = token }; return(response); }
public async Task <Admin> UpdateAdmin(Admin admin) { var data = await _adminRepository.Update(AdminMapper.Map(admin)); return(admin); }
public async Task <Admin> GetAdmin(int id) { var data = await _adminRepository.Get(id); return(AdminMapper.Map(data)); }
public async Task <IActionResult> UpdateAdmin([FromBody] AdminModel admin) { var name = await _adminService.UpdateAdmin(AdminMapper.Map(admin)); return(Ok(name)); }
public async Task <Admin> GetAdmin(int id) { var entidad = await _adminRepository.Get(id); return(AdminMapper.Map(entidad)); }
public async Task <IActionResult> Update(int id, [FromBody] AdminModel admin) { var data = await _adminService.UpdateAdmin(AdminMapper.Map(admin)); return(Ok(data)); }
public async Task <IActionResult> Add([FromBody] AdminModel admin) { var data = await _adminService.AddAdmin((AdminMapper.Map(admin))); return(Ok(data)); }
public async Task <IActionResult> AddAdmin([FromBody] AdminModel admin) { var newAdmin = await _adminService.AddAdmin(AdminMapper.Map(admin)); return(Ok(newAdmin)); }
public async Task <Admin> UpdateAdmin(Admin admin) { var updated = await _AdminRepository.Update(AdminMapper.Map(admin)); return(AdminMapper.Map(updated)); }