Exemplo n.º 1
0
        private async Task RemoveEndingServices()
        {
            InProgress = true;
            try
            {
                using (var scope = _serviceScopeFactory.CreateScope())
                {
                    IBaseRepository <Servicio> _servicioRepository = scope.ServiceProvider.GetRequiredService <IBaseRepository <Servicio> >();
                    var servicios = await _servicioRepository.ListBy(s => s.Active == true &&
                                                                     s.FechaFin <= DateTime.Now);

                    IServicioService _servicioService = scope.ServiceProvider.GetRequiredService <IServicioService>();
                    foreach (var servicio in servicios)
                    {
                        await _servicioService.RemoveAsEnding(servicio.Id);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                InProgress = false;
            }
        }