Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var context = new VeterinaryContext();

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();



            for (int i = 1; i < 20; i++)
            {
                var Pet = new Pet()
                {
                    Type     = "Pitbull_" + i,
                    ParentId = i
                };

                context.Pets.Add(Pet);

                context.Persons.Add(new Person
                {
                    FirstName = "Moro_" + i,
                    LastName  = "Joro_" + i,
                });
            }

            context.SaveChanges();

            var persons = context.Persons
                          .Select(x => new
            {
                FullName = x.FirstName + ' ' + x.LastName,
                Pets     = String.Join(", ", x.Pets.Select(x => x.Type))
            })
                          .ToList();

            var firstPerson = context.Persons.FirstOrDefault();

            context.Persons.Remove(firstPerson);
            context.SaveChanges();

            //foreach (var person in persons)
            //{
            //    Console.WriteLine(person.FullName);
            //    Console.WriteLine(person.Pets);

            //}
        }
Exemplo n.º 2
0
        public JsonResult CreateOwner(Owner owner)
        {
            var status = true;

            if (owner.OwnerName != String.Empty & owner.OwnerLastName != String.Empty)
            {
                db.Owners.Add(owner);
                db.SaveChanges();
            }
            else
            {
                status = false;
            }

            return(new JsonResult {
                Data = new { status = status, ownerId = owner.OwnerId }
            });
        }
        public JsonResult CreateVaccine(Vaccine vaccine)
        {
            if (!db.Vaccines.ToList().Exists(v => v.PetId == vaccine.PetId & v.VaccineNumber == vaccine.VaccineNumber))
            {
                vaccine.Pet = db.Pets.Find(vaccine.PetId);
                db.Vaccines.Add(vaccine);
                db.SaveChanges();

                var specie = vaccine.Pet.PetSpecie == Species.Canina ? "Canina" : "Felina";

                return(new JsonResult {
                    Data = new { status = true, vaccineId = vaccine.VaccineId, owner = vaccine.Pet.Owner.OwnerFullName, pet = vaccine.Pet.PetName, specie = specie, date = vaccine.VaccineDate.ToString("yyyy-MM-dd") + "." + vaccine.VaccineDate.ToString("D") }
                });
            }

            return(new JsonResult {
                Data = new { status = false }
            });
        }
        // GET: LandingPage
        public ActionResult Index()
        {
            var owners = (from s in db.Surgeries.ToList()
                          where !s.SurgeryPatientFrequent & s.SurgeryDate < DateTime.Today
                          select s.Pet.Owner);

            db.Owners.RemoveRange(owners);
            db.SaveChanges();

            ViewBag.Vaccines  = db.Vaccines.Count(v => v.VaccineDate == DateTime.Today & v.VaccineNumber != 1);
            ViewBag.Surgeries = db.Surgeries.Count(s => s.SurgeryDate == DateTime.Today);
            ViewBag.Showers   = db.Showers.Count(sh => sh.ShowerDate == DateTime.Today);

            return(View());
        }
        public JsonResult CreatePet(Pet pet)
        {
            pet.Owner = db.Owners.Find(pet.OwnerId);
            db.Pets.Add(pet);
            db.SaveChanges();

            return(new JsonResult {
                Data = new { PetId = pet.PetId, OwnerName = pet.Owner.OwnerFullName }
            });
        }
Exemplo n.º 6
0
        public JsonResult CreateShower(Shower shower)
        {
            if (shower.ShowerDate != null)
            {
                Pet pet = db.Pets.Find(shower.PetId);

                if (pet != null)
                {
                    shower.PetName    = pet.PetName;
                    shower.Owner      = pet.Owner.OwnerFullName;
                    shower.OwnerPhone = pet.Owner.OwnerPhone;

                    if (pet.PetSpecie == Species.Canina)
                    {
                        shower.PetSpecie = "Canina";
                    }
                    else
                    {
                        shower.PetSpecie = "Felina";
                    }
                }

                db.Showers.Add(shower);
                db.SaveChanges();

                return(new JsonResult {
                    Data = new { status = true, showerId = shower.ShowerId, petId = shower.PetId, petname = shower.PetName, owner = shower.Owner, ownerPhone = shower.OwnerPhone, specie = shower.PetSpecie, date = shower.ShowerDate.ToString("yyyy-MM-dd"), dateTitle = shower.ShowerDate.ToString("D") }
                });
            }
            else
            {
                return(new JsonResult {
                    Data = new { status = false }
                });
            }
        }
Exemplo n.º 7
0
        public JsonResult CreateSurgeryType(SurgeryType surgeryType)
        {
            var exist = db.SurgeryTypes.ToList().Exists(st => st.SurgeryTypeName == surgeryType.SurgeryTypeName);

            if (exist)
            {
                return(new JsonResult {
                    Data = new { status = false }
                });
            }
            else
            {
                db.SurgeryTypes.Add(surgeryType);
                db.SaveChanges();

                return(new JsonResult {
                    Data = new { status = true, surgeryTypeId = surgeryType.SurgeryTypeId }
                });
            }
        }