Exemplo n.º 1
0
        // TODO
        //public async Task<ActionResult> AddReview()
        //{
        //    string ratingId = Request.QueryString["ratingId"];
        //    string companyId = Request.QueryString["CompanyRating"];
        //    // Get the document to edit
        //    CompanyRating companyRating = await _companyService.GetDocumentAsync(ratingId, companyId);
        //    //Rating Model = new Rating();
        //    return View(companyRating);
        //}

        // TODO
        //[HttpPost]
        //public async Task<ActionResult> AddReview(Rating newRating)
        //{
        //    string ratingId = Request.QueryString["ratingId"];
        //    string companyId = Request.QueryString["CompanyRating"];
        //    // Get the No SQL document to edit
        //

        // TODO
        //    // Add the document then send it to the update method

        //    CompanyRating NewCompanyRating = mapNewRatings(companyRating, newRating);

        //    //Save to doc db
        //    await _companyService.UpdateDocumentAsync(NewCompanyRating);
        //    if(newRating.Body != null && newRating.Heading != null)
        //    {
        //        return RedirectToAction("CompanyRating", "Home", new { CompanyRating = NewCompanyRating.CompanyId });
        //    }

        //    return View(NewCompanyRating);
        //}

        private CompanyRating mapNewRatings(CompanyRating companyRating, Rating newRating)
        {
            List <Rating> RatingList = new List <Rating>();

            foreach (var item in companyRating.Ratings)
            {
                if (item.Body != null)
                {
                    RatingList.Add(item);
                }
            }
            if (newRating.Body != null)
            {
                newRating.Date = DateTime.Now;
                RatingList.Add(newRating);
            }

            CompanyRating newCompanyRating = new CompanyRating
            {
                Id          = companyRating.Id,
                CompanyId   = companyRating.CompanyId,
                Key         = companyRating.Key,
                CompanyName = companyRating.CompanyName,
                Ratings     = RatingList,
            };

            return(newCompanyRating);
        }
Exemplo n.º 2
0
        // TODO
        //private async Task<IPagedList<JobPostingInfo>> MapRatings(IPagedList<JobPostingInfo> viewModel)
        //{
        //    foreach (var jobInfo in viewModel)
        //    {
        //       /* Get ratings here and add them to view here */
        //       var rating = ratings.FirstOrDefault(r => r.CompanyId == jobInfo.CompanyId);
        //       jobInfo.AverageRating = GetAverageRating(rating);
        //    }
        //    return viewModel;
        //}

        private int GetAverageRating(CompanyRating rating)
        {
            var total = 0;

            foreach (var item in rating.Ratings)
            {
                total += item.NumberOfStars;
            }
            return(total / rating.Ratings.Count());
        }