public int Count() { using (MyPOSContext context = new MyPOSContext()) { return(context.Set <TEntity>().Count()); } }
public List <TEntity> ObterTodos() { using (MyPOSContext context = new MyPOSContext()) { return(context.Set <TEntity>().ToList()); } }
private void SaveButton_Click(object sender, EventArgs e) { CustomerInfo customerInfo = new CustomerInfo(); customerInfo.CustomerID = this.customerID; customerInfo.Name = CustomerNameTextBox.Text; customerInfo.Mobile = CustomerMobileTextBox.Text; customerInfo.Address = CustomerAddressTextBox.Text; if (IsValid()) { if (this.IsUpdate) { using (MyPOSContext db = new MyPOSContext()) { db.Entry(customerInfo).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Customer detail is updated succesfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearControls(); } } else { using (MyPOSContext db = new MyPOSContext()) { db.CustomerInfoes.Add(customerInfo); db.SaveChanges(); MessageBox.Show("Customer detail is saved succesfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearControls(); } } } }
public TEntity Obter(params object[] variaveis) { using (MyPOSContext context = new MyPOSContext()) { return(context.Set <TEntity>().Find(variaveis)); } }
public Usuario ObterPorId(int id) { using (MyPOSContext context = new MyPOSContext()) { return(context.Set <Usuario>().FirstOrDefault(p => p.Id_Usuario == id)); } }
public Usuario Login(string login, string senha) { using (MyPOSContext context = new MyPOSContext()) { return(context.Set <Usuario>().FirstOrDefault(p => p.Email == login && p.Senha == senha)); } }
public Usuario ObterPorLogin(string login) { using (MyPOSContext context = new MyPOSContext()) { return(context.Set <Usuario>().FirstOrDefault(p => p.Email == login)); } }
public Trabalho ObterPorId(int id) { using (MyPOSContext context = new MyPOSContext()) { return(context.Set <Trabalho>().FirstOrDefault(a => a.Id_Trabalho == id)); } }
public int ObterQuantidadeEntregue() { using (MyPOSContext context = new MyPOSContext()) { return(context.Set <Trabalho>().Where(t => t.Entregue).Count()); } }
public int ObterQuantidadeVencidos() { using (MyPOSContext context = new MyPOSContext()) { return(context.Set <Trabalho>().Where(t => t.DataParaEntrega < DateTime.Now && !t.Entregue).Count()); } }
public void SalvarModificacoes(List <TEntity> objEntity) { using (MyPOSContext context = new MyPOSContext()) { objEntity.ForEach(e => context.Entry(e).State = EntityState.Modified); context.SaveChanges(); } }
public void SalvarModificacoes(TEntity objEntity) { using (MyPOSContext context = new MyPOSContext()) { context.Entry(objEntity).State = EntityState.Modified; context.SaveChanges(); } }
public void RemoverItem(TEntity objEntity) { using (MyPOSContext context = new MyPOSContext()) { context.Entry(objEntity).State = EntityState.Deleted; context.SaveChanges(); } }
public void InserirNovo(TEntity objEntity) { using (MyPOSContext context = new MyPOSContext()) { context.Set <TEntity>().Add(objEntity); context.Entry(objEntity).State = EntityState.Added; context.SaveChanges(); } }
public void InsertOrUpdate(TEntity objEntity) { using (MyPOSContext context = new MyPOSContext()) { var obj = Obter(objEntity); if (obj is null) { context.Entry(objEntity).State = EntityState.Added; } else { context.Entry(obj).State = EntityState.Modified; } context.SaveChanges(); } }
public List <string> ObterVencendoEmTresDias() { List <Trabalho> trabalhos; var ret = new List <string>(); using (MyPOSContext context = new MyPOSContext()) { var dataFutura = DateTime.Now.AddDays(3); trabalhos = context.Set <Trabalho>() .Where(t => !t.Entregue && t.DataParaEntrega > DateTime.Now && t.DataParaEntrega < dataFutura).ToList(); } foreach (var trabalho in trabalhos) { ret.Add($"A atividade {trabalho.Titulo} vence em ({(int)(trabalho.DataParaEntrega - DateTime.Now).TotalDays}) dias"); } return(ret); }