public int PostProgresso(MaterialApostilaProgresso progresso)
        {
            var json      = System.Text.Json.JsonSerializer.Serialize(progresso);
            var startDate = DateTime.MinValue;
            var endDate   = DateTime.MinValue;
            int?timeout   = null;

            try
            {
                using (var ctx = new DesenvContext())
                {
                    timeout = ctx.Database.GetCommandTimeout();
                    var result = ctx.tblMaterialApostilaProgresso.FirstOrDefault(x => x.intClientID == progresso.ClientId && x.intApostilaID == progresso.ApostilaId);

                    if (result == null)
                    {
                        result = new tblMaterialApostilaProgresso()
                        {
                            dteDataAlteracao    = DateTime.Now,
                            intApostilaID       = progresso.ApostilaId,
                            intClientID         = progresso.ClientId,
                            dblPercentProgresso = 0
                        };
                        ctx.tblMaterialApostilaProgresso.Add(result);
                    }

                    if (progresso.Progresso <= result.dblPercentProgresso)
                    {
                        return(0);
                    }

                    result.dblPercentProgresso = progresso.Progresso;

                    startDate = DateTime.Now;
                    var retorno = ctx.SaveChanges();
                    endDate = DateTime.Now;

                    return(retorno);
                }
            }
            catch (Exception ex)
            {
                endDate = DateTime.Now;
                Console.WriteLine($@"
###################################################################################

PAYLOAD: {json} - {startDate} - {endDate} - {timeout}
Exception: {ex.Message}
Stack Trace: {ex.StackTrace}
Inner Exception: {(ex.InnerException != null ? ex.InnerException.Message : String.Empty)}
Inner Stack Trace: {(ex.InnerException != null ? ex.InnerException.StackTrace : String.Empty)}

###################################################################################");
                return(0);
            }
        }
        private bool IniciaProgressoApostila(int idMaterial, int matricula, DesenvContext ctx)
        {
            using (MiniProfiler.Current.Step("Registra progresso de apostila"))
            {
                var apostila = ctx.tblMaterialApostila.Any(x => x.intID == idMaterial);

                if (!apostila)
                {
                    return(false);
                }

                var obj = new tblMaterialApostilaProgresso()
                {
                    dteDataAlteracao    = DateTime.Now,
                    intApostilaID       = idMaterial,
                    intClientID         = matricula,
                    dblPercentProgresso = 0
                };

                ctx.tblMaterialApostilaProgresso.Add(obj);

                return(ctx.SaveChanges() == 1);
            }
        }