Beispiel #1
0
        public async Task <IActionResult> Profile(int id)
        {
            //Gets currently logged in user
            AppUser currentUser = await _appUserManager.GetUserAsync(User);

            //Returns List<Post> of user whose profile is being viewed, as split query,
            //because of cartesian explosion
            List <Post> userPosts = await _postRepository.GetAll()
                                    .Where(p => p.AppUserId == id)
                                    .Include(p => p.Post_Ingredients)
                                    .ThenInclude(pi => pi.Ingredient)
                                    .Include(p => p.AppUser)
                                    .Include(p => p.Comments)
                                    .ThenInclude(c => c.Commentator)
                                    .OrderByDescending(p => p.TimeOfPosting)
                                    .AsSplitQuery()
                                    .AsNoTracking()
                                    .ToListAsync();

            //Convers Posts to PostsModel type
            List <PostModel> userPostsModel = userPosts.ToPostModel()
                                              .ToList();

            #region Most efficient query for userPostsModel, use it when entity framework core 6.0 gets released!! AsSplitQuery() doesn't work on projections yet!!
            //Most efficient query for postmodel, use it when entity framework core 6.0 gets released!! Don't forget to chain AsSplitQuery()!!
            //var userPostsModel = _postRepository.GetAll()
            //                                    .Where(p => p.AppUserId == id)
            //                                    .ToPostModelTest()
            //                                    .ToList();
            #endregion

            //Gets the user whose profile is being viewed
            AppUserModel userModelProfile = await _appUserManager.FindByIdAsync(id.ToString())
                                            .ContinueWith(au => au.Result.ToAppUserModelBaseInfo());

            //Checks and sets bool if current user is following the one whose profile is being viewed
            userModelProfile.IsBeingFollowed = _user_FollowsRepository.GetAll()
                                               .Any(u => u.FollowerId == currentUser.Id && u.FollowsId == id);

            //Gets all the posts which current user has liked from user whose profile he is visiting
            List <Yummy_Post> currentUsersYummedPosts = await _yummy_PostRepository.GetAll()
                                                        .Where(yp => yp.AppUserId == currentUser.Id && yp.PostAppUserId == id)
                                                        .ToListAsync();

            //Sets IsPostYummed property if current user has already liked the post, would probably be the best to denormalize database instead of doing this
            foreach (var yummedPost in currentUsersYummedPosts)
            {
                userPostsModel.SingleOrDefault(p => p.Id == yummedPost.PostId).IsPostYummed = true;
            }

            //To pass necessary data for view
            ViewBag.UserProfile = userModelProfile;
            ViewBag.CurrentUser = currentUser;

            return(View(userPostsModel));
        }
Beispiel #2
0
        public async Task <IActionResult> GetAll([FromQuery] SubjectParams subjectParams)
        {
            var subjects = await _repo.GetAll <Subject>(subjectParams);

            var returnSubjects = _mapper.Map <IEnumerable <SubjectDTO> >(subjects);

            {
                switch (subjectParams.OrderBy)
                {
                case "az":
                    returnSubjects = returnSubjects.OrderBy(t => t.SubjectName);
                    break;

                case "za":
                    returnSubjects = returnSubjects.OrderByDescending(t => t.SubjectName);
                    break;

                case "enrolled":
                    returnSubjects = returnSubjects.OrderByDescending(t => t.EnrolledCount);
                    break;

                case "exp":
                    returnSubjects = returnSubjects.OrderByDescending(t => t.ExpGain);
                    break;

                default:
                    break;
                }
            }
            Response.AddPaginationHeader(subjects.CurrentPages, subjects.PageSize, subjects.TotalCount, subjects.TotalPages);
            return(Ok(returnSubjects));
        }
Beispiel #3
0
        public IEnumerable <T> GetAll()
        {
            Log("In decorator - Before Getting Entities");
            var result = _decorated.GetAll();

            Log("In decorator - After Getting Entities");
            return(result);
        }
