Example #1
0
        public bool Guardar(LLamadas llamada)
        {
            Contexto db   = new Contexto();
            bool     paso = false;

            try
            {
                if (db.Llamadas.Any(A => A.LlamadaId == llamada.LlamadaId))
                {
                    paso = Modificar(llamada);
                }
                else
                {
                    paso = Insertar(llamada);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                db.Dispose();
            }
            return(paso);
        }
Example #2
0
        public bool Insertar(LLamadas llamadas)
        {
            Contexto db   = new Contexto();
            bool     paso = false;

            try
            {
                db.Llamadas.Add(llamadas);
                paso = db.SaveChanges() > 0;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                db.Dispose();
            }
            return(paso);
        }
Example #3
0
        public bool  Modificar(LLamadas llamada)
        {
            Contexto db   = new Contexto();
            bool     paso = false;

            try
            {
                var anterior = Buscar(llamada.LlamadaId);

                foreach (var item in llamada.Detalle)
                {
                    if (item.Id == 0)
                    {
                        db.Entry(item).State = EntityState.Added;
                    }
                }

                foreach (var item in anterior.Detalle)
                {
                    if (!llamada.Detalle.Any(A => A.Id == item.Id))
                    {
                        db.Entry(item).State = EntityState.Deleted;
                    }
                }


                db.Entry(llamada).State = EntityState.Modified;
                paso = db.SaveChanges() > 0;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                db.Dispose();
            }

            return(paso);
        }