Exemplo n.º 1
0
        public void Delete(int ProdId)
        {
            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    var prd_found = ctx.Produto.Find(ProdId);

                    if (prd_found != null)
                    {
                        ctx.ProdVendidoPorFranqueado.RemoveRange(ctx.ProdVendidoPorFranqueado.Where(x => x.prod_id == prd_found.id));
                        ctx.HistoricoVendas.RemoveRange(ctx.HistoricoVendas.Where(x => x.prod_id == prd_found.id));
                        ctx.Entrega.RemoveRange(ctx.Entrega.Where(x => x.prod_id == prd_found.id));
                        ctx.Produto.Remove(prd_found);
                        ctx.SaveChanges();
                        Console.WriteLine("Product with ID {0} removed.", ProdId);
                    }
                    else
                    {
                        Console.WriteLine("Error removing Product {0}", ProdId);
                    }
                }
                das.Commit();
            }
        }
Exemplo n.º 2
0
        public void Execute()
        {
            Console.WriteLine("What percentage relative to maxStock should be considered as running out of stock? (0-100)");
            double percentagemRutura = Double.Parse(Console.ReadLine());

            Console.WriteLine("Which franchisee is making the order?");
            int fid = int.Parse(Console.ReadLine());

            List <Entrega> produtosEmRutura;


            using (var das = new DataAccessScope(true))
            {
                IMapperProdVendidoPorFranqueado map   = new MapperProdVendidoPorFranqueado();
                List <ProdVendidoPorFranqueado> lpvpf = map.GetOutOfStock(percentagemRutura, fid);
                produtosEmRutura = lpvpf.Select(pvpf => ToEntrega(pvpf)).ToList();
                das.Commit();
            }

            using (var das = new DataAccessScope(true))
            {
                IMapperEntrega map = new MapperEntrega();
                map.OrderOutOfStock(produtosEmRutura);
                das.Commit();
            }
        }
Exemplo n.º 3
0
        public void Update(Franqueado entity)
        {
            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    var franq_found = ctx.Franqueado.Find(entity.id);
                    if (franq_found != null)
                    {
                        var f = (from a in ctx.Franqueado where a.id == entity.id select a).SingleOrDefault();

                        f.id     = entity.id;
                        f.nif    = entity.nif;
                        f.morada = entity.morada;
                        f.nome   = entity.nome;

                        try
                        {
                            ctx.SaveChanges();
                            Console.WriteLine("Franchisee {0} updated.", entity.id);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.GetBaseException());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Error updating Franchisee {0}", entity.id);
                    }
                }
                das.Commit();
            }
        }
Exemplo n.º 4
0
 private void UpdateStock(List <ProdutoViewInStore> sale)
 {
     using (var das = new DataAccessScope(true))
     {
         IMapperProdVendidoPorFranqueado map = new MapperProdVendidoPorFranqueado();
         map.UpdateInBulk(franqId, sale);
         das.Commit();
     }
 }
 private void Order(List <Proposta> encs)
 {
     using (var das = new DataAccessScope(true))
     {
         IMapperProduto map = new MapperProduto();
         map.FulfillOrders(encs);
         das.Commit();
     }
 }
Exemplo n.º 6
0
 private void RemoveFranchiseeFromProdVendidoPorFranqueado(int franqId)
 {
     using (var das = new DataAccessScope(true))
     {
         IMapperProdVendidoPorFranqueado map = new MapperProdVendidoPorFranqueado();
         map.DeleteAllWithFranqId(franqId);
         das.Commit();
     }
 }
Exemplo n.º 7
0
 private void RemoveFranchiseeFromFranqueado(int franqId)
 {
     using (var das = new DataAccessScope(true))
     {
         IMapperFranqueado map = new MapperFranqueado();
         map.Delete(franqId);
         das.Commit();
     }
 }
Exemplo n.º 8
0
 private void RemoveFranchiseeFromEntrega(int franqId)
 {
     using (var das = new DataAccessScope(true))
     {
         IMapperEntrega map = new MapperEntrega();
         map.DeleteAllWithFranqId(franqId);
         das.Commit();
     }
 }
Exemplo n.º 9
0
 private void RemoveFromProduto(int prodId)
 {
     using (var das = new DataAccessScope(true))
     {
         IMapperProduto map = new MapperProduto();
         map.Delete(prodId);
         das.Commit();
     }
 }
Exemplo n.º 10
0
 private void RemoveFranchiseeFromHistoricoVendas(int franqId)
 {
     using (var das = new DataAccessScope(true))
     {
         IMapperHistoricoVendas map = new MapperHistoricoVendas();
         map.DeleteAllWithFranqId(franqId);
         das.Commit();
     }
 }
Exemplo n.º 11
0
 private void RemoveProductFromFornecedorProduto(int prodId)
 {
     using (var das = new DataAccessScope(true))
     {
         IMapperFornecedorProduto map = new MapperFornecedorProduto();
         map.DeleteAllWithProdId(prodId);
         das.Commit();
     }
 }
 public void UpdateInBulk(int franqId, List <ProdutoViewInStore> sale)
 {
     using (var das = new DataAccessScope(false))
     {
         foreach (ProdutoViewInStore p in sale)
         {
             UpdateDueToSale(franqId, p.ProdId, p.Quantidade);
         }
         das.Commit();
     }
 }
Exemplo n.º 13
0
        private void InsertProduto()
        {
            Produto p = PromptUserForProductInfo();

            using (var das = new DataAccessScope(true))
            {
                IMapperProduto prod = new MapperProduto();
                prod.Create(p);
                das.Commit();
            }
        }
