コード例 #1
0
        //metodo eliminar

        public void eliminar()
        {
            try
            {
                using (var db = new proyecto_ARTC())
                {
                    db.Entry(this).State = EntityState.Deleted;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #2
0
        // metodo guardar

        public void guardar()
        {
            try
            {
                using (var db = new proyecto_ARTC())
                {
                    if (this.control_id > 0)
                    {
                        //si existe un valor mayor a cero es porque exiiste el registro
                        db.Entry(this).State = EntityState.Modified;
                    }
                    else
                    {
                        //si no existe el registro lo graba(nuevo)
                        db.Entry(this).State = EntityState.Added;
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #3
0
        ////metodo guardar perfil

        public ResponseModel guardarperfil(HttpPostedFileBase foto)
        {
            var rm = new ResponseModel();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    db.Configuration.ValidateOnSaveEnabled = false;

                    var usu = db.Entry(this);
                    usu.State = EntityState.Modified; //permite modificar el usuario

                    if (foto != null)
                    {
                        string extension = Path.GetExtension(foto.FileName).ToLower(); //el path me permite obtener algunas propiedades del archivo

                        int size            = 1024 * 1014 * 5;                         //es el tamaño que recibe
                        var filtroextension = new[] { ".jpg", ".jpeg", ".png", ".gif" };
                        var extensiones     = Path.GetExtension(foto.FileName);        //la foto

                        if (filtroextension.Contains(extensiones) && (foto.ContentLength <= size))
                        {
                            string archivo = Path.GetFileName(foto.FileName);//es lo que vamos a obtener

                            //la ruta doonde guardaremos las imagenes
                            foto.SaveAs(HttpContext.Current.Server.MapPath("~/fotousu/" + archivo));
                            this.foto_usu = archivo;
                        }
                    }
                    else
                    {
                        usu.Property(x => x.foto_usu).IsModified = false;
                    }

                    if (this.usuario_id == 0)
                    {
                        usu.Property(x => x.usuario_id).IsModified = false;
                    }
                    if (this.persona_id == 0)
                    {
                        usu.Property(x => x.persona_id).IsModified = false;
                    }
                    if (this.nomb_usu == null)
                    {
                        usu.Property(x => x.nomb_usu).IsModified = false;
                    }
                    if (this.pas_usu == null)
                    {
                        usu.Property(x => x.pas_usu).IsModified = false;
                    }
                    if (this.nivel_usu == null)
                    {
                        usu.Property(x => x.nivel_usu).IsModified = false;
                    }
                    if (this.estado_usu == null)
                    {
                        usu.Property(x => x.estado_usu).IsModified = false;
                    }

                    db.SaveChanges();
                    rm.SetResponse(true);
                }
            }
            catch (DbEntityValidationException e)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
            return(rm);
        }