Esempio n. 1
0
        private async Task SetLearningContent(ObservableCollection <LearningResource> model)
        {
            if (model != null)
            {
                var usermodel = await LocalStorage.ReadJsonFromFile <UserRegistrationPageViewModel>("registration");

                if (usermodel != null)
                {
                    foreach (LearningResource rs in model)
                    {
                        if (
                            rs.AudienceTypes.FirstOrDefault(
                                x => x.AudienceTypeName == usermodel.SelectedAudienceType.AudienceTypeName) != null)
                        {
                            rs.Weitage++;
                        }

                        if (
                            usermodel.SecondaryTechnologies.FirstOrDefault(
                                x => x.PrimaryTechnologyName == rs.PrimaryTechnologyName) != null)
                        {
                            rs.Weitage++;
                        }
                    }

                    model = new ObservableCollection <LearningResource>(model.OrderByDescending(x => x.Weitage));

                    await LearningResourceService.SaveLearningResources(model);

                    this.AllLearningResources = model;

                    var recomendedresources =
                        new ObservableCollection <LearningResource>(model.OrderByDescending(x => x.Weitage).ToList());

                    if (AllLearningResources.Count > 5)
                    {
                        recomendedresources = new ObservableCollection <LearningResource>(recomendedresources.Take(5));
                        recomendedresources.Add(new LoadMoreLearningResource());
                    }
                    else
                    {
                        recomendedresources = AllLearningResources;
                    }

                    this.RecommendedLearningResources = recomendedresources;

                    OnPropertyChanged("AllLearningResources");
                    OnPropertyChanged("RecommendedLearningResources");
                }
            }
        }
Esempio n. 2
0
        public async Task GetLearningContent()
        {
            this.OperationInProgress = true;
            try
            {
                LearningResourcesRequest request = new LearningResourcesRequest()
                {
                    RequestedPageNo = 1,
                    SourceType      = "All",
                    Technologies    = new List <string>(),
                    UserRole        = "All"
                };


                ObservableCollection <LearningResource> model =
                    await LearningResourceService.GetLearningResourcesFromLocal();

                await SetLearningContent(model);

                if (NetworkHelper.IsNetworkAvailable() == false)
                {
                    if (model == null)
                    {
                        await MessageHelper.ShowMessage("Please connect to internet to download learning resources");

                        return;
                    }
                }
                else
                {
                    var result = await LearningResourceService.GetLearningResourcesFromServer(request);

                    if (result != null)
                    {
                        model = result;
                        await LearningResourceService.SaveLearningResources(model);
                    }
                    else
                    {
                        //await MessageHelper.ShowMessage(result.Error.Message);
                    }
                }

                var favVideos =
                    await LocalStorage.ReadJsonFromFile <ObservableCollection <LearningResource> >("watchedVideos");

                foreach (var flr in favVideos)
                {
                    var lr = model.Where(x => x.LearningResourceID == flr.LearningResourceID).FirstOrDefault();
                    if (lr != null)
                    {
                        lr.Favourited = true;
                    }
                }
                await SetLearningContent(model);
            }
            catch (Exception)
            {
            }
            finally
            {
                this.OperationInProgress = false;
            }
        }