コード例 #1
0
ファイル: Documentos.aspx.cs プロジェクト: Mustahai/yourPEL
        // O nome do parâmetro id deve corresponder ao valor DataKeyNames definido no controle
        public void docsGridView_UpdateItem(DOCUMENTO item)
        {
            using (YourPELcs ctx = new YourPELcs())
            {
                DOCUMENTO doc = ctx.DOCUMENTOes.Find(item.idDocumento);
                // Carregue o item aqui, por exemplo item = MyDataLayer.Find(id);
                if (doc == null)
                {
                    // O item não foi encontrado
                    ModelState.AddModelError("", String.Format("O item com id {0} não foi encontrado", item.idDocumento));
                    return;
                }
                TryUpdateModel(doc);



                if (ModelState.IsValid)
                {
                    if ((doc.tema.ToString() != "Alimentação") &&
                        (doc.tema.ToString() != "Consumos Nocivos") &&
                        (doc.tema.ToString() != "Sexualidade"))
                    {
                        lblFeedback2.Text = "Campo 'Tema' inválido! ('Alimentação', 'Consumos Nocivos' ou 'Sexualidade')";
                    }
                    else
                    {
                        // Salve alterações aqui, por exemplo MyDataLayer.SaveChanges();
                        ctx.SaveChanges();
                    }
                }
            }
        }
コード例 #2
0
ファイル: Documentos.aspx.cs プロジェクト: Mustahai/yourPEL
        // O tipo de retorno pode ser alterado para IEnumerable, no entanto, para dar suporte à paginação de
        // e classificação, os seguintes parâmetros devem ser adicionados:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <DOCUMENTO> docsGridView_GetData()
        {
            YourPELcs db    = new YourPELcs();
            var       query = db.DOCUMENTOes;

            return(query);
        }
コード例 #3
0
ファイル: Videos.aspx.cs プロジェクト: Mustahai/yourPEL
        // The return type can be changed to IEnumerable, however to support
        // paging and sorting, the following parameters must be added:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable GridViewEditar_GetData()
        {
            YourPELcs db    = new YourPELcs();
            var       query = db.ARTIGOes;

            return(query);
        }
コード例 #4
0
ファイル: Documentos.aspx.cs プロジェクト: Mustahai/yourPEL
 // O nome do parâmetro id deve corresponder ao valor DataKeyNames definido no controle
 public void docsGridView_DeleteItem(DOCUMENTO item)
 {
     using (YourPELcs ctx = new YourPELcs())
     {
         DOCUMENTO doc = ctx.DOCUMENTOes.Find(item.idDocumento);
         // Carregue o item aqui, por exemplo item = MyDataLayer.Find(id);
         if (doc == null)
         {
             // O item não foi encontrado
             ModelState.AddModelError("", String.Format("O item com id {0} não foi encontrado", item.idDocumento));
             return;
         }
         ctx.DOCUMENTOes.Remove(doc);
         TryUpdateModel(doc);
         if (ModelState.IsValid)
         {
             // Salve alterações aqui, por exemplo MyDataLayer.SaveChanges();
             ctx.SaveChanges();
         }
     }
 }
コード例 #5
0
ファイル: EditarEvento.aspx.cs プロジェクト: Mustahai/yourPEL
        // The id parameter name should match the DataKeyNames value set on the control
        public void GridViewEditar_UpdateItem(int idEvento)
        {
            //Editar
            using (YourPELcs db = new YourPELcs())
            {
                EVENTO item = null;
                item = db.EVENTOes.Find(idEvento);


                if (item == null)
                {
                    ModelState.AddModelError("", String.Format("O item com id {0} não foi encontrado", idEvento));
                    return;
                }

                TryUpdateModel(item);
                if (ModelState.IsValid)
                {
                    db.SaveChanges();
                }
            }
        }
コード例 #6
0
ファイル: Videos.aspx.cs プロジェクト: Mustahai/yourPEL
        // The id parameter name should match the DataKeyNames value set on the control

        /*public void GridViewEditar_UpdateItem(int id)
         * {
         *  //Editar
         *  using (YourPELEntities db = new YourPELEntities())
         *  {
         *      ARTIGO item = null;
         *      item = db.ARTIGOes.Find(idArtigo);
         *
         *
         *      if (item == null)
         *      {
         *          ModelState.AddModelError("", String.Format("O item com id {0} não foi encontrado", idArtigo));
         *          return;
         *      }
         *
         *      TryUpdateModel(item);
         *      if (ModelState.IsValid)
         *      {
         *          db.SaveChanges();
         *      }
         *  }
         * }*/

        // The id parameter name should match the DataKeyNames value set on the control
        public void GridViewEditar_DeleteItem(int id)
        {
            //Apagar
            using (YourPELcs db = new YourPELcs())
            {
                ARTIGO item = null;
                item = db.ARTIGOes.Find(idArtigo);

                if (item != null)
                {
                    db.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DBConcurrencyException)
                    {
                        ModelState.AddModelError(
                            "", String.Format("O item com o id {0} não existe", idArtigo));
                    }
                }
            }
        }