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);
            }
        }
Esempio n. 2
0
 public int PostProgressoApostila(MaterialApostilaProgresso progresso)
 {
     return(new MaterialApostilaEntity().PostProgresso(progresso));
 }