Beispiel #4
0
        public async Task <IActionResult> GetAll(SubjectParams subjectParams)
        {
            var temp = await _repo.GetAll <Level>(subjectParams, "Accounts");

            var levelListForReturn = _mapper.Map <IEnumerable <LevelDetailDTO> >(temp);

            return(Ok(levelListForReturn.ToList()));
        }
Beispiel #5
0
        public List <TransactionViewModel> GetAll()
        {
            List <TransactionViewModel> _transactionViewModels = new List <TransactionViewModel>();
            List <Transaction>          _transactions          = _transactionManager.GetAll();

            foreach (var transaction in _transactions)
            {
                TransactionViewModel viewModel = new TransactionViewModel();
                viewModel.TransactionId       = transaction.TransactionId;
                viewModel.TransactionType     = Enum.GetName(typeof(ETransactionType), transaction.TransactionCategory.TransactionType);
                viewModel.DateTime            = transaction.TransactionDate.ToString("yyyy-MM-dd");
                viewModel.TransactionCategory = transaction.TransactionCategory.TransactionCategoryName;
                viewModel.UserName            = transaction.User.Name;
                viewModel.Amount = transaction.Sum;
                _transactionViewModels.Add(viewModel);
            }
            return(_transactionViewModels.OrderBy(z => z.DateTime).ToList());
        }
Beispiel #6
0
        public async Task <IActionResult> GetReportedPosts()
        {
            //Gets all reported posts and converts them to postmodel
            List <Post> reportedPosts = await _postRepository.GetAll()
                                        .Where(p => p.IsReported == true)
                                        .Include(p => p.AppUser)
                                        .Include(p => p.Post_Ingredients)
                                        .ThenInclude(pi => pi.Ingredient)
                                        .OrderByDescending(p => p.TimeOfPosting)
                                        .AsSplitQuery()
                                        .AsNoTracking()
                                        .ToListAsync();

            List <PostModel> reportedPostsModel = reportedPosts.ToPostModel().ToList();

            //Gets necessary data for view
            ViewBag.CurrentUser = await _appUserManager.GetUserAsync(User);

            return(View(reportedPostsModel));
        }
        protected async Task <HttpResponseMessage> GetAll()
        {
            IEnumerable <TObject> objectList = await repository.GetAll();

            return(Request.CreateResponse <IEnumerable <TObject> >(HttpStatusCode.OK, objectList));
        }
Beispiel #8
0
 public IEnumerable <SuperHeroClient> GetAll()
 {
     return(_repo.GetAll().Select(x => x.ToClient()));
 }
Beispiel #9
0
        public async Task <IActionResult> GetAll(SubjectParams subjectParams)
        {
            var certificates = await _repo.GetAll <Certificate>(subjectParams);

            return(Ok(certificates));
        }
Beispiel #10
0
 public async Task <IActionResult> GetAll(SubjectParams subjectParams)
 {
     return(Ok(await _repo.GetAll <History>(subjectParams, "Account,Subject")));
 }
Beispiel #11
0
        public async Task <IActionResult> GetAll(SubjectParams subjectParams)
        {
            var badges = await _repo.GetAll <Badge>(subjectParams, "Accounts");

            return(Ok(badges));
        }
Beispiel #12
0
        public async Task <IActionResult> GetAll(SubjectParams subjectParams)
        {
            var enrolleds = await _repo.GetAll <Enrolled>(subjectParams, "Account,Subject");

            return(Ok(enrolleds));
        }
 public IEnumerable <SuperHeroGlobal> Get()
 {
     return(_repo.GetAll());
 }
Beispiel #14
0
        public async Task <IActionResult> GetAll(SubjectParams subjectParams)
        {
            var questions = await _repo.GetAll <Question>(subjectParams, "Subject");

            return(Ok(questions));
        }
 public ActionResult Index()
 {
     return(View(_service.GetAll()));
 }