private void SetDateId(string s)
        {
            DiaryDate diaryDate = new DiaryDate();
            var       task      = Task.Run(async() =>
            {
                diaryDate = await repository.GetDateByString(s);
            });

            task.Wait();
            if (diaryDate != null)
            {
                dateId = diaryDate.DateId;
                // set date rating if in accepted range
                if (diaryDate.Rating >= 1 && diaryDate.Rating <= 5)
                {
                    ratingBar.Rating = (float)diaryDate.Rating;
                }
                else
                {
                    ratingBar.Rating = 0F;
                }
            }
            else
            {
                dateId           = 0;
                ratingBar.Rating = 0F;
            }
        }
Beispiel #2
0
        private async void saveButton_Click(object sender, EventArgs e)
        {
            // Check to see if DiaryDate exists for date of this entry. If not, create one
            //DiaryDate diaryDate = await repository.GetDateByString(date);
            //if (diaryDate == null)
            //{
            //    diaryDate.Date = date;
            //    await repository.AddDate(diaryDate);
            //}
            if (dateId == 0)
            {
                DiaryDate diaryDate = new DiaryDate();
                diaryDate.Date = date;
                await repository.AddDate(diaryDate);

                // reassign dateId
                diaryDate = await repository.GetDateByString(date);

                dateId = diaryDate.DateId;
            }
            // build full date
            DateTime fullDate = DateTime.ParseExact(date.PadLeft(10, Convert.ToChar("0")) + " " + hour + ":" + minute, "MM/dd/yyyy HH:mm", null);

            // Assign new entry details
            Entry entry = new Entry();

            entry.EntryDate   = fullDate;
            entry.EntryDateId = dateId;
            entry.Description = descriptionText.Text;
            entry.Quantity    = Convert.ToInt32(quantityText.Text);
            if (foodRadioButton.Checked)
            {
                entry.EntryType = 0;
            }
            else if (eventRadioButton.Checked)
            {
                entry.EntryType = 1;
            }

            // Insert new entry and finish activity
            await repository.AddEntry(entry);

            Toast.MakeText(this, "Entry added!", ToastLength.Short).Show();
            Finish();
        }