/// <inheritdoc/> public Task <T> GetBySpecAsync <Spec>(Spec specification, CancellationToken cancellationToken = default) where Spec : ISingleResultSpecification, ISpecification <T> { if (specification.CacheEnabled) { string key = $"{specification.CacheKey}-GetBySpecAsync"; _logger.LogInformation("Checking cache for " + key); return(_cache.GetOrCreate(key, entry => { entry.SetOptions(_cacheOptions); _logger.LogWarning("Fetching source data for " + key); return _sourceRepository.GetBySpecAsync(specification, cancellationToken); })); } return(_sourceRepository.GetBySpecAsync(specification, cancellationToken)); }
public async Task <IActionResult> OnPost() { try { var existeNegocio = await _repository.GetBySpecAsync(new ProductoPorNombreSpec(Producto.Nombre, Producto.NegocioId)); if (existeNegocio != null) { _notifyService.Warning($"Ya existe un negocio con el nombre {Producto.Nombre}."); return(RedirectToPage("Create", new { negocioId = Producto.NegocioId })); } if (ModelState.IsValid) { await _repository.AddAsync(Producto); _notifyService.Success("Producto agregada exitosamente"); } else { _notifyService.Warning("El formulario no cumple las reglas de negocio"); return(RedirectToPage("Create", new { negocioId = Producto.NegocioId })); } return(RedirectToPage("Index", new { negocioId = Producto.NegocioId })); } catch (Exception ex) { _logger.LogWarning(ex.Message); _notifyService.Error("Ocurrio un error en el servidor, intente nuevamente"); return(RedirectToPage("Index")); } }