Exemplo n.º 1
0
 public static double GetTotalInvestido()
 {
     using (var ctx = new ClienteContext())
     {
         return(ctx.Cliente.Sum(a => a.Valor));
     }
 }
Exemplo n.º 2
0
 public IEnumerable <Conta> BuscarPorCliente(Guid clienteID)
 {
     using (var context = new ClienteContext())
     {
         return(context.Contas.Where(x => x.ClienteID == clienteID).Select(x => x).ToList());
     }
 }
Exemplo n.º 3
0
        public static ClienteContext DataInMemory()
        {
            var options = new DbContextOptionsBuilder <ClienteContext>()
                          .EnableSensitiveDataLogging()
                          .UseInMemoryDatabase(Guid
                                               .NewGuid().ToString()).Options;

            var context = new ClienteContext(options);

            context.Clientes.AddRange(new List <ClienteModel>()
            {
                new ClienteModel {
                    Id = 1, Nome = "Erick Henrique de Oliveira", Cpf = "44243792801", Rg = "460743181", DataNascimento = new DateTime(1994, 03, 19)
                },
                new ClienteModel {
                    Id = 2, Nome = "Paulo Rodrigo de Oliveira", Cpf = "52406000079", Rg = "195756551", DataNascimento = new DateTime(1990, 11, 19)
                },
                new ClienteModel {
                    Id = 3, Nome = "Maria de Fatima Santos Oliveira", Cpf = "72711992098", Rg = "371240955", DataNascimento = new DateTime(1969, 07, 01)
                },
            });

            context.SaveChanges();

            return(context);
        }