Exemplo n.º 14
0
 public void DeleteAllWithProdId(int prodId)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.HistoricoVendas.RemoveRange(ctx.HistoricoVendas.Where(hv => hv.prod_id == prodId));
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
 public void DeleteAllWithProdId(int prodId)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.ProdVendidoPorFranqueado.RemoveRange(ctx.ProdVendidoPorFranqueado.Where(pvpf => pvpf.prod_id == prodId));
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
 public void DeleteAllWithProdId(int prodId)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.FornecedorProduto.RemoveRange(ctx.FornecedorProduto.Where(fp => fp.prod_id == prodId));
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
Exemplo n.º 17
0
        private void RemoveProduto()
        {
            Console.WriteLine("Insert id of Product to Remove");
            int key = (int)GetInput(typeof(int));

            using (var das = new DataAccessScope(true))
            {
                IMapperProduto prod = new MapperProduto();
                prod.Delete(key);
                das.Commit();
            }
        }
Exemplo n.º 18
0
 public void Create(Franqueado entity)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.Franqueado.Add(entity);
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
Exemplo n.º 19
0
        private void InsertFranqueado()
        {
            Franqueado f = PromptUserForFranchiseeInfo();

            using (var das = new DataAccessScope(true))
            {
                IMapperFranqueado franq = new MapperFranqueado();
                franq.Create(f);
                das.Commit();
                Console.WriteLine("Franchisee inserted with id: {0}.", f.id);
            }
        }
Exemplo n.º 20
0
        private void RemoveFranqueado()
        {
            Console.WriteLine("Insert id of franchisee");
            int key = (int)GetInput(typeof(int));


            using (var das = new DataAccessScope(true))
            {
                IMapperFranqueado f = new MapperFranqueado();
                f.Delete(key);
                das.Commit();
            }
        }
Exemplo n.º 21
0
 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();
     }
 }
Exemplo n.º 22
0
 public void Delete(HistoricoVendas entity)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.HistoricoVendas.Attach(entity);
             ctx.HistoricoVendas.Remove(entity);
             ctx.SaveChanges();
         }
         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 DeleteAllWithFranqId(int franqId)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             var pvpfToDelete = ctx.ProdVendidoPorFranqueado.Where(p => p.franq_id == franqId).ToList();
             foreach (var deletepvpf in pvpfToDelete)
             {
                 ctx.ProdVendidoPorFranqueado.Remove(deletepvpf);
             }
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
Exemplo n.º 25
0
 public void DeleteAllWithFranqId(int franqId)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             var histToDelete = ctx.HistoricoVendas.Where(h => h.franq_id == franqId).ToList();
             foreach (var deleteHist in histToDelete)
             {
                 ctx.HistoricoVendas.Remove(deleteHist);
             }
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
Exemplo n.º 26
0
        private void UpdateFranqueado()
        {
            Console.WriteLine("Insert id of franchisee to update");
            int key = (int)GetInput(typeof(int));

            Franqueado f = PromptUserForFranchiseeInfo();

            f.id = key;


            using (var das = new DataAccessScope(true))
            {
                IMapperFranqueado franq = new MapperFranqueado();
                franq.Update(f);
                das.Commit();
            }
        }
Exemplo n.º 27
0
        public void FulfillOrders(List <Proposta> encs)
        {
            List <int> pIds = encs.Select(e => e.ProdId).ToList();

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    var query = (from p in ctx.Produto where pIds.Contains(p.id) select p).ToList();
                    foreach (var q in query)
                    {
                        q.stock_total += encs.Where(e => e.ProdId == q.id).First().Qtd;
                    }
                    ctx.SaveChanges();
                }
                das.Commit();
            }
        }
Exemplo n.º 28
0
        private void UpdateProduto()
        {
            Console.WriteLine("Insert id of Product to Update");
            int key = (int)GetInput(typeof(int));


            Produto p = PromptUserForProductInfo();

            p.id = key;


            using (var das = new DataAccessScope(true))
            {
                IMapperProduto prod = new MapperProduto();
                prod.Update(p);
                das.Commit();
            }
        }
Exemplo n.º 29
0
        public void Execute()
        {
            ShowAllFranqueados();
            Console.WriteLine("Insert Id of the franchisee you wish to delete");
            int franqId;

            while (!int.TryParse(Console.ReadLine(), out franqId))
            {
                Console.WriteLine("Invalid number, please try again!");
            }
            using (var das = new DataAccessScope(true))
            {
                RemoveFranchiseeFromHistoricoVendas(franqId);
                RemoveFranchiseeFromProdVendidoPorFranqueado(franqId);
                RemoveFranchiseeFromEntrega(franqId);
                RemoveFranchiseeFromFranqueado(franqId);
                das.Commit();
            }
        }
Exemplo n.º 30
0
        public void Execute()
        {
            Console.WriteLine("Add a Prod");

            Produto p = PromptUserToBuildProduct();

            using (var das = new DataAccessScope(true))
            {
                IMapperProduto map = new MapperProduto();
                map.Create(p);
                das.Commit();
            }
            Console.WriteLine("Product created with id = {0}", p.id);

            ProdVendidoPorFranqueado pvpf = PromptUserToBuildProdVendidoPorFranqueado();

            using (var das = new DataAccessScope(true))
            {
                IMapperProdVendidoPorFranqueado map = new MapperProdVendidoPorFranqueado();
                map.Create(pvpf);
                das.Commit();
            }
        }