示例#1
0
        public IList <Countdown> GetCountdowns()
        {
            using (var database = new CountdownContext())
            {
                var countdowns = database.Countdowns.ToList();

                return(countdowns);
            }
        }
示例#2
0
        public App()
        {
            AppCenter.Start("{Your App Secret}", typeof(Analytics), typeof(Crashes));

            InitializeComponent();

            using (var database = new CountdownContext())
            {
                database.Database.Migrate();
            }
        }
示例#3
0
        public async Task <bool> UnpinCountdown(int countdownId)
        {
            using (var database = new CountdownContext())
            {
                var countdown = database.Countdowns.Single(x => x.Id == countdownId);

                var success = await TileManager.UnpinCountdown(countdown);

                if (!success)
                {
                    return(false);
                }

                countdown.PinnedToStart = false;

                await database.SaveChangesAsync();

                return(true);
            }
        }
示例#4
0
        public async Task DeleteCountdown(int countdownId)
        {
            using (var database = new CountdownContext())
            {
                var countdown = database.Countdowns.Single(x => x.Id == countdownId);

                if (countdown.PinnedToStart)
                {
                    await TileManager.UnpinCountdown(countdown);
                }

                if (countdown.HasImage)
                {
                    await countdown.DeleteImageFile();
                }

                database.Countdowns.Remove(countdown);

                await database.SaveChangesAsync();
            }
        }
示例#5
0
        public async Task <Countdown> SaveCountdown(int countdownId, string name, DateTime dateTime, bool isRecurrent, byte[] imageData,
                                                    bool finishedNotification, bool pinnedToStart)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = "Countdown";
            }

            using (var database = new CountdownContext())
            {
                var countdown = database.Countdowns.SingleOrDefault(x => x.Id == countdownId);
                if (countdown == null)
                {
                    countdown = new Countdown
                    {
                        Created = DateTime.Now,
                        Guid    = Guid.NewGuid().ToString()
                    };

                    database.Countdowns.Add(countdown);
                }
                else
                {
                    if (imageData == null && countdown.Name == name &&
                        countdown.Date == dateTime && countdown.IsRecurrent == isRecurrent &&
                        countdown.FinishedNotification == finishedNotification && countdown.PinnedToStart == pinnedToStart)
                    {
                        return(countdown);
                    }
                }

                countdown.Name                 = name;
                countdown.Date                 = dateTime;
                countdown.IsRecurrent          = isRecurrent;
                countdown.FinishedNotification = finishedNotification;
                countdown.PinnedToStart        = pinnedToStart;

                if (imageData != null)
                {
                    if (imageData.Length > 0)
                    {
                        countdown.ImageData = imageData;
                        countdown.HasImage  = true;

                        await countdown.CreateImageFile();
                    }
                    else if (countdown.HasImage)
                    {
                        countdown.ImageData = null;
                        countdown.HasImage  = false;

                        await countdown.DeleteImageFile();
                    }
                }

                if (countdown.PinnedToStart)
                {
                    countdown.PinnedToStart = await TileManager.RefreshCountdown(countdown);
                }
                else
                {
                    await TileManager.UnpinCountdown(countdown);
                }

                if (countdown.FinishedNotification)
                {
                    countdown.FinishedNotification = NotificationManager.RefreshCountdown(countdown);
                }
                else
                {
                    NotificationManager.RemoveCountdown(countdown);
                }

                await database.SaveChangesAsync();

                return(countdown);
            }
        }