private int AdicionaNovos(MaterialApostilaInteracoes comentarios)
        {
            using (MiniProfiler.Current.Step("Adiciona novas interações de apostila"))
            {
                using (var ctx = new DesenvContext())
                {
                    var novos = comentarios
                                .Where(x => x.Id == 0)
                                .Select(x => new tblMaterialApostilaInteracao()
                    {
                        intID            = 0,
                        intClientID      = x.ClientId,
                        txtInteracaoID   = x.AnotacaoId,
                        intApostilaID    = x.ApostilaId,
                        txtComentario    = x.Comentario,
                        txtConteudo      = x.Conteudo,
                        intVersaoMinima  = x.VersaoMinima,
                        intVersaoMaxima  = 0,
                        intTipoInteracao = x.TipoInteracao
                    })
                                .ToList();

                    novos.ForEach(x => ctx.tblMaterialApostilaInteracao.Add(x));

                    return(ctx.SaveChanges());
                }
            }
        }
        public int PostInteracoes(MaterialApostilaInteracoes interacoes)
        {
            try
            {
                var novosInteracoes       = AdicionaNovos(interacoes);
                var interacoesAtualizadas = AtualizaModificacoes(interacoes);

                if (novosInteracoes + interacoesAtualizadas < 1)
                {
                    return(0);
                }

                return(1);
            }
            catch
            {
                throw;
            }
        }
        private int AtualizaModificacoes(MaterialApostilaInteracoes interacoes)
        {
            using (MiniProfiler.Current.Step("Atualiza interações de apostila"))
            {
                using (var ctx = new DesenvContext())
                {
                    interacoes
                    .Where(x => x.Id != 0)
                    .ToList()
                    .ForEach(y =>
                    {
                        var anotacao              = ctx.tblMaterialApostilaInteracao.FirstOrDefault(z => z.intID == y.Id);
                        anotacao.intVersaoMaxima  = y.VersaoMaxima;
                        anotacao.txtComentario    = y.Comentario;
                        anotacao.txtConteudo      = y.Conteudo;
                        ctx.Entry(anotacao).State = EntityState.Modified;
                    });

                    return(ctx.SaveChanges());
                }
            }
        }
 public int PostInteracoesApostila(MaterialApostilaInteracoes interacoes)
 {
     return(new MaterialApostilaEntity().PostInteracoes(interacoes));
 }