Example #1
0
        public async Task <bool> GuardarCiudadAsing(CiudadModel modelo)
        {
            bool   respuesta = false;
            Ciudad ciudades  = new Ciudad();

            try
            {
                using (ContextoDatos db = new ContextoDatos())
                {
                    Ciudad ciudad = new Ciudad
                    {
                        CiudadId = modelo.CiudadId,
                        Codigo   = modelo.Codigo,
                        Nombre   = modelo.Nombre,
                    };
                    if (ciudad.CiudadId > 0)
                    {
                        db.Entry(ciudad).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Entry(ciudad).State = EntityState.Added;
                    }
                    db.SaveChanges();
                    // System.Threading.Tasks.Task<int> rta = db.SaveChangesAsync();
                    respuesta = true;
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            return(respuesta);
        }
Example #2
0
        public async System.Threading.Tasks.Task <bool> EliminarCiudad(int ciudad)
        {
            bool   respuesta = false;
            Ciudad ciudades  = new Ciudad();

            try
            {
                using (ContextoDatos db = new ContextoDatos())
                {
                    Ciudad _ciudad = db.Ciudades.Find(ciudad);
                    if (_ciudad.CiudadId > 0)
                    {
                        db.Entry(_ciudad).State = EntityState.Deleted;
                        db.SaveChanges();
                        //System.Threading.Tasks.Task<int> rta = db.SaveChangesAsync();
                        respuesta = true;
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            return(respuesta);
        }
Example #3
0
        public async Task <bool> GuardarVendedorAsing(VendedoresModel modelo)
        {
            bool   respuesta = false;
            Ciudad ciudades  = new Ciudad();

            try
            {
                using (ContextoDatos db = new ContextoDatos())
                {
                    Vendedor vendedor = new Vendedor
                    {
                        Apellido = modelo.Apellido,
                        Numero_Identificacion = modelo.Numero_Identificacion,
                        VendedorId            = modelo.VendedorId,
                        CiudadId = modelo.CiudadId,
                        Codigo   = modelo.Codigo,
                        Nombre   = modelo.Nombre,
                    };
                    if (vendedor.VendedorId > 0)
                    {
                        db.Entry(vendedor).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Entry(vendedor).State = EntityState.Added;
                    }
                    db.SaveChanges();
                    respuesta = true;
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            return(respuesta);
        }
Example #4
0
        public async Task <bool> EliminarVendedor(int codigo)
        {
            bool respuesta = false;

            using (var db = new ContextoDatos())
            {
                var buscar = db.Vendedores.Find(codigo);

                if (buscar.VendedorId > 0)
                {
                    db.Entry(buscar).State = EntityState.Deleted;
                    db.SaveChanges();
                    respuesta = true;
                }
            }
            return(respuesta);
        }
Example #5
0
        public async System.Threading.Tasks.Task <bool> GuardarTransaccionAsing(Models.ModeloCompleto modelo)
        {
            bool respuesta = false;

            using (ContextoDatos db = new ContextoDatos())
            {
                using (DbContextTransaction transaccion = db.Database.BeginTransaction())
                {
                    try
                    {
                        Datos.Entidades.Ciudad _ciudad = new Ciudad
                        {
                            CiudadId = modelo.ciudad.CiudadId,
                            Codigo   = modelo.ciudad.Codigo,
                            Nombre   = modelo.ciudad.Nombre,
                        };

                        if (_ciudad.CiudadId == 0)
                        {
                            db.Entry(_ciudad).State = EntityState.Added;
                        }
                        else
                        {
                            db.Entry(_ciudad).State = EntityState.Modified;
                        }
                        int numero = await db.SaveChangesAsync();

                        foreach (var vendedor in modelo.vendedores)
                        {
                            Vendedor _vendedor = new Datos.Entidades.Vendedor
                            {
                                Apellido = vendedor.Apellido,
                                CiudadId = vendedor.CiudadId,
                                Codigo   = vendedor.Codigo,
                                Nombre   = vendedor.Nombre,
                                Numero_Identificacion = vendedor.Numero_Identificacion,
                                VendedorId            = vendedor.VendedorId,
                            };

                            if (_vendedor.CiudadId == 0)
                            {
                                db.Entry(_vendedor).State = EntityState.Added;
                            }
                            else
                            {
                                db.Entry(_vendedor).State = EntityState.Modified;
                            }
                            int numero2 = await db.SaveChangesAsync();
                        }
                        transaccion.Commit();
                        respuesta = true;
                    }
                    catch (Exception ex)
                    {
                        transaccion.Rollback();
                        throw (ex);
                    }
                    return(respuesta);
                }
            }
        }