Ejemplo n.º 1
0
        private List <CorporationDTO> FilterCorporationsByRating(List <CorporationDTO> corporations, double wantedRating)
        {
            var filteredCorporations = new List <CorporationDTO>();

            foreach (var corporation in corporations)
            {
                var avgRating = RatingHelper.CountAverageRating(corporation.RatingCount, corporation.SumRating);
                if (avgRating.HasValue && avgRating >= wantedRating)
                {
                    filteredCorporations.Add(corporation);
                }
            }

            return(filteredCorporations);
        }
        private List <FreelancerDTO> FilterFreelancersByRating(List <FreelancerDTO> freelancers, double wantedRating)
        {
            var filteredFreelancers = new List <FreelancerDTO>();

            foreach (var freelancer in freelancers)
            {
                var avgRating = RatingHelper.CountAverageRating(freelancer.RatingCount, freelancer.SumRating);
                if (avgRating.HasValue && avgRating >= wantedRating)
                {
                    filteredFreelancers.Add(freelancer);
                }
            }

            return(filteredFreelancers);
        }
Ejemplo n.º 3
0
        private CorporationListViewModel InitializeCorporationListViewModel(QueryResultDTO <CorporationDTO, CorporationFilterDTO> result)
        {
            var finalList = result.PagedResult();

            foreach (CorporationDTO corporation in finalList)
            {
                corporation.SumRating = RatingHelper.CountAverageRating(corporation.RatingCount, corporation.SumRating);
            }

            return(new CorporationListViewModel
            {
                Corporations = new List <CorporationDTO>(finalList),
                Filter = result.Filter,
                CurrentPageIndex = result.RequestedPageNumber.HasValue ? (int)result.RequestedPageNumber : 1,
                PageCount = (int)Math.Ceiling(result.TotalItemsCount / (double)result.PageSize)
            });
        }
        private FreelancerListViewModel InitializeFreelancerListViewModel(QueryResultDTO <FreelancerDTO, FreelancerFilterDTO> result)
        {
            var finalList = result.PagedResult();

            foreach (FreelancerDTO freelancer in finalList)
            {
                freelancer.SumRating = RatingHelper.CountAverageRating(freelancer.RatingCount, freelancer.SumRating);
            }

            return(new FreelancerListViewModel
            {
                Freelancers = new List <FreelancerDTO>(finalList),
                Filter = result.Filter,
                CurrentPageIndex = result.RequestedPageNumber.HasValue ? (int)result.RequestedPageNumber : 1,
                PageCount = (int)Math.Ceiling(result.TotalItemsCount / (double)result.PageSize)
            });
        }
Ejemplo n.º 5
0
        // GET: Corporations/Details/5
        public async Task <ActionResult> Details(int id)
        {
            var model = await UserFacade.GetCorporationAsync(id);

            var idOffers = await OfferFacade.ListOffersAsync(new OfferFilterDTO { SearchedAuthorsIds = new int[] { id } });

            model.Offers = new List <OfferDTO>(idOffers.Items);

            var appliedOffers = await OfferFacade.ListOffersAsync(new OfferFilterDTO { SearchedAppliersIds = new int[] { id } });

            model.AppliedToOffers = new List <OfferDTO>(appliedOffers.Items);

            var ratings = await RatingFacade.ListRatingsAsync(new RatingFilterDTO { SearchedRatedUsersId = new int[] { id } });

            model.Ratings = await RatingHelper.MergeRatingsCreators(UserFacade, ratings.Items.ToList());

            model.SumRating = RatingHelper.CountAverageRating(model.RatingCount, model.SumRating);

            return(View("CorporationDetailView", model));
        }
        // GET: FreelancerController/Details/5
        public async Task <ActionResult> Details(int id)
        {
            var model = await UserFacade.GetFreelancerAsync(id);

            var user = await UserFacade.GetUserAsync(id);

            var offers = await OfferFacade.ListOffersAsync(new OfferFilterDTO { SearchedAuthorsIds = new int[] { id } });

            model.Offers = new List <OfferDTO>(offers.Items);

            var appliedOffers = await OfferFacade.ListOffersAsync(new OfferFilterDTO { SearchedAppliersIds = new int[] { id } });

            model.AppliedToOffers = new List <OfferDTO>(appliedOffers.Items);

            var ratings = await RatingFacade.ListRatingsAsync(new RatingFilterDTO { SearchedRatedUsersId = new int[] { id } });

            model.Ratings = await RatingHelper.MergeRatingsCreators(UserFacade, ratings.Items.ToList());

            model.SumRating = RatingHelper.CountAverageRating(model.RatingCount, model.SumRating);

            return(View("FreelancerDetailView", InitializeFreelancerDetailViewModel(model, user.UserName)));
        }
        public new async Task <ActionResult> Profile()
        {
            var user = await userFacade.GetUserAccordingToUsernameAsync(User.Identity.Name);

            var idOffers = await offerFacade.ListOffersAsync(new OfferFilterDTO { SearchedAuthorsIds = new int[] { user.Id } });

            var idAppliedOffers = await offerFacade.ListOffersAsync(new OfferFilterDTO { SearchedAppliersIds = new int[] { user.Id } });

            var idRatings = await ratingFacade.ListRatingsAsync(new RatingFilterDTO { SearchedRatedUsersId = new int[] { user.Id } });

            if (user.UserRole == "Freelancer")
            {
                var freelancer = await userFacade.GetFreelancerAsync(user.Id);

                freelancer.Offers          = new List <OfferDTO>(idOffers.Items);
                freelancer.AppliedToOffers = new List <OfferDTO>(idAppliedOffers.Items);
                freelancer.Ratings         = await RatingHelper.MergeRatingsCreators(userFacade, idRatings.Items.ToList());

                freelancer.SumRating = RatingHelper.CountAverageRating(freelancer.RatingCount, freelancer.SumRating);

                return(View("Users/FreelancerDetailView", ToProfileModel(freelancer, user.UserName)));
            }
            else if (user.UserRole == "Corporation")
            {
                var corporation = await userFacade.GetCorporationAsync(user.Id);

                corporation.Offers          = new List <OfferDTO>(idOffers.Items);
                corporation.AppliedToOffers = new List <OfferDTO>(idAppliedOffers.Items);
                corporation.Ratings         = await RatingHelper.MergeRatingsCreators(userFacade, idRatings.Items.ToList());

                corporation.SumRating = RatingHelper.CountAverageRating(corporation.RatingCount, corporation.SumRating);

                return(View("Users/CorporationDetailView", corporation));
            }

            return(RedirectToAction("Index", "Home"));
        }