Ejemplo n.º 1
0
 private void BtnPetAction_Click(object sender, RoutedEventArgs e)
 {
     if (this.Title == "New Pet")
     {
         if (captureNewPet())
         {
             try
             {
                 int latestID = _petManager.CreatePet(_newPet);                    // added on 3/12/19 by Matt H.
                 _petManager.AddPetImageFilename(_newPet.imageFilename, latestID); // added on 3/12/19 by Matt H.
                 this.DialogResult = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Creating a new pet has failed, try again." + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
             }
         }
     }
     if (this.btnPetAction.Content.ToString() == "Save")
     {
         if (captureNewPet())
         {
             try
             {
                 _petManager.UpdatePet(_oldPet, _newPet);
                 _petManager.EditPetImageFilename(_oldPet.PetID, _oldPet.imageFilename, _newPet.imageFilename); // added on 3/14/19 by Matt H.
                 this.DialogResult = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void CanDeletePet()
        {
            int petID = 999991;

            Pet pet = new Pet()
            {
                PetID     = petID,
                PetName   = "PetName",
                Gender    = "Male",
                Species   = "Lion",
                PetTypeID = "Cat",
                GuestID   = 123456
            };

            _petManager.CreatePet(pet);


            _petManager.DeletePet(999991);

            _petManager.RetrieveAllPets();
        }
Ejemplo n.º 3
0
        public IActionResult CreatePet(PetRegisterDto pet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //authentication
            var userId = Int32.Parse(User.FindFirst("UserId").Value);

            pet.OwnerId = userId;

            try
            {
                var newPet = petManager.CreatePet(pet);
                return(Ok(newPet));
            }
            catch (CustomDbConflictException e)
            {
                return(BadRequest(e.Message));
            }
        }