Exemplo n.º 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ClienteContext clienteContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();

                //Populando dados fake nas tabelas
                DbInitializer.Initialize(clienteContext);
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
        public ActionResult RegistraCliente(Cliente c)
        {
            if (!ModelState.IsValid)
            {
                return(View("MenuAdministracionVenta"));
            }

            try
            {
                using (var db = new ClienteContext())
                {
                    var existe = db.Cliente.ToList().Exists(x => x.dni == c.dni);

                    if (!existe)
                    {                                                                               //verifica en la BD si el cliente esta registrado o no
                        db.Cliente.Add(c);
                        db.SaveChanges();
                        return(RedirectToAction("MenuAdministracionVenta", new { message = "Cliente Registrado Satisfactoriamente. Su ID es: 11" }));
                    }
                    else
                    {
                        return(RedirectToAction("MenuAdministracionVenta", new { message = "Cliente ya Registrado" }));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Error al registrar un Cliente -" + ex.Message);
                return(View());
            }
        }
Exemplo n.º 6
0
        private void CadastrarClienteClick(object sender, EventArgs e)
        {
            try
            {
                var cliente = new Cliente {
                    Nome = txtNome.Text, Email = txtEmail.Text, Telefone = txtTelefone.Text
                };

                if (cliente.Validate())
                {
                    var verificaCliente = ClienteContext.GetClientId(cliente.Nome);

                    if (verificaCliente > 0)
                    {
                        MessageBox.Show("Já existe um cliente cadastrado com este nome");
                        txtNome.Focus();
                    }
                    else
                    {
                        var result = ClienteContext.Gravar(cliente);
                        MessageBox.Show("Cliente Cadastrado com Sucesso");
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show("Os campos não foram preenchidos corretamente");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro reportado : " + ex.Message);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // The ServiceManifest.XML file defines one or more service type names.
                // Registering a service maps a service type name to a .NET type.
                // When Service Fabric creates an instance of this service type,
                // an instance of the class is created in this host process.

                ClienteContext.Initialize();
                ContaContext.Initialize();

                ServiceRuntime.RegisterServiceAsync("Sciensa.Desafio.API.ClienteType",
                                                    context => new ServiceCliente(context)).GetAwaiter().GetResult();

                ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(ServiceCliente).Name);

                // Prevents this host process from terminating so services keeps running.
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
Exemplo n.º 8
0
 public IEnumerable <Cliente> Listar()
 {
     using (var context = new ClienteContext())
     {
         return(context.Clientes.ToList());
     }
 }
Exemplo n.º 9
0
        public static List <Cliente> pesquisar(Cliente cli, bool Receber)
        {
            cli.Nome   = cli.Nome == null ? "" : cli.Nome;
            cli.Email  = cli.Email == null ? "" : cli.Email;
            cli.Cidade = cli.Cidade == null ? "" : cli.Cidade;
            string CPF = cli.CPF.ToString();

            CPF = CPF == null ? "" : CPF;
            using (var ctx = new ClienteContext())
            {
                if (Receber)
                {
                    if (CPF != "0")
                    {
                        return(ctx.Cliente.Where((t => t.Nome.Contains(cli.Nome) && t.Email.Contains(cli.Email) && t.Cidade.Contains(cli.Cidade) && t.ReceberNoticiasEmail == cli.ReceberNoticiasEmail && t.CPF.ToString().Contains(CPF))).ToList());
                    }
                    else
                    {
                        return(ctx.Cliente.Where((t => t.Nome.Contains(cli.Nome) && t.Email.Contains(cli.Email) && t.Cidade.Contains(cli.Cidade) && t.ReceberNoticiasEmail == cli.ReceberNoticiasEmail)).ToList());
                    }
                }
                else
                {
                    if (CPF != "0")
                    {
                        return(ctx.Cliente.Where((t => t.Nome.Contains(cli.Nome) && t.Email.Contains(cli.Email) && t.Cidade.Contains(cli.Cidade) && t.CPF.ToString().Contains(CPF))).ToList());
                    }
                    else
                    {
                        return(ctx.Cliente.Where((t => t.Nome.Contains(cli.Nome) && t.Email.Contains(cli.Email) && t.Cidade.Contains(cli.Cidade))).ToList());
                    }
                }
            }
        }
Exemplo n.º 10
0
 public static Cliente pesquisarPorID(int id)
 {
     using (var ctx = new ClienteContext())
     {
         return(ctx.Cliente.Find(id));
     }
 }
Exemplo n.º 11
0
 public async Task <List <Models.Cliente> > Obter()
 {
     using (var context = new ClienteContext())
     {
         return(await context.Clientes.Select(s => s).ToListAsync());
     }
 }
Exemplo n.º 12
0
 public async Task <Models.Cliente> Obter(Guid id)
 {
     using (var context = new ClienteContext())
     {
         return(await context.Clientes.FirstAsync(f => f.Id == id));
     }
 }
Exemplo n.º 13
0
        public static void Initialize(ClienteContext context)
        {
            context.Database.EnsureCreated();

            if (context.Clientes.Any())
            {
                return;
            }

            var clientes = new ClienteModel[]
            {
                new ClienteModel {
                    Nome = "Erick Henrique de Oliveira", Cpf = "44243792801", Rg = "460743181", DataNascimento = new DateTime(1994, 03, 19)
                },
                new ClienteModel {
                    Nome = "Paulo Rodrigo de Oliveira", Cpf = "52406000079", Rg = "195756551", DataNascimento = new DateTime(1990, 11, 19)
                },
                new ClienteModel {
                    Nome = "Maria de Fatima Santos Oliveira", Cpf = "72711992098", Rg = "371240955", DataNascimento = new DateTime(1969, 07, 01)
                },
            };

            foreach (ClienteModel cliente in clientes)
            {
                context.Clientes.Add(cliente);
            }

            context.SaveChanges();
        }
Exemplo n.º 14
0
 public BaseFormConfig()
 {
     ProdutoContext = new ProdutoContext(Conn);
     ClienteContext = new ClienteContext(Conn);
     VendasContext  = new VendasContext(Conn);
     InitializeComponent();
 }
Exemplo n.º 15
0
 public PartialViewResult MostrarClientes()
 {
     using (ClienteContext db = new ClienteContext())
     {
         return(PartialView("_Mostrar", db.Clientes.ToList()));
     }
 }
 // GET: Cliente
 public ActionResult Index()
 {
     using (ClienteContext clienteContext = new ClienteContext())
     {
         List <Cliente> clientes = clienteContext.clientes.ToList();
         return(View(clientes));
     }
 }
Exemplo n.º 17
0
 // GET: Cliente
 public ActionResult Index()
 {
     //libera o recurso quando terminar de usar
     using (ClienteContext clienteContext = new ClienteContext()) {
         List <Cliente> clientes = clienteContext.clientes.ToList();
         return(View(clientes));
     };
 }
Exemplo n.º 18
0
 public int Adicionar(Cliente cliente)
 {
     using (var context = new ClienteContext())
     {
         context.Clientes.Add(cliente);
         return(context.SaveChanges());
     }
 }
Exemplo n.º 19
0
 // GET: TipoCliente
 public ActionResult Index()
 {
     using (ClienteContext clienteContext = new ClienteContext())
     {
         List<Tipo> tiposCliente = clienteContext.Tipos.ToList();
         return View(tiposCliente);
     }
 }
 public ActionResult Detalhes(int id)
 {
     using (ClienteContext clienteContext = new ClienteContext())
     {
         Cliente cliente = clienteContext.clientes.Single(cli => cli.ClienteId == id);
         return(View(cliente));
     }
 }
 public ActionResult Detalhes(int id)
 {
     using (ClienteContext cc = new ClienteContext())
     {
         Cliente cliente = cc.clientes.Include("Tipo").SingleOrDefault(c => c.Id == id);
         return(View(cliente));
     }
 }
 //
 // GET: /Tipo/
 public ActionResult Index()
 {
     using (ClienteContext context = new ClienteContext())
     {
         List <TipoCliente> tipos = context.tipos.ToList();
         return(View(tipos));
     }
 }
Exemplo n.º 23
0
 public ActionResult Eliminar(int id)
 {
     using (ClienteContext db = new ClienteContext())
     {
         var obj = db.Clientes.Where(x => x.ID.Equals(id)).FirstOrDefault();
         return(View(obj));
     }
 }
Exemplo n.º 24
0
 public void AddCliente(ICliente cliente)
 {
     using (var db = new ClienteContext(ConnectionStrings))
     {
         db.Clientes.Add((Cliente)cliente);
         db.SaveChanges();
     }
 }
Exemplo n.º 25
0
 public static void cadastrar(Cliente cliente)
 {
     using (var ctx = new ClienteContext())
     {
         ctx.Cliente.Add(cliente);
         ctx.SaveChanges();
     }
 }
Exemplo n.º 26
0
 public static void deletar(int id)
 {
     using (var ctx = new ClienteContext())
     {
         ctx.Cliente.Remove(ctx.Cliente.Find(id));
         ctx.SaveChanges();
     }
 }
Exemplo n.º 27
0
        public static ClienteDAO getInstance()
        {
            if (instance == null)
            {
                instance = new ClienteDAO(ClienteContext.getInstance());
            }

            return(instance);
        }
Exemplo n.º 28
0
 public int Editar(Conta conta)
 {
     using (var context = new ClienteContext())
     {
         context.Contas.Attach(conta);
         context.Entry(conta).State = EntityState.Modified;
         return(context.SaveChanges());
     }
 }
Exemplo n.º 29
0
        // GET: Cliente
        public ActionResult Index(int TipoId)
        {
            using (ClienteContext clienteContext = new ClienteContext())
            {
                List <Cliente> clientes = clienteContext.Clientes.Where(cli => cli.TipoId == TipoId).ToList();

                return(View(clientes));
            }
        }
        //
        // GET: /Cliente/
        public ActionResult Index(int tipoId)
        {
            using (ClienteContext cc = new ClienteContext()) {
                List <Cliente> lista = new List <Cliente>();
                lista = cc.clientes.Where(c => c.TipoId == tipoId).ToList();

                return(View(lista));
            }
        }