Exemplo n.º 1
0
        public void OnException(ExceptionContext context)
        {
            context.Result = new JsonResult(BoolResult.Error(context.Exception))
            {
                StatusCode = StatusCodes.Status500InternalServerError
            };
            var mensaje = @$ "Ha habido una exception no controlado.
                {context.Exception}
                {context.HttpContext.Request.Method} {context.HttpContext.Request.QueryString}
                {context.HttpContext.Request.Headers.Aggregate(" headers : ", (s, ns) => s + ns.Key + " : " + ns.Value + " - ")}
                ";

            _logger.LogCritical(mensaje);
        }
Exemplo n.º 2
0
        public BoolResult DeleteTranslate(int idTranslate)
        {
            var translate = context.Translation
                            .Include(t => t.IdWordNavigation)
                            .ThenInclude(w => w.Translation)
                            .FirstOrDefault(t => t.IdTranslation == idTranslate);

            if (translate == null)
            {
                return(BoolResult.Error("Translate not found"));
            }
            context.Entry(translate).State = EntityState.Deleted;

            if (translate.IdWordNavigation.Translation.Count() == 1)
            {
                context.Entry(translate.IdWordNavigation).State = EntityState.Deleted;
            }
            context.SaveChanges();
            return(BoolResult.Ok(true));
        }