public ActionResult Create(categoria Categoria)
 {
     plantadbEntities db = new plantadbEntities();
     db.categoria.Add(Categoria);
     db.SaveChanges();
     return Categorias();
 }
        public IHttpActionResult Getcategoria(int id)
        {
            categoria categoria = db.categoria.Find(id);

            if (categoria == null)
            {
                return(NotFound());
            }

            return(Ok(categoria));
        }
Example #3
0
 public ActionResult Edit([Bind(Include = "id_categoria,tipo_categoria")] categoria categoria)
 {
     if (ModelState.IsValid)
     {
         db.Entry(categoria).State = EntityState.Modified;
         db.SaveChanges();
         Request.Flash("success", "Categoria Editada Correctamente");
         return(RedirectToAction("Index"));
     }
     return(View(categoria));
 }
 public ActionResult Edit(categoria cat)
 {
     plantadbEntities db = new plantadbEntities();
     categoria cat2 = new categoria();
     cat2 = db.categoria.Find(cat.idcategoria);
     cat2.activa = cat.activa;
     cat2.desc = cat.desc;
     cat2.color = cat.color;
     db.SaveChanges();
     return Categorias();
 }
Example #5
0
        public ActionResult Create([Bind(Include = "id_categoria,tipo_categoria")] categoria categoria)
        {
            if (ModelState.IsValid)
            {
                db.categoria.Add(categoria);
                db.SaveChanges();
                Request.Flash("success", "Categoria Creada Correctamente");
                return(RedirectToAction("Index"));
            }

            return(View(categoria));
        }
Example #6
0
 private void Cat_V_btn_del_Click(object sender, EventArgs e)
 {
     using (ferreteriaEntities1 db = new ferreteriaEntities1())
     {
         String id = dtvCategoria.CurrentRow.Cells[0].Value.ToString();
         cate = db.categoria.Find(int.Parse(id));
         db.categoria.Remove(cate);
         db.SaveChanges();
     }
     MessageBox.Show("Eliminado con exito");
     CargarDatos();
 }
        public void Update(Guid IdCategoria, categoria categoriaNew)
        {
            categoria categoria = examregisterContext.categoria.Where(a => a.idcategoria == IdCategoria).FirstOrDefault();

            categoria.idcategoriapai = categoriaNew.idcategoriapai;
            categoria.nome           = categoriaNew.nome;
            categoria.nomecompleto   = categoriaNew.nomecompleto;
            categoria.inativo        = categoriaNew.inativo;
            categoria.idexterno      = categoriaNew.idexterno;

            examregisterContext.SaveChanges();
        }
Example #8
0
 public IHttpActionResult EliminarCategoria(categoria usr)
 {
     try
     {
         var resp = new _01_Dal.Dal.Metodos().DelCatergoria(usr);
         return(Ok(resp));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Example #9
0
 public ActionResult Update(categoria obj)
 {
     if (ModelState.IsValid)
     {
         new CategoriasManager().Modificar(obj);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("Create", obj));
     }
 }
Example #10
0
        public CategoriasControllerTest()
        {
            _mockSet     = new Mock <DbSet <categoria> >();
            _mockContext = new Mock <Context>();
            _categoria   = new categoria {
                Id = 1, Descricao = "Teste Categoria"
            };

            _mockContext.Setup(m => m.Categorias).Returns(_mockSet.Object);
            _mockContext.Setup(expression: m => m.Categorias.FindAsync(1))
            .ReturnsAsync(_categoria);
        }
Example #11
0
 public addCategory(Central2 central)
 {
     InitializeComponent();
     this.Text = "Agregar Categoria";
     this.setatribs();
     this.KeyPreview  = true;
     this.db          = new dbop();
     this.cat         = new categoria();
     this.central     = central;
     this.FormClosed += (sender, args) => { this.closed(); };
     this.stopBounds();
 }
Example #12
0
        public IHttpActionResult Postcategoria(categoria categoria)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.categoria.Add(categoria);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = categoria.id_categoria }, categoria));
        }
Example #13
0
        public bool find(Categoria objCategoria)
        {
            bool hayRegistros;

            //string find = "select*from categoria where idCategoria='" + objCategoria.IdCategoria + "'";
            try
            {
                categoria cat = db.categoria.Find(objCategoria.IdCategoria);
                if (cat != null)
                {
                    objCategoria.Nombre      = cat.nombre;
                    objCategoria.Descripcion = cat.descripcion;

                    objCategoria.Estado = 99;
                    hayRegistros        = true;
                }
                else
                {
                    objCategoria.Estado = 1;
                    hayRegistros        = false;
                }

                /*
                 * comando = new SqlCommand(find, objConexionDB.getCon());
                 * objConexionDB.getCon().Open();
                 * reader = comando.ExecuteReader();
                 * hayRegistros = reader.Read();
                 *
                 * if (hayRegistros)
                 * {
                 *  objCategoria.Nombre = reader[1].ToString();
                 *  objCategoria.Descripcion = reader[2].ToString();
                 *
                 *  objCategoria.Estado = 99;
                 * }
                 * else
                 * {
                 *  objCategoria.Estado = 1;
                 * }
                 */
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                objConexionDB.getCon().Close();
                objConexionDB.closeDB();
            }

            return(hayRegistros);
        }
