Esempio 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);
             }
         }
     }
 }
Esempio n. 2
0
        public IActionResult Put(int id, PetUpdateDto pet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //authentication
            var userId = Int32.Parse(User.FindFirst("UserId").Value);

            try
            {
                var newPet = petManager.UpdatePet(id, userId, pet);
                return(Ok(newPet));
            }
            catch (CustomDbConflictException e)
            {
                return(BadRequest(e.Message));
            }
        }