public async Task <object> LoadMore([FromBody] FeedPageModel webFeedPageModel) { FeedPageModel model = new FeedPageModel(); bool result = true; string error = string.Empty; try { var id = webFeedPageModel.UserId; model.PageNumber = webFeedPageModel.PageNumber + 1; model.PageSize = webFeedPageModel.PageSize; model.listFeed = new List <FeedViewModel>(); model.listFeed = _feedRepository.GetFeedById(id, model.PageNumber, model.PageSize); List <FeedViewModel> listFeed = new List <FeedViewModel>(); foreach (FeedViewModel item in model.listFeed) { FeedViewModel newItem = item; byte[] data = Convert.FromBase64String(item.Data); string decodedString = Encoding.UTF8.GetString(data); newItem.Data = decodedString; //adding comments of the feed newItem.CommentsViewModel = new List <CommentsViewModel>(); newItem.CommentsViewModel = _feedRepository.GetCommentsByFeedId(item.FeedId); listFeed.Add(newItem); } model.listFeed = listFeed; model.listDepartment = _departmentRepository.GetDepartmentsByUserId(id); model.listDepartmentItems = new List <SelectListItem>(); foreach (var item in model.listDepartment) { SelectListItem listItem = new SelectListItem { Text = item.Name, Value = item.DepartmentId.ToString() }; model.listDepartmentItems.Add(listItem); } } catch (Exception ex) { result = false; error = ex.Message; } return(new SingleResponse <FeedPageModel> { Message = error, DidError = !result, ErrorMessage = error, Token = string.Empty, Model = model }); }
public async Task <JsonResult> LoadMore(int PageNumber, int PageSize) { try { FeedPageModel loadMoreFeedPageModel = new FeedPageModel(); loadMoreFeedPageModel.UserId = HttpContext.Session.GetObject(StorageType.UserId).ToString();//LocalStorageExtensions.Get(StorageType.UserId); loadMoreFeedPageModel.PageNumber = PageNumber; loadMoreFeedPageModel.PageSize = PageSize; string response = await APICallerExtensions.APICallAsync("Feed/LoadMore", loadMoreFeedPageModel, false, HttpContext.Session.GetObject(StorageType.Token).ToString()); if (response.ToLower().Contains("exception:")) { ModelState.AddModelError(string.Empty, response); return(Json(new { result = false, error = response })); } var content = JsonConvert.DeserializeObject <SingleResponse <FeedPageModel> >(response); if (!content.DidError) { return(Json(new { content.Model, })); } else { return(Json(new { result = false, error = content.ErrorMessage })); } } catch (Exception ex) { return(Json(new { result = false, error = ex.Message })); } }
public async Task <object> Index([FromBody] UserModel userModel) { try { FeedPageModel model = new FeedPageModel(); var id = userModel.Id; //adding picture instead of using cookies model.UserPicture = userModel.Picture; //if (Request.Cookies["Picture"] != null) //{ // model.UserPicture = Request.Cookies["Picture"]; // if (string.IsNullOrEmpty(model.UserPicture)) // { // model.UserPicture = "user.jpg"; // } //} model.PageNumber = 0; model.PageSize = 5; model.listFeed = new List <FeedViewModel>(); model.listFeed = _feedRepository.GetFeedById(id, model.PageNumber, model.PageSize); List <FeedViewModel> listFeed = new List <FeedViewModel>(); foreach (FeedViewModel item in model.listFeed) { FeedViewModel newItem = item; byte[] data = Convert.FromBase64String(item.Data); string decodedString = Encoding.UTF8.GetString(data); newItem.Data = decodedString; //adding comments of the feed newItem.CommentsViewModel = new List <CommentsViewModel>(); newItem.CommentsViewModel = _feedRepository.GetCommentsByFeedId(item.FeedId); listFeed.Add(newItem); } model.listFeed = listFeed; model.listDepartment = _departmentRepository.GetDepartmentsByUserId(id); model.listDepartmentItems = new List <SelectListItem>(); foreach (var item in model.listDepartment) { SelectListItem listItem = new SelectListItem { Text = item.Name, Value = item.DepartmentId.ToString() }; model.listDepartmentItems.Add(listItem); } return(new SingleResponse <FeedPageModel> { Message = "Feed fetched successfully", DidError = false, ErrorMessage = string.Empty, Token = string.Empty, Model = model }); } catch (Exception ex) { return(new SingleResponse <FeedPageModel> { Message = ex.InnerException.ToString(), DidError = true, ErrorMessage = ex.Message, Token = string.Empty, Model = null }); } }