Esempio n. 1
0
        public AtletaEntity getAtletaById(int atletaId)
        {
            AtletaEntity atleta = null;

            using (var db = new AtletiDbEntities())
            {
                atleta = db.Atleta.FirstOrDefault(x => x.AtletaId == atletaId).ToAtletaEntity();
            }

            return(atleta);
        }
Esempio n. 2
0
 public int Delete(AtletaEntity atleta)
 {
     if (atleta != null)
     {
         using (var db = new AtletiDbEntities())
         {
             db.Atleta.Remove(db.Atleta.First(x => x.AtletaId == atleta.AtletaId));
             db.SaveChanges();
         }
         return(0);
     }
     return(-1);
 }
Esempio n. 3
0
 public int Add(AtletaEntity atleta)
 {
     if (atleta != null)
     {
         using (var db = new AtletiDbEntities())
         {
             db.Atleta.Add(atleta.ToDbAtleta());
             db.SaveChanges();
         }
         return(0);
     }
     return(-1);
 }
Esempio n. 4
0
        public List <AtletaEntity> GetAll()
        {
            List <AtletaEntity> atletiList = new List <AtletaEntity>();
            List <Atleta>       atletiDb   = new List <Atleta>();

            using (var db = new AtletiDbEntities())
            {
                atletiDb = db.Atleta.ToList();
            }

            atletiDb.ForEach((item) => { atletiList.Add(item.ToAtletaEntity()); });

            return(atletiList);
        }
Esempio n. 5
0
        public int Update(AtletaEntity atleta)
        {
            int result = 0;

            if (atleta != null)
            {
                using (var db = new AtletiDbEntities())
                {
                    Atleta atletaDb = db.Atleta.FirstOrDefault(x => atleta.AtletaId == x.AtletaId);
                    if (atletaDb == null)
                    {
                        result = -1;
                    }
                    else
                    {
                        atletaDb = atleta.ToDbAtleta(atletaDb);
                        db.SaveChanges();
                    }
                }
            }
            return(result);
        }