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);
     }
 }
Exemple #2
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);
     }
 }
 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 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);
            }
        }
Exemple #5
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 string UpdateEmployee(Employee employee)
        {
            try
            {
                Employee c = (from e in db.Employees
                              where e.Id == employee.Id
                              select e).First();
                c.EmployeeName = employee.EmployeeName;
                c.Position     = employee.Position;
                c.Departament  = employee.Departament;
                c.Version      = employee.Version;
                db.SaveChanges();

                return("ok");
            }
            catch (Exception ex)
            {
                return("bad");
            }
        }
Exemple #8
0
        public HttpResponseMessage Post(FormDataCollection form)
        {
            var values = form.Get("values");

            var sales = new tb_sales_transactions();

            JsonConvert.PopulateObject(values, sales);
            sales.UserPosted = "kris";
            Validate(sales);
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }


            db.tb_sales_transactions.Add(sales);
            db.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.Created));
        }
Exemple #9
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);
     }
 }
Exemple #10
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);
     }
 }
 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);
     }
 }
Exemple #13
0
 public int DeletarDatas()
 {
     try
     {
         InstanciarBanco();
         var datas   = _banco.Datas;
         int retorno = 0;
         foreach (var item in datas)
         {
             _banco.Datas.Remove(item);
             retorno += _banco.SaveChanges();
         }
         return(retorno);
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
 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);
     }
 }
Exemple #15
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));
        }
Exemple #16
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);
     }
 }