Esempio n. 1
0
        public bool Delete(int id)
        {
            Nationality dbNationality;

            try
            {
                using (var context = new AppContext())
                {
                    dbNationality = GetById(id);
                    context.Nationality.Remove(dbNationality);
                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw ex;
            }
        }
Esempio n. 2
0
        public Nationality Add(Nationality nationality)
        {
            Nationality dbNationality;

            try
            {
                using (var context = new AppContext())
                {
                    dbNationality = context.Nationality.Add(nationality);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }

            return(dbNationality);
        }
Esempio n. 3
0
        public Nationality Update(Nationality nationality)
        {
            try
            {
                using (var context = new AppContext())
                {
                    if (nationality != null)
                    {
                        context.Nationality.Attach(nationality);
                        context.Entry(nationality).State = EntityState.Modified;
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }

            return(nationality);
        }