Ejemplo n.º 1
0
 public void AddAnswerPicture(AnswerPicture ansPicToAdd)
 {
     using (CAAContext context = new CAAContext())
     {
         context.AnswerPictures.Add(ansPicToAdd);
         context.SaveChanges();
     }
 }
        private async void BtnCreateConfirm_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Answer  add = new Answer();
            Picture pic = new Picture();

            //If there was an image selected with the create new
            if (file != null)
            {
                //converts image to byte and saves to database
                pic.Image = await imageConverter.ImageToByte(file);;
                picRepo.AddPicture(pic);
                //If there is text to image adds it to new answer
                if (txtCreateNewAnswer.Text != "")
                {
                    add.Text = txtCreateNewAnswer.Text;
                }

                answerRepo.AddAnswer(add);

                //joins answer to picture in joining table
                var answerPic = new AnswerPicture {
                    AnswerID = add.ID, PictureID = pic.ID
                };
                answerRepo.AddAnswerPicture(answerPic);
                add.AnswerPictures.Add(answerPic);

                answerRepo.UpdateAnswer(add);
                btnCreateNewAnswer.Flyout.Hide();
                PopulateAnswerList();
            }
            else
            {
                //if no image is added, inserts new answer with text
                add.Text = txtCreateNewAnswer.Text;
                answerRepo.AddAnswer(add);
                btnCreateNewAnswer.Flyout.Hide();
                PopulateAnswerList();
            }
        }