public HttpResponseMessage Post([FromBody] LearningResourcesRequest request) { HttpResponseMessage response; try { LearningResourcesResponse learningResourcesResponse = new LearningResourcesResponse { LearningResources = new ObservableCollection <LearningResource>() }; using (DbModel.TechReadyDbContext ctx = new DbModel.TechReadyDbContext()) { var learningResources = (from c in ctx.LearningResources select c).ToList(); foreach (var lr in learningResources) { try { learningResourcesResponse.LearningResources.Add(CreateDxLearningResource(lr)); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } } } response = Request.CreateResponse(HttpStatusCode.OK, learningResourcesResponse); response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300)); } catch (Exception ex) { HttpError myCustomError = new HttpError(ex.Message) { { "IsSuccess", false } }; return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError)); } return(response); }
public static async Task <ObservableCollection <LearningResource> > GetLearningResourcesFromServer( LearningResourcesRequest request) { try { var result = await ServiceProxy.CallService("api/LearningResources", JsonConvert.SerializeObject(request)); if (result.IsSuccess) { var homeResponse = JsonConvert.DeserializeObject <LearningResourcesResponse>(result.response); return(homeResponse.LearningResources); } else { return(null); } } catch (Exception) { return(null); } }
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; } }