public void DarBaixa(Produto produto, Estoque estoque)
 {
     try
     {
         if (produto.GerenciarEstoque == GerenciarEstoque)
         {
             InstanciarDbContext();
             produto.Quantidade         -= estoque.Quantidade;
             _banco.Entry(produto).State = System.Data.Entity.EntityState.Modified;
             if (produto.Quantidade < 0)
             {
                 produto.Quantidade          = 0;
                 _banco.Entry(produto).State = System.Data.Entity.EntityState.Modified;
             }
             _banco.SaveChanges();
         }
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
 public int Salvar(Usuarios usuario)
 {
     try
     {
         int retorno = 0;
         if (_usuarioBo.VerificarSeJaExisteLoginSenha(usuario) == NaoExiste)
         {
             _banco.Entry(usuario).State = EntityState.Added;
             retorno = _banco.SaveChanges() == Sucesso ? Sucesso : Insucesso.ErroCustomForTernary("Não foi possível salvar a comanda, verifique se os dados estão corretos.");
         }
         else
         {
             throw new CustomException("Usuário já Existe");
         }
         return(retorno);
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
Пример #3
0
 public int Cadastrar(Caixa caixa)
 {
     try
     {
         if (this.GetQuantidade() > 0)
         {
             caixa.ID     = GetQuantidade();
             caixa.Valor += GetValor().Valor;
             InstanciarBanco();
             _banco.Entry(caixa).State = EntityState.Modified;
             return(_banco.SaveChanges() == Sucesso ? Sucesso : Insucesso);
         }
         else
         {
             InstanciarBanco();
             _banco.Entry(caixa).State = EntityState.Added;
             return(_banco.SaveChanges() == Sucesso ? Sucesso : Insucesso);
         }
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
Пример #4
0
        public async Task <ActionResult> Edit([Bind(Include = "id,bran_code,branch_name,bran_type_code,address1,address2,state,zip,assets")] app_branch app_branch)
        {
            if (ModelState.IsValid)
            {
                db.Entry(app_branch).State = EntityState.Modified;
                await db.SaveChangesAsync();

                ViewBag.alert = "saved";
                return(RedirectToAction("Index"));

                // return RedirectToAction("Index");
            }
            else
            {
                ViewBag.alert = "error";
            }

            var errors = ModelState.Values.SelectMany(v => v.Errors);

            ViewBag.bran_type_code = new SelectList(db.app_bran_type, "id", "name", app_branch.bran_type_code);
            return(View(app_branch));

            //if (ModelState.IsValid)
            //{
            //    db.Entry(app_branch).State = EntityState.Modified;
            //    await db.SaveChangesAsync();
            //    return RedirectToAction("Index");
            //}
            //ViewBag.bran_type_code = new SelectList(db.app_bran_type, "id", "name", app_branch.bran_type_code);
            //return View(app_branch);
        }
        public int Cadastrar()
        {
            try
            {
                int contador = 0;
                InstanciarBanco();
                if (GetQuantidade() != 2)
                {
                    foreach (TipoCadastro tipo in TipoDeCadastroList())
                    {
                        _banco.Entry(tipo).State = System.Data.Entity.EntityState.Added;
                        contador += _banco.SaveChanges();
                    }
                }

                return(contador);
            }
            catch (CustomException erro)
            {
                throw new CustomException(erro.Message);
            }
            catch (Exception erro)
            {
                throw new Exception(erro.Message);
            }
        }
Пример #6
0
        public ActionResult DelCustomer([Bind(Include = "id,home_type_code,age_cat_type_code,cus_type_code,title,firstname,lastname,middlename,dob,gender,occupation_code,img_url,sign_img_url,marital_status,child_num,cus_since,cus_doc_code,credit_limit,kin_type_code,created_by,modified_by,deleted_by,created_date,modified_date,deleted_date,rel_off_code,bran_code")]
                                        app_cus_main app_cus_main
                                        , app_cus_other_info app_cus_other_info
                                        , app_cus_contact app_cus_contact
                                        , app_kin_details app_kin_details
                                        )

        {
            if (ModelState.IsValid)
            //  return View(app_cus_main);
            {
                app_cus_main.modified_by        = _repository.GetLoginUser();
                app_cus_main.modified_date      = _repository.GetCurrentDateTime();
                app_cus_main.status             = "del";
                app_cus_main.app_cus_contact    = app_cus_contact;
                app_cus_main.app_kin_details    = app_kin_details;
                app_cus_main.app_cus_other_info = app_cus_other_info;

                app_cus_main.cus_code = _repository.GetCustomerCode(app_cus_main.id);
                db.app_cus_main.Add(app_cus_main);

                db.Entry(app_cus_main).State = EntityState.Modified;
                db.SaveChanges();
                ViewBag.alert = "saved";
                return(RedirectToAction("Index"));
            }
            ViewBag.contact_code      = new SelectList(db.app_cus_contact, "id", "email", app_cus_main.contact_code);
            ViewBag.age_cat_type_code = new SelectList(db.app_age_cate, "id", "name_of_cat", app_cus_main.age_cat_type_code);
            ViewBag.bran_code         = new SelectList(db.app_branch, "id", "branch_name", app_cus_main.bran_code);

            ViewBag.contact_code      = new SelectList(db.app_cus_contact, "id", "email", app_cus_main.contact_code);
            ViewBag.age_cat_type_code = new SelectList(db.app_age_cate, "id", "name_of_cat", app_cus_main.age_cat_type_code);
            ViewBag.bran_code         = new SelectList(db.app_branch, "id", "branch_name", app_cus_main.bran_code);
            //  ViewBag.contact_code = new SelectList(db.app_cus_contact, "id", "tele_number", app_cus_main.age_cat_type_code);
            ViewBag.cus_doc_code     = new SelectList(db.app_cus_doc, "id", "cus_doc_name", app_cus_main.age_cat_type_code);
            ViewBag.cus_other_code   = new SelectList(db.app_cus_other_info, "id", "security_group", app_cus_main.age_cat_type_code);
            ViewBag.cus_type_code    = new SelectList(db.app_cus_type, "id", "type_name", app_cus_main.cus_type_code);
            ViewBag.gender           = new SelectList(db.app_gender, "id", "sex", app_cus_main.gender);
            ViewBag.home_type_code   = new SelectList(db.app_home_type, "id", "type_name", app_cus_main.home_type_code);
            ViewBag.kin_details_code = new SelectList(db.app_kin_details, "id", "full_name", app_cus_main.kin_details_code);
            ViewBag.occupation_code  = new SelectList(db.app_occupation, "id", "name", app_cus_main.occupation_code);
            ViewBag.rel_off_code     = new SelectList(db.app_rel_office, "id", "full_name", app_cus_main.rel_off_code);
            ViewBag.countries        = new SelectList(db.app_countries, "id", "name", app_cus_main.app_cus_contact.contact_code);
            //ViewBag.kin_type = new SelectList(db.app_kin_type, "id", "kin_type_name", app_cus_main.kin_details_code);

            return(View(app_cus_main));
        }
Пример #7
0
 public int Cadastrar(Venda venda)
 {
     try
     {
         InstanciarBanco();
         _banco.Entry(venda).State = EntityState.Added;
         return(_banco.SaveChanges() == Sucesso ? Sucesso : Insucesso);
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
 public int Salvar(MovimentacaoCaixa movimentacaoCaixa)
 {
     try
     {
         InstanciarBanco();
         _banco.Entry(movimentacaoCaixa).State = EntityState.Added;
         return(_banco.SaveChanges());
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
        public async Task <ActionResult> Edit([Bind(Include = "id,country_code,contact_code,tele_number,fax,email,address1,address2,city,state,zip,brief_location,gps_cordinates")] app_cus_contact app_cus_contact)
        {
            if (ModelState.IsValid)
            {
                db.Entry(app_cus_contact).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(app_cus_contact));
        }
        public async Task <ActionResult> Edit([Bind(Include = "ID,DatePosted,RecNo,US_Dollars,BritishPounds,Yen,CFA,Euro,CanDollar,Rate,TotalAmount,UserPosted,UserModified")] tb_sales_transactions tb_sales_transactions)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tb_sales_transactions).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(tb_sales_transactions));
        }
Пример #11
0
 public int Cadastrar(Categoria categoria)
 {
     try
     {
         int retorno = Insucesso;
         if (new CategoriaBO().VerificarSeJaExisteNoSalvamento(categoria: categoria) == NaoExiste)
         {
             _banco.Entry(categoria).State = EntityState.Added;
             retorno = _banco.SaveChanges() == Sucesso ? Sucesso : Insucesso;
         }
         return(retorno);
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
Пример #12
0
 public int Salvar(Comanda comanda)
 {
     try
     {
         int retorno = Insucesso;
         if (_comandaBO.VerificaSeExisteComanda(comanda) == NaoExiste)
         {
             _banco.Entry(comanda).State = EntityState.Added;
             retorno = _banco.SaveChanges() == Sucesso ? Sucesso : Insucesso.ErroCustomForTernary("Não foi possível cadastrar a comanda, verifique os dados.");
         }
         return(retorno);
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
 public int Salvar(Cliente cliente)
 {
     try
     {
         InstanciarClienteBO();
         int retorno = Insucesso;
         if (_clienteBO.VerificarSeJaExisteNoSalvamento(cliente) == NaoExiste)
         {
             _banco.Entry(cliente).State = EntityState.Added;
             retorno = _banco.SaveChanges() == Sucesso ? Sucesso : Insucesso.ErroCustomForTernary("Não foi possível salvar o cliente");
         }
         return(retorno);
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
Пример #14
0
 public int Cadastrar(Fiado fiado)
 {
     try
     {
         int retorno = 0;
         InstanciarBanco();
         _fiado = _banco.Fiado.FirstOrDefault(c => c.IDCliente == fiado.IDCliente);
         if (_fiado != null)
         {
             fiado.ID = _fiado.ID;
             InstanciarBanco();
             fiado.Valor += _fiado.Valor;
             if (fiado.Valor <= 0)
             {
                 _banco.Entry(fiado).State = EntityState.Deleted;
                 retorno = _banco.SaveChanges();
             }
             else
             {
                 _banco.Entry(fiado).State = EntityState.Modified;
                 retorno = _banco.SaveChanges();
             }
         }
         else
         {
             _banco.Entry(fiado).State = EntityState.Added;
             retorno = _banco.SaveChanges();
         }
         return(retorno);
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
Пример #15
0
 public int Salvar(Produto produto)
 {
     try
     {
         InstanciarDbContext();
         InstanciarProdutoBO();
         int retorno = 0;
         if (_produtoBO.VerificaSeExisteProduto(produto) == NaoExiste)
         {
             _banco.Entry(produto).State = EntityState.Added;
             retorno = _banco.SaveChanges() == Sucesso ? Sucesso : Insucesso.ErroCustomForTernary("Não foi possível salvar, verifiques os dados");
         }
         return(retorno);
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
Пример #16
0
        public async Task <StudentDetails> UpdateAsync(int id, StudentDetails entity)
        {
            var res = await ctx.StudentDetails.FindAsync(id);

            if (id != entity.StudentId)
            {
                throw new Exception("Id does not match");
            }
            if (res == null)
            {
                throw new Exception("record not found");
            }

            ctx.Entry <StudentDetails>(entity).State = EntityState.Modified;
            await ctx.SaveChangesAsync();

            return(entity);
        }
 public bool Salvar(Sangria sangria)
 {
     try
     {
         using (Banco = new _DbContext())
         {
             Banco.Entry <Sangria>(sangria).State = EntityState.Added;
             return(SaveChanges() > 0);
         }
     }
     catch (CustomException error)
     {
         throw new CustomException(error.Message);
     }
     catch (Exception error)
     {
         throw new Exception(error.Message);
     }
 }
Пример #18
0
        public async Task <ActionResult> Edit([Bind(Include = "id,cus_type_code,bran_code,rel_off_code,title,firstname,lastname,middlename,dob,age_cat_type_code,gender,occupation_code,img_url,sign_img_url,marital_status,child_num,home_type_code,cus_since,cus_other_code,kin_details_code,contact_code,cus_doc_code,credit_limit,created_by,modified_by,deleted_by,created_date,modified_date,deleted_date")] app_cus_main app_cus_main)
        {
            if (ModelState.IsValid)
            {
                db.Entry(app_cus_main).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.age_cat_type_code = new SelectList(db.app_age_cate, "id", "age_code", app_cus_main.age_cat_type_code);
            ViewBag.bran_code         = new SelectList(db.app_branch, "id", "branch_name", app_cus_main.bran_code);
            ViewBag.contact_code      = new SelectList(db.app_cus_contact, "id", "tele_number", app_cus_main.contact_code);
            ViewBag.cus_doc_code      = new SelectList(db.app_cus_doc, "id", "cus_doc_name", app_cus_main.cus_doc_code);
            ViewBag.cus_other_code    = new SelectList(db.app_cus_other_info, "id", "cus_other_code", app_cus_main.cus_other_code);
            ViewBag.cus_type_code     = new SelectList(db.app_cus_type, "id", "cus_type_code", app_cus_main.cus_type_code);
            ViewBag.kin_details_code  = new SelectList(db.app_kin_details, "id", "kin_details_code", app_cus_main.kin_details_code);
            ViewBag.occupation_code   = new SelectList(db.app_occupation, "id", "occ_code", app_cus_main.occupation_code);
            ViewBag.rel_off_code      = new SelectList(db.app_rel_office, "id", "rel_code", app_cus_main.rel_off_code);
            return(View(app_cus_main));
        }
Пример #19
0
 public int InsertDatas(Datas datas)
 {
     try
     {
         InstanciarKeyGenBO();
         int retorno = 0;
         if (_keyGenBo.VerificaSeExisteDatas(datas) == null)
         {
             InstanciarBanco();
             _banco.Entry(datas).State = EntityState.Added;
             retorno = _banco.SaveChanges();
         }
         return(retorno);
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
Пример #20
0
 public int Cadastrar()
 {
     try
     {
         int contador = 0;
         if (VerificarQuantidade() < 3)
         {
             foreach (TipoPagamento tipo in TipoPagamentoList())
             {
                 _banco.Entry(tipo).State = EntityState.Added;
                 contador += _banco.SaveChanges();
             }
         }
         return(contador == 3 ? contador : 1);
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
 public int DeletaItensDaComandaPorCodigo(string codigo)
 {
     try
     {
         InstanciaBanco();
         int     retorno    = 0;
         Comanda comanda    = _banco.Comanda.FirstOrDefault(c => c.Codigo == codigo);
         var     listaVenda = _banco.VendaComComandaAtiva.Where(c => c.IDComanda == comanda.ID);
         foreach (var venda in listaVenda)
         {
             _banco.Entry(venda).State = EntityState.Deleted;
             retorno = _banco.SaveChanges();
         }
         return(retorno);
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }