public bool DeleteUser(Guid userId) { try { using (var db = new DB.DBEntities()) { var oldData = db.User.Where(c => c.Id == userId).FirstOrDefault(); if (oldData == null) { return(false); } var temp = new DB.User() { Address = oldData.Address, CreateBy = oldData.CreateBy, CreateDate = oldData.CreateDate, Enable = oldData.Enable, Id = oldData.Id, ModifiedDate = oldData.ModifiedDate.HasValue ? oldData.ModifiedDate.Value : new DateTime(), ModifiedBy = oldData.ModifiedBy, Password = oldData.Password, Phone = oldData.Phone, UserName = oldData.UserName }; temp.Enable = false; db.Entry(oldData).CurrentValues.SetValues(temp); db.SaveChanges(); return(true); } } catch { return(true); } }
public Pedido BuscarPorId(int id) { using (var db = new DB.DBEntities()) { return(GetPedido(id, db)); } }
public List <DB.User> GetUsers() { using (var db = new DB.DBEntities()) { return(db.User.Where(c => c.Enable).ToList()); } }
public List <Produto> Buscar() { using (var db = new DB.DBEntities()) { var produtos = db.Produtos .FindAll().OrderByDescending(x => x.Id).ToList(); return(produtos); } }
private object SetProdutoApagado(int id, bool apagado) { using (var db = new DB.DBEntities()) { var produto = db.Produtos.FindOne(x => x.Id == id); produto.Apagado = apagado; db.Produtos.Update(produto); return(null); } }
private object SetClienteApagado(int id, bool apagado) { using (var db = new DB.DBEntities()) { var cliente = db.Clientes.FindOne(x => x.Id == id); cliente.Apagado = apagado; db.Clientes.Update(cliente); return(null); } }
public object Imprimir(int id) { using (var db = new DB.DBEntities()) { var pedidoDB = GetPedido(id, db); return(new { DataPedido = pedidoDB.DataPedido.ToString("dd/MM/yyyy"), NomeCliente = pedidoDB.Cliente.Nome, EnderecoCliente = pedidoDB.Cliente.Endereco?.ToString(), Produtos = pedidoDB.Produtos.Select(x => new { x.Produto.Nome, x.Quantidade, x.ValorVendido, ValorTotal = x.Quantidade * x.ValorVendido }), ValorTotal = pedidoDB.Produtos.Sum(x => x.ValorVendido * x.Quantidade) }); } }
public object Salvar(DB.Produto pr) { using (var db = new DB.DBEntities()) { if (pr.Id > 0) { db.Produtos.Update(pr); } else { db.Produtos.Insert(pr); } return(null); } }
public object Salvar(DB.Cliente cl) { using (var db = new DB.DBEntities()) { if (cl.Id > 0) { db.Clientes.Update(cl); } else { db.Clientes.Insert(cl); } return(null); } }
public bool SaveUser(DB.User user) { try { using (var db = new DB.DBEntities()) { var isValidate = CheckUserInfo(user); if (!isValidate) { return(false); } if (user == null) { return(false); } if (user.Id == Guid.Empty) { user.Id = Guid.NewGuid(); user.CreateBy = user.UserName; user.CreateDate = DateTime.Now; user.ModifiedBy = user.UserName; user.ModifiedDate = DateTime.Now; user.Enable = true; } var oldData = db.User.Where(c => c.Id == user.Id).FirstOrDefault(); if (oldData == null) { db.User.Add(user); } else { user.CreateBy = oldData.CreateBy; user.CreateDate = oldData.CreateDate; user.ModifiedBy = oldData.ModifiedBy; user.ModifiedDate = DateTime.Now; user.Enable = oldData.Enable; db.Entry(oldData).CurrentValues.SetValues(user); } db.SaveChanges(); return(true); } } catch (Exception e) { return(false); } }
public int Salvar(DB.Pedido pd) { using (var db = new DB.DBEntities()) { pd.DataPedido = DateTime.Now; if (pd.Id > 0) { db.Pedidos.Update(pd); } else { db.Pedidos.Insert(pd); } return(pd.Id); } }
public IEnumerable <Pedido> Buscar() { using (var db = new DB.DBEntities()) { return(db.Pedidos .Include(x => x.Cliente) //.Include(x => x.Produtos[0].Produto) .FindAll()); //var pedidos = db.Pedidos // .Include(x => x.Cliente) // .FindAll().Select(x => new // { // x.Id, // x.DataPedido, // x.Cliente, // ValorTotal = x.Produtos == null ? 0 : x.Produtos.Sum(y => y.ValorVendido * y.Quantidade), // }).ToList(); //return pedidos; } }
public bool Apagar(int id) { using (var db = new DB.DBEntities()) return(db.Pedidos.Delete(x => x.Id == id) >= 1); }