public void Create(Produto entity)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.Produto.Add(entity);
             ctx.SaveChanges();
             Console.WriteLine("Product inserted with id: {0}.", entity.id);
         }
         das.Commit();
     }
 }
        private int GetQuantityToSupply(int prodId)
        {
            int qtd;

            using (var das = new DataAccessScope(true))
            {
                IMapperProduto map = new MapperProduto();
                Produto        p   = map.Read(prodId);
                qtd = p.stock_max - p.stock_total;
                das.Commit();
            }
            return(qtd);
        }
        public void Update(Produto entity)
        {
            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    var prd_found = ctx.Produto.Find(entity.id);
                    if (prd_found != null)
                    {
                        var pu = (from a in ctx.Produto where a.id == entity.id select a).SingleOrDefault();

                        pu.cod         = entity.cod;
                        pu.tipo        = entity.tipo;
                        pu.descricao   = entity.descricao;
                        pu.stock_max   = entity.stock_max;
                        pu.stock_min   = entity.stock_min;
                        pu.stock_total = entity.stock_total;

                        try
                        {
                            ctx.SaveChanges();
                            Console.WriteLine("Product {0} updated.", entity.id);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.GetBaseException());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Error updating Product {0}", entity.id);
                    }
                }
                das.Commit();
            }
        }
 public void Delete(Produto entity)
 {
     Delete(entity.id);
 }