public void GetAllNewsfeeds() { new Thread(() => { NewsfeedRequest request = new NewsfeedRequest() { RequestType = RequestType.GetAll }; BaseDto bDto = new BaseDto { Type = DtoType.Newsfeed, JsonObject = JsonConvert.SerializeObject(request) }; string result = _remoteConnection.Request(bDto); if (String.IsNullOrEmpty(result)) { Log.Error(Tag, "GetAllWallposts error result is null"); return; } var arrayMessage = JsonConvert.DeserializeObject <ArrayMessage>(result); var tempItemList = new List <WallPost>(); foreach (var id in arrayMessage.Ids) { var convertedWallPost = GetSingleNewsfeedInternal(id); if (convertedWallPost != null) { tempItemList.Add(convertedWallPost); } } _newsfeedRepo.AddWallPosts(tempItemList); OnUpdate(this, null); }).Start(); }
public void GetSingleNewsfeed(int id) { new Thread(() => { NewsfeedRequest request = new NewsfeedRequest() { RequestType = RequestType.GetSingle, Id = id }; BaseDto bDto = new BaseDto { Type = DtoType.Newsfeed, JsonObject = JsonConvert.SerializeObject(request) }; string result = _remoteConnection.Request(bDto); if (String.IsNullOrEmpty(result)) { Log.Error(Tag, "GetSingleWallpost error result is null"); return; } NewsfeedDto dto = JsonConvert.DeserializeObject <NewsfeedDto>(result); if (dto == null) { Log.Error(Tag, String.Format("Could not parse newsfeeddto {0}", result)); return; } WallPost post = Mapper.Map <NewsfeedDto, WallPost>(dto); _newsfeedRepo.AddWallPosts(new List <WallPost>(new [] { post })); OnUpdate(this, null); }).Start(); }
WallPost GetSingleNewsfeedInternal(int id) { NewsfeedRequest request = new NewsfeedRequest() { RequestType = RequestType.GetSingle, Id = id }; BaseDto bDto = new BaseDto { Type = DtoType.Newsfeed, JsonObject = JsonConvert.SerializeObject(request) }; string result = _remoteConnection.Request(bDto); if (String.IsNullOrEmpty(result)) { Log.Error(Tag, "GetSingleWallpost error result is null"); return(null); } NewsfeedDto dto = JsonConvert.DeserializeObject <NewsfeedDto>(result); if (dto == null) { Log.Error(Tag, String.Format("Could not parse newsfeeddto {0}", result)); return(null); } WallPost post = Mapper.Map <NewsfeedDto, WallPost>(dto); return(post); }
public void PostSingleNewsfeed(WallPost post) { new Thread(() => { NewsfeedDto dto = Mapper.Map <WallPost, NewsfeedDto>(post); NewsfeedRequest request = new NewsfeedRequest() { RequestType = RequestType.PostSingle, SingleDto = dto, Token = "123498" //Token = _privateRepo.GetLocalUser().Token }; BaseDto bDto = new BaseDto { Type = DtoType.Newsfeed, JsonObject = JsonConvert.SerializeObject(request) }; string result = _remoteConnection.Request(bDto); if (String.IsNullOrEmpty(result)) { Log.Error(Tag, "GetSingleWallpost error result is null"); return; } var resultObject = JsonConvert.DeserializeObject <NewsfeedDto>(result); if (resultObject.Error != null) { Log.Error(Tag, resultObject.Error.Message); } }).Start(); }
string HandleRequest(NewsfeedRequest request) { switch (request.RequestType) { case RequestType.GetAll: return(GetAllWallPosts()); case RequestType.GetSingle: return(GetSingle(request)); case RequestType.PostSingle: return(ProcessSinglePost(request)); default: return(_requestNullMessage); } }
string GetSingle(NewsfeedRequest request) { if (request.Id == 0) { s_log.Warn("Request Single Newsfeed with Bad id"); return(_requestBadId); } var wallpost = _wallPostRepo.GetAllWallPosts().FirstOrDefault(i => i.Id.Equals(request.Id)); if (wallpost == null) { s_log.Warn(String.Format("Could not find wallpost with id {0}", request.Id)); return(_requestBadId); } return(JsonConvert.SerializeObject(ConvertWallPostToDto(wallpost))); }
string ProcessSinglePost(NewsfeedRequest request) { var user = _loginManager.VerifyToken(request.Token); if (user == null) { return(_requestBadAuth); } if (request.SingleDto == null) { return(_requestNullMessage); } WallPost post = Mapper.Map <NewsfeedDto, WallPost> (request.SingleDto); post.Owner = user; if (request.SingleDto.HeaderImage.Count() > 1) { var headerImagePath = _imageRepository.SaveImage(request.SingleDto.HeaderImage); if (headerImagePath.Item1) { post.HeaderImage = headerImagePath.Item2; } } if (request.SingleDto.Image.Count() > 1) { var imagePath = _imageRepository.SaveImage(request.SingleDto.Image); if (imagePath.Item1) { post.Image = imagePath.Item2; } } _wallPostRepo.AddWallPost(post); return(JsonConvert.SerializeObject(new NewsfeedDto() { Title = "OK" })); }