Exemplo n.º 1
0
        public void Select_As_Favourite(object sender, EventArgs e)
        {
            var fav = sender as Button;

            var favSurvey = Surveys.FirstOrDefault(s => s.SurveyId == fav.Text);

            if (favSurvey.Image == "unselect.png")
            {
                favSurvey.Image       = "selected.png";
                favSurvey.IsFavourite = true;
            }
            else
            {
                favSurvey.Image       = "unselect.png";
                favSurvey.IsFavourite = false;
            }

            var isSurveyAdded = _db.GetFavourites().FirstOrDefault(x => x.SurveId == fav.Text);

            if (isSurveyAdded == null || string.IsNullOrEmpty(isSurveyAdded.SurveId))
            {
                _db.AddFav(fav.Text, favSurvey.IsFavourite, favSurvey.Image);
            }
            else
            {
                _db.UpdateFav(fav.Text, favSurvey.IsFavourite, favSurvey.Image);
            }

            Favourites();
            SurveyList.ItemsSource = Surveys;
        }
        /// <summary>
        /// Update the survey from the database with "Sent/Not sent" status.
        /// </summary>
        /// <param name="id">Id of the survey</param>
        /// <param name="wasSent">Indicate if the survey was sent to the API or not</param>
        public void UpdateSurveyStatus(int id, bool wasSent)
        {
            Survey surveyToUpdate = Surveys.FirstOrDefault(e => e.SurveyId == id);

            if (surveyToUpdate != null)
            {
                surveyToUpdate.WasSent = true;
                SaveChanges();
            }
        }