public bool UpdateStudenti(int id_c, string name, string prenume, string email, string tel, string grad, int camera, string functie, int code)
        {
            if (code == 0)
                return false;

            using (var context = new ServiciiATMContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var serv = new Studenti
                        {
                            ID_C = id_c,
                            Nume = name,
                            Prenume = prenume,
                            Email = email,
                            Nr_tel = tel,
                            Grad_militar = grad,
                            Camera = camera,
                            Functie = functie

                        };
                        context.Studentis.Add(serv);
                        context.Entry(serv).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                        transaction.Commit();
                        return true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        return false;
                    }
                }
            }
        }
        public bool UpdateInvoireApel(int id_s, DateTime data, TimeSpan ora_plecare, TimeSpan ora_sosire, int code)
        {
            if (code == 0)
                return false;

            using (var context = new ServiciiATMContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var serv = new Invoire_apel
                        {
                            ID_S = id_s,
                            Data = data,
                            Ora_plecare = ora_plecare,
                            Ora_sosire = ora_sosire

                        };
                        context.Invoire_apel.Add(serv);
                        context.Entry(serv).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                        transaction.Commit();
                        return true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        return false;
                    }
                }
            }
        }
        public bool UpdateListaServicii(string nume, int nr, string an, int code)
        {
            if (code == 0)
                return false;

            using (var context = new ServiciiATMContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var serv = new Lista_servicii
                        {
                            Nume_serviciu = nume,
                            Nr_componenta = nr,
                            An_studiu = an,

                        };
                        context.Lista_servicii.Add(serv);
                        context.Entry(serv).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                        transaction.Commit();
                        return true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        return false;
                    }
                }
            }
        }
        public void DeleteComandanti(string nume, string prenume)
        {
            using (var context = new ServiciiATMContext())
            {
                var cdt = context.Comandantis.Where(n => n.Nume == nume && n.Prenume == prenume).ToList<Comandanti>().FirstOrDefault();
                if (cdt != null)
                {
                    context.Comandantis.Attach(cdt);
                    context.Comandantis.Remove(cdt);
                    context.Entry(cdt).State = System.Data.Entity.EntityState.Deleted;
                    context.SaveChangesAsync();
                }

            }
        }
        public void DeleteInvApel(DateTime dt)
        {
            using (var context = new ServiciiATMContext())
            {
                var std = context.Apel_seara.Where(n => n.Data == dt).ToList<Apel_seara>().FirstOrDefault();
                if (std != null)
                {
                    context.Apel_seara.Attach(std);
                    context.Apel_seara.Remove(std);
                    context.Entry(std).State = System.Data.Entity.EntityState.Deleted;
                    context.SaveChanges();
                }

            }
        }
        public bool InsertListaServicii(string nume, int nr_comp, string an, int code)
        {
            if (code == 0)
                return false;
            using (var context = new ServiciiATMContext())
            {
                var lista = new Lista_servicii
                {
                    Nume_serviciu = nume,
                    Nr_componenta = nr_comp,
                    An_studiu = an,
                };
                context.Lista_servicii.Add(lista);
                context.Entry(lista).State = System.Data.Entity.EntityState.Added;
                context.SaveChanges();

                return true;
            }

        }
        //Merge
        public void DeleteServicii(DateTime time)
        {
            using (var context = new ServiciiATMContext())
            {
                var serv = context.Serviciis.Where(n => n.Data == time && n.Data < DateTime.Now).ToList<Servicii>().FirstOrDefault();
                if (serv != null)
                {
                    context.Serviciis.Attach(serv);
                    context.Serviciis.Remove(serv);
                    context.Entry(serv).State = System.Data.Entity.EntityState.Deleted;
                    context.SaveChanges();
                }

            }
        }
        public void DeleteListaServicii(string name)
        {
            using (var context = new ServiciiATMContext())
            {
                var std = context.Lista_servicii.Where(n => n.Nume_serviciu == name).ToList<Lista_servicii>().FirstOrDefault();
                if (std != null)
                {
                    context.Lista_servicii.Attach(std);
                    context.Lista_servicii.Remove(std);
                    context.Entry(std).State = System.Data.Entity.EntityState.Deleted;
                    context.SaveChanges();
                }

            }
        }
 public void DeleteCompanii(string an)
 {
     using (var context = new ServiciiATMContext())
     {
         var std = context.Companiis.Where(n => n.An_studii == an).ToList<Companii>().FirstOrDefault();
         if (std != null)
         {
             context.Companiis.Attach(std);
             context.Companiis.Remove(std);
             context.Entry(std).State = System.Data.Entity.EntityState.Deleted;
             context.SaveChanges();
         }
     }
 }
        public bool InsertComandanti(string name, string lastname, string tel, string mail, string adr, string gm, int code)
        {
            if (code == 0)
                return false;
            using (var context = new ServiciiATMContext())
            {
                var com = new Comandanti
                {
                    Nume = name,
                    Prenume = lastname,
                    Nr_tel = tel,
                    Email = mail,
                    Adresa = adr,
                    Grad_militar = gm

                };
                context.Comandantis.Add(com);
                context.Entry(com).State = System.Data.Entity.EntityState.Added;
                context.SaveChanges();

                return true;
            }

        }
        public bool InsertCompanii(int id_com, string an_studiu, int code)
        {
            if (code == 0)
                return false;
            using (var context = new ServiciiATMContext())
            {
                var com = new Companii
                {
                    ID_com = id_com,
                    An_studii = an_studiu,
                };
                context.Companiis.Add(com);
                context.Entry(com).State = System.Data.Entity.EntityState.Added;
                context.SaveChanges();

                return true;
            }

        }
        public bool InsertApelSeara(int id_c, int efc, int efp, int efa, DateTime data, int code)
        {
            if (code == 0)
                return false;
            using (var context = new ServiciiATMContext())
            {
                var apel = new Apel_seara
                {
                    ID_C = id_c,
                    Efectiv_control = efc,
                    Efectiv_prezenti = efp,
                    Efectiv_absenti = efa,
                    Data = data,

                };
                context.Apel_seara.Add(apel);
                context.Entry(apel).State = System.Data.Entity.EntityState.Added;
                context.SaveChanges();

                return true;
            }

        }
        public bool InsertServicii(int id_l, int id_s, DateTime data, bool check, int code)
        {
            if (code == 0)
                return false;
            using (var context = new ServiciiATMContext())
            {
                var serv = new Servicii
                {
                    ID_ls = id_l,
                    ID_S = id_s,
                    Data = data,
                    Check = check
                };
                context.Serviciis.Add(serv);
                context.Entry(serv).State = System.Data.Entity.EntityState.Added;
                context.SaveChanges();

                return true;
            }
        }
        public bool InsertStudenti(int id_c, string nume, string prenume, string mail, string tel, string grad, int camera, string functie, int code)
        {
            if (code == 0)
                return false;
            using (var context = new ServiciiATMContext())
            {
                var student = new Studenti
                {
                    ID_C = id_c,
                    Nume = nume,
                    Prenume = prenume,
                    Email = mail,
                    Nr_tel = tel,
                    Grad_militar = grad,
                    Camera = camera,
                    Functie = functie,

                };
                context.Studentis.Add(student);
                context.Entry(student).State = System.Data.Entity.EntityState.Added;
                context.SaveChanges();

                return true;
            }

        }
        public bool UpdateApelSeara(int id_c, int efc, int efp, int efa, DateTime data, int code)
        {
            if (code == 0)
                return false;

            using (var context = new ServiciiATMContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var apel = new Apel_seara
                        {
                            ID_C = id_c
                        };

                        context.Apel_seara.Attach(apel);
                        context.Entry(apel).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                        transaction.Commit();
                        return true;

                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        return false;
                    }
                }
            }

        }
        public void DeleteStudent(string name, string lastname)
        {
            using (var context = new ServiciiATMContext())
            {
                var std = context.Studentis.Where(n => n.Nume == name && n.Prenume == lastname).ToList<Studenti>().FirstOrDefault();
                if (std != null)
                {
                    context.Studentis.Attach(std);
                    context.Studentis.Remove(std);
                    context.Entry(std).State = System.Data.Entity.EntityState.Deleted;
                    context.SaveChanges();
                }

            }
        }
        public bool UpdServicii(int id_l, int id_s, DateTime data, bool check, int code)
        {
            if (code == 0)
                return false;

            using (var context = new ServiciiATMContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var serv = new Servicii
                        {
                            ID_ls = id_l,
                            ID_S = id_s,

                        };
                        context.Serviciis.Add(serv);
                        context.Entry(serv).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                        transaction.Commit();
                        return true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        return false;
                    }
                }
            }
        }
        public bool InsertInvoireSeara(int id_s, DateTime data, TimeSpan ora_plecare, TimeSpan ora_sosire, int code)
        {
            if (code == 0)
                return false;
            using (var context = new ServiciiATMContext())
            {
                var invoire = new Invoire_apel
                {
                    ID_S = id_s,
                    Ora_plecare = ora_plecare,
                    Ora_sosire = ora_sosire,
                    Data = data,

                };
                context.Invoire_apel.Add(invoire);
                context.Entry(invoire).State = System.Data.Entity.EntityState.Added;
                context.SaveChanges();

                return true;
            }

        }