Example #14
0
        public ActionResult Edit(categoria cat)
        {
            plantadbEntities db   = new plantadbEntities();
            categoria        cat2 = new categoria();

            cat2        = db.categoria.Find(cat.idcategoria);
            cat2.activa = cat.activa;
            cat2.desc   = cat.desc;
            cat2.color  = cat.color;
            db.SaveChanges();
            return(Categorias());
        }
 public categoria GuardarModificarCategoria(categoria oCategoria)
 {
     if (oCategoria.idCategoria == 0)
     {
         oCategoria = GuardarCategoria(oCategoria);
     }
     else
     {
         oCategoria = ModificarCategoria(oCategoria); //falta actualizar detalle
     }
     return(oCategoria);
 }
Example #16
0
 public IHttpActionResult ActualizaCasoStore(categoria usr)
 {
     try
     {
         var resp = new _01_Dal.Dal.Metodos().ActualizarCategoria(usr);
         return(Ok(resp));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Example #17
0
        public ActionResult Editar(long id)
        {
            // lista de categorias
            ViewBag.categorias = _categoriaservice.GetAllAtivas(id);
            categoria model = new categoria();

            if (id != 0)
            {
                model = _categoriaservice.GetById(id);
            }

            return(View(model));
        }
 public IHttpActionResult AgregarCategoria([FromBody] categoria ct)
 {
     if (ModelState.IsValid)
     {
         dbContext.categorias.Add(ct);
         dbContext.SaveChanges();
         return(Ok(ct));
     }
     else
     {
         return(BadRequest());
     }
 }
Example #19
0
        /*  public categoria selectedCategory
         * {
         *    get
         *    {
         *        return (categoria)this.tbcategoriaBindingSource.Current;
         *    }
         * }
         */
        private bool HasProducts(categoria ctg)
        {
            var getProducts = dataContextFactory.DataContext.produtos.Where(x => x.id_categoria == ctg.id_categoria);

            if (getProducts.Count() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #20
0
        private bool CategoriaPossuiProduto(categoria Categoria)
        {
            var produtos = DataContextFactory.DataContext.produto.Where(x => x.id_categoria == Categoria.id_categoria);

            if (produtos.Count() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public int Salvar(string nomeCategoria)
        {
            int idCategoria = 0;

            try
            {
                using (var bd = new granamizaEntities())
                {
                    //Tenta recuperar categoria através do nome:
                    categoria cat = (from c in bd.categoria
                                     where c.nome == nomeCategoria
                                     select c)
                                    .Where(u => u.usuario_id == Sessao.IdUsuario)
                                    .FirstOrDefault();

                    if (cat != null)
                    {
                        //Retorna o id para o usuario
                        idCategoria = cat.id;
                    }

                    // se não encontrou:
                    else
                    {
                        //cria uma nova
                        categoria nova_cat = new categoria
                        {
                            nome       = nomeCategoria,
                            is_gasto   = 0,
                            usuario_id = Sessao.IdUsuario
                        };

                        bd.categoria.Add(nova_cat);

                        bd.SaveChanges();

                        //Retorna o id ao usuário
                        idCategoria = nova_cat.id;
                    }
                }

                return(idCategoria);
            }

            //Se ocorrer erro ao conectar.
            catch (Exception)
            {
                _ = new FrmPopupErro();
                return(idCategoria);
            }
        }
Example #22
0
        public categoria ActualizarCategoria(categoria item)
        {
            var obj = db.categoria.Find(item.id_categoria);

            if (obj == null)
            {
                return(null);
            }
            obj.img             = item.img;
            obj.nombre          = item.nombre;
            db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(obj);
        }
 public IHttpActionResult Put(int id, Categoria_POCO produto)
 {       
     try
     {
         categoria cat = contexto.categoria.SingleOrDefault(gen => gen.cat_cod == id);
         cat.cat_nome = produto.nome;
         contexto.SaveChanges();
         return RedirectToRoute("DefaultApi", new { controller = "Categoria", id = id });
     }
     catch (Exception e)
     {
         return BadRequest();
     }
 }
Example #24
0
        private void Cat_V_btn_edit_Click(object sender, EventArgs e)
        {
            using (ferreteriaEntities1 db = new ferreteriaEntities1())
            {
                String id  = dtvCategoria.CurrentRow.Cells[0].Value.ToString();
                int    idC = int.Parse(id);
                cate = db.categoria.Where(VerificarID => VerificarID.id_categoria == idC).First();
                cate.nombre_categoria = txtcategoria.Text;

                db.Entry(cate).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            CargarDatos();
        }
Example #25
0
        // GET: categorias/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            categoria categoria = db.categorias.Find(id);

            if (categoria == null)
            {
                return(HttpNotFound());
            }
            return(View(categoria));
        }
Example #26
0
        public IHttpActionResult Deletecategoria(int id)
        {
            categoria categoria = db.categoria.Find(id);

            if (categoria == null)
            {
                return(NotFound());
            }

            db.categoria.Remove(categoria);
            db.SaveChanges();

            return(Ok(categoria));
        }
Example #27
0
        public void Cadcategorias()
        {
            //cadastrar receitas por defeito
            categoria de        = new categoria();
            var       despfixas = Enum.GetValues(typeof(categoriasfixas)).Cast <categoriasfixas>().ToList();
            Random    r         = new Random();

            foreach (var item in despfixas)
            {
                de.proCategorias = item.ToString();
                si.categoria.Add(de);
                si.SaveChanges();
            }
        }
        public static int Actualizar(categoria categoria)
        {
            SqlCommand sql = new SqlCommand("editar_categoria", conexion.ObtenerConexion());

            sql.CommandType = CommandType.StoredProcedure;

            sql.Parameters.AddWithValue("@id_categoria", categoria.id);
            sql.Parameters.Add("@nombre", SqlDbType.VarChar, 0).Value      = categoria.nombre;
            sql.Parameters.Add("@descripcion", SqlDbType.VarChar, 0).Value = categoria.descripcion;

            int resul = sql.ExecuteNonQuery();

            return(Convert.ToInt32(resul > 0));
        }
Example #29
0
        public ActionResult EditCategory(EditCategoryViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    model.CargarDatos(CargarDatosContext(), model.CategoryId);
                    TryUpdateModel(model);
                    PostMessage(MessageType.Error, i18n.ValidationStrings.DatosIncorrectos);
                    return(View(model));
                }

                using (TransactionScope transaction = new TransactionScope())
                {
                    var category = new categoria();

                    if (model.CategoryId.HasValue)
                    {
                        category = context.categoria.First(x => x.id == model.CategoryId);
                    }
                    else
                    {
                        context.categoria.Add(category);
                    }

                    category.nombre      = model.Nombre;
                    category.descripcion = model.Descripcion;
                    category.created_by  = Session.GetUsuarioId();
                    category.updated_by  = Session.GetUsuarioId();
                    category.created_at  = DateTime.Now;
                    category.updated_at  = DateTime.Now;
                    category.deleted_at  = null;

                    context.SaveChanges();

                    PostMessage(MessageType.Success, "Se registró la categoría correctamente.");
                    transaction.Complete();

                    return(RedirectToAction("ListCategory"));
                }
            }
            catch (Exception ex)
            {
                InvalidarContext();
                PostMessage(MessageType.Error, "Ha ocurrido un error, por favor intentelo más tarde");
                model.CargarDatos(CargarDatosContext(), model.CategoryId);
                TryUpdateModel(model);
                return(View(model));
            }
        }
Example #30
0
 public void Put(categoria categoria)
 {
     if (ModelState.IsValid)
     {
         myEntity.Entry(categoria).State = EntityState.Modified;
         try
         {
             myEntity.SaveChanges();
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #31
0
        public PCategorias()
        {
            InitializeComponent();

            //   repo = new CategoriasRepository();

            refreshGrid();
            lCarpeta.Tag = "Carpeta";
            lNombre.Tag  = "Nombre";
            hideForm();
            State  = AppMAnager.STATE_NULL;
            entity = null;

            RefreshComboTiposCateg();
        }
 public static CategoryModel GetCategoryModel(int id)
 {
     if (id > 0)
     {
         sale_pointEntities db          = new sale_pointEntities();
         categoria          categoryObj = db.categoria.FirstOrDefault(x => x.cat_id_categoria == id) ?? new categoria();
         return(new CategoryModel {
             categoryId = categoryObj.cat_id_categoria, categoryDescription = categoryObj.cat_ds_categoria
         });
     }
     else
     {
         return(new CategoryModel());
     }
 }
Example #33
0
        public Arma(categoria tArma, danno tDanno, int vel, int fat)
        {
            tipoArma = tArma;
            tipoDanno = tDanno;
            velocita = vel;
            fatica = fat;

            switch (tArma)
            {
                case categoria.manoSingola: lunghezza = 1; break;
                case categoria.manoDoppia: lunghezza = 2; break;
                case categoria.lunga: lunghezza = 3; break;
                case categoria.daLancio: lunghezza = 4; break;
                case categoria.daTiro: lunghezza = 5; break;
                case categoria.scudo: lunghezza = 0; break;
            }
        }
        public ActionResult Delete(int id)
        {
            plantadbEntities db = new plantadbEntities();
            categoria cat = new categoria();
            List<ficha> fichas = new List<ficha>();
            fichas.AddRange(db.ficha.ToList());

            cat = db.categoria.Find(id);
            for (var i = 0; i < db.ficha.Count(); i++)
            {
                if (fichas.ElementAt(i).categoria.Contains(cat)) 
                {
                    ficha fich = new ficha();
                    fich = db.ficha.Find(i);
                    fich.categoria.Remove(cat);
                }
            }

            db.categoria.Remove(cat);
            db.SaveChanges();
            return Categorias();
        }