Exemple #1
0
        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
                });
            }
        }