Ejemplo n.º 1
0
        public void addAppointmentDetails(AppointmentModel appointmentModel)
        {
            var registeredOwnerID = GetRegistredOwnerId(appointmentModel.Owner_FirstName, appointmentModel.Owner_LastName, appointmentModel.MobileNumber);
            var registeredPetID   = GetRegisterdPetID(appointmentModel.PetName, appointmentModel.BreedName, registeredOwnerID);

            using (VetDBEntities db = new VetDBEntities())
            {
                if (registeredOwnerID == 0)
                {
                    Communication_Address address = new Communication_Address();
                    address.AddressLane1 = appointmentModel.AddressLane1;
                    address.AdressLane2  = appointmentModel.AdressLane2;
                    address.City         = appointmentModel.City;

                    db.Communication_Address.Add(address);
                    db.SaveChanges();
                    int addressID = address.ID;

                    Owner owner = new Owner();
                    owner.FirstName    = appointmentModel.Owner_FirstName;
                    owner.LastName     = appointmentModel.Owner_LastName;
                    owner.MobileNumber = appointmentModel.MobileNumber;
                    owner.AddressID    = addressID;

                    db.Owners.Add(owner);
                    db.SaveChanges();
                    registeredOwnerID = owner.ID;
                }

                if (registeredPetID == 0)
                {
                    Pet_Details pet = new Pet_Details();
                    pet.PetName     = appointmentModel.PetName;
                    pet.BreedName   = appointmentModel.BreedName;
                    pet.DateOfBirth = appointmentModel.DateOfBirth;
                    pet.Pedegree    = appointmentModel.Pedegree;

                    db.Pet_Details.Add(pet);
                    db.SaveChanges();
                    registeredPetID = pet.ID;
                }


                Treatement_Details treatment = new Treatement_Details();
                treatment.TreatementDate = appointmentModel.TreatementDate;
                treatment.TreatementCost = appointmentModel.TreatementCost;
                treatment.Notes          = appointmentModel.Notes;
                treatment.PetID          = registeredPetID;

                db.Treatement_Details.Add(treatment);
                db.SaveChanges();

                Pet_Owner petOwner = new Pet_Owner();
                petOwner.OwnerID = registeredOwnerID;
                petOwner.PetID   = registeredPetID;

                db.Pet_Owner.Add(petOwner);
                db.SaveChanges();
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Pet_Details pet_Details = db.Pet_Details.Find(id);

            db.Pet_Details.Remove(pet_Details);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,Seller_Id,Pet_Category,Pet_Description,Pet_Color,Pet_Age,Pet_Weight,Pet_Gender,Pet_AvailableQuantity,Pet_Price,Pet_ImagePath,Pet_ImageName,Flag")] Pet_Details pet_Details)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pet_Details).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Seller_Id = new SelectList(db.Seller_Details, "Id", "Seller_Name", pet_Details.Seller_Id);
     return(View(pet_Details));
 }
        // GET: Pets/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Pet_Details pet_Details = db.Pet_Details.Find(id);

            if (pet_Details == null)
            {
                return(HttpNotFound());
            }
            return(View(pet_Details));
        }
        // GET: Pets/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Pet_Details pet_Details = db.Pet_Details.Find(id);

            if (pet_Details == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Seller_Id = new SelectList(db.Seller_Details, "Id", "Seller_Name", pet_Details.Seller_Id);
            return(View(pet_Details));
        }