Ejemplo n.º 1
0
        // D e l e t e
        public bool DeleteVetVisit(int id)
        {
            VetVisit vetVisitToDelete =
                context.VetVisits.FirstOrDefault(v => v.Id == id);

            if (vetVisitToDelete == null)
            {
                return(false);
            }
            context.VetVisits.Remove(vetVisitToDelete);
            context.SaveChanges();
            return(true);
        }
Ejemplo n.º 2
0
        // M e t h o d s  -  C R U D

        // C r e a t e
        public VetVisit Create(VetVisit vetVisit)
        {
            try
            {
                context.VetVisits.Add(vetVisit);
                context.SaveChanges();
                return(vetVisit);
            }
            catch (Exception e)
            {//something bad happened!
                return(null);
            }
        }
Ejemplo n.º 3
0
        // U p d a t e
        public VetVisit UpdateVetVisit(VetVisit vetVisit)
        {
            //1. Go find (read) this product from the database
            VetVisit vetVisitToUpdate = context.VetVisits                          //This will return an IQueryable
                                        .FirstOrDefault(v => v.Id == vetVisit.Id); //gets one product out of the database

            //2. Modify the database copy of the product
            if (vetVisitToUpdate != null)
            {
                vetVisitToUpdate.Date     = vetVisit.Date;
                vetVisitToUpdate.Vaccine  = vetVisit.Vaccine;
                vetVisitToUpdate.Weight   = vetVisit.Weight;
                vetVisitToUpdate.Comments = vetVisit.Comments;
                vetVisitToUpdate.Id       = vetVisit.Id;

                //3. Dear Database: Please update you copy of this product
                context.SaveChanges();
            }
            return(vetVisitToUpdate);
        }