示例#1
0
        public static async Task UpdateOneCharacter(StructureContext context, Character character, bool force = false)
        {
            if (string.IsNullOrEmpty(character.AccessToken))
            {
                throw new Exception("User had no existing token.");
            }
            if (character.ExpiresAt < DateTime.UtcNow)
            {
                var token = await EVESwagger.GetToken(Token.REFRESH, character.RefreshToken);

                character.ConsumeToken(token);

                context.Update(character);

                await context.SaveChangesAsync();
            }

            //get notifications
            // if (force || character.ExpiresAt < DateTime.UtcNow){
            var notifications =
                await EVESwagger.GetNotificationsByCharacterId(character.CharacterID, character.AccessToken);

            //deduplciated
            //TODO this SHould work except it doesnt so we need to figure out why.
            // var Current = context.Notifications.Select(x => x.NotificationId).ToArray();
            notifications = notifications.Where(n => context.Notifications.Select(x => x.NotificationId).Contains(n.NotificationId) == false).ToList();
            context.Notifications.AddRange(notifications);
            context.SaveChanges();
            // }
        }
        public async Task Hide(long id)
        {
            using (var context = new StructureContext())
            {
                var notif = context.Notifications.Find(id);
                if (notif != null)
                {
                    notif.Hidden = true;
                    context.Update(notif);
                    await context.SaveChangesAsync();
                }
            }


            Response.Redirect("/Me/Notifications");
        }