Example #1
0
        public bool Update(Model.Mascota model)
        {
            bool success = false;

            if (model == null)
            {
                return(false);
            }

            try
            {
                using (var ctx = new PetZooContext())
                {
                    ctx.Mascota.Attach(model);
                    ctx.Entry(model).State = EntityState.Modified;
                    success = ctx.SaveChanges() > 0;
                }
            }
            catch (Exception)
            {
                //log
            }

            return(success);
        }
Example #2
0
        public Model.Mascota GetFullById(long id)
        {
            Model.Mascota model = new Model.Mascota();

            try
            {
                using (var ctx = new PetZooContext())
                {
                    model = ctx.Mascota.AsNoTracking()
                            .Include(m => m.Foto.Select(f => f.Path))
                            .Include(m => m.EstadoMascota)
                            .Include(m => m.Comportamiento)
                            .Include(m => m.ClaseMascota)
                            .Include(m => m.Raza)
                            .Include(m => m.Tamano)
                            .SingleOrDefault(m => m.IdMascota == id);
                }
            }
            catch (Exception)
            {
                //log
            }

            return(model);
        }
Example #3
0
        public Model.Mascota GetById(long id)
        {
            Model.Mascota model = new Model.Mascota();

            try
            {
                using (var ctx = new PetZooContext())
                {
                    model = ctx.Mascota.AsNoTracking()
                            .SingleOrDefault(m => m.IdMascota == id);
                }
            }
            catch (Exception)
            {
                //log
            }

            return(model);
        }
Example #4
0
        public Model.Mascota GetWithPhotosById(long id)
        {
            Model.Mascota model = new Model.Mascota();

            try
            {
                using (var ctx = new PetZooContext())
                {
                    model = ctx.Mascota.AsNoTracking()
                            .Include(m => m.Foto.Select(f => f.Path))
                            .SingleOrDefault(m => m.IdMascota == id);
                }
            }
            catch (Exception)
            {
                //log
            }

            return(model);
        }
Example #5
0
        public long Add(Model.Mascota model)
        {
            if (model == null)
            {
                return(0);
            }

            try
            {
                using (var ctx = new PetZooContext())
                {
                    ctx.Mascota.Add(model);
                    ctx.SaveChanges();
                }
            }
            catch (Exception)
            {
                //log
            }

            return(model.IdMascota);
        }