示例#1
0
        async Task refreshAvContentAsync()
        {
            var content = new List <AvContent> ();

            switch (UserRole)
            {
            case UserRoles.General:
                content = await azureClient.GetAsync <AvContent> (c => c.PublishedTo == UserRoles.General);

                break;

            case UserRoles.Insider:
                content = await azureClient.GetAsync <AvContent> (c => c.PublishedTo == UserRoles.General ||
                                                                  c.PublishedTo == UserRoles.Insider);

                break;

            case UserRoles.Producer:
            case UserRoles.Admin:
                content = await azureClient.GetAsync <AvContent> (c => c.PublishedTo == UserRoles.General ||
                                                                  c.PublishedTo == UserRoles.Insider ||
                                                                  c.PublishedTo == UserRoles.Producer);

                break;
            }

            AvContent [UserRoles.General]  = content.Where(c => c.PublishedTo == UserRoles.General).OrderByDescending(c => c.UpdatedAt).ToList();
            AvContent [UserRoles.Insider]  = content.Where(c => c.PublishedTo == UserRoles.Insider).OrderByDescending(c => c.UpdatedAt).ToList();
            AvContent [UserRoles.Producer] = content.Where(c => c.PublishedTo == UserRoles.Producer).OrderByDescending(c => c.UpdatedAt).ToList();

            AvContentChanged?.Invoke(this, UserRole);
        }
示例#2
0
        public async Task DeleteAvContent(AvContent item)
        {
            if (AvContent [item.PublishedTo].Remove(item))
            {
                AvContentChanged?.Invoke(this, item.PublishedTo);
            }

            var deletedItem = await Delete(item);
        }
示例#3
0
        public async Task <AvContent> CreateAvContent(AvContent item)
        {
            var newItem = await Create(item);

            AvContent [newItem.PublishedTo].Insert(0, newItem);

            AvContentChanged?.Invoke(this, newItem.PublishedTo);

            return(newItem);
        }
示例#4
0
        public async Task UpdateAvContent(AvContent item, UserRoles?oldRole = null, bool publish = true)
        {
            if (oldRole.HasValue && AvContent [oldRole.Value].Remove(item))
            {
                // specify old role if role is what changed
                AvContentChanged?.Invoke(this, oldRole.Value);
            }
            else if (AvContent [item.PublishedTo].Remove(item))
            {
                AvContentChanged?.Invoke(this, item.PublishedTo);
            }

            var newItem = await Replace(item);

            AvContent [newItem.PublishedTo].Add(newItem);

            AvContentChanged?.Invoke(this, newItem.PublishedTo);

            if (publish)
            {
                await PublishUpdate(newItem, oldRole);
            }
        }
示例#5
0
        public async Task GetAllAvContent()
        {
            if (!Initialized && !string.IsNullOrEmpty(Settings.ContentDataCache))
            {
                AvContent = JsonConvert.DeserializeObject <Dictionary <UserRoles, List <AvContent> > > (Settings.ContentDataCache);

                AvContentChanged?.Invoke(this, UserRole);
            }

            await RefreshAvContentAsync();

            async Task RefreshAvContentAsync()
            {
                try
                {
                    Expression <Func <AvContent, bool> > predicate = null;

                    switch (UserRole)
                    {
                    case UserRoles.General:
                        predicate = c => c.PublishedTo == UserRoles.General;
                        break;

                    case UserRoles.Insider:
                        predicate = c => c.PublishedTo == UserRoles.General || c.PublishedTo == UserRoles.Insider;
                        break;

                    case UserRoles.Producer:
                    case UserRoles.Admin:
                        predicate = c => c.PublishedTo == UserRoles.General || c.PublishedTo == UserRoles.Insider || c.PublishedTo == UserRoles.Producer;
                        break;
                    }

                    var content = await Get(predicate);

                    AvContent = content.GroupBy(c => c.PublishedTo).ToDictionary(g => g.Key, g => g.OrderByDescending(i => i.Timestamp).ToList());

                    if (!AvContent.ContainsKey(UserRoles.General))
                    {
                        AvContent [UserRoles.General] = new List <AvContent> ();
                    }
                    if (!AvContent.ContainsKey(UserRoles.Insider))
                    {
                        AvContent [UserRoles.Insider] = new List <AvContent> ();
                    }
                    if (!AvContent.ContainsKey(UserRoles.Producer))
                    {
                        AvContent [UserRoles.Producer] = new List <AvContent> ();
                    }


                    initialDataLoad = true;

                    AvContentChanged?.Invoke(this, UserRole);

                    Settings.ContentDataCache = JsonConvert.SerializeObject(AvContent);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    throw;
                }
            }
        }