public bool AddInternRating(InternRatingRequest request) { if (request.InternId != 0 && request.Rating.Any()) { var avgInternRating = (int)request.Rating.Average(x => x.RatingId); foreach (var rate in request.Rating) { this.internRatingRepository.Create(new InternRating() { InternsId = request.InternId, RatingMasterId = rate.RatingId, TechnologiesId = rate.TechId, CreatedDate = DateTime.Now }); } this.internRatingRepository.Save(); var updateItem = this.internRepository.FindByCondition(x => x.InternsId == request.InternId).FirstOrDefault(); updateItem.OverallRating = avgInternRating; this.internRepository.Update(updateItem); this.internRepository.Save(); return(true); } return(false); }
public IEnumerable <InternRatingResponse> GetInternRatings(InternRatingRequest request) { if (request.InternId != 0) { //var response = this.internRatingRepository.FindByCondition(x => x.InternsId == request.InternId, "Interns,Technologies,Technologies.ProjectTechnologiesRelation,Technologies.ProjectTechnologiesRelation.Projects,Rating") // .ToList() // .Select( // x => new InternRatingResponse() // { // InternId = x.Interns.InternsId, // InternName = x.Interns?.Name, // //ProjectName = x.Interns?.ProjectInternRelation?.FirstOrDefault()?.Projects.Name, // ProjectName = x.Technologies.ProjectTechnologiesRelation.Select(y => y.Projects.Name).FirstOrDefault(), // TechId = x.TechnologiesId, // ProjectDescription = x.Technologies.ProjectTechnologiesRelation.Select(y => y.Projects.Description).FirstOrDefault(), // TechnologyName = x.Technologies?.Name, // TechnologyRating = x.Rating?.Rate // }); var response = this.projectInternRepository.FindByCondition(x => x.InternsId == request.InternId, "Interns,Interns.InternRating,Interns.InternRating.Rating,Projects,Projects.ProjectTechnologiesRelation,Projects.ProjectTechnologiesRelation.Technologies,Projects.MentorProjectRelation,Projects.MentorProjectRelation.Mentor") .ToList() .Select( x => new InternRatingResponse() { InternId = x.InternsId, InternName = x.Interns.Name, ProjectName = x.Projects.Name, ProjectDescription = x.Projects.Description, TechIds = x.Projects.ProjectTechnologiesRelation.Select(y => y.TechnologiesId).ToList(), TechnologyNameList = x.Projects.ProjectTechnologiesRelation.Select(y => y.Technologies.Name).ToList(), Ratings = x.Interns.InternRating.Select(y => y.Rating.Rate).ToList(), Email = x.Interns.EmailId, PhoneNo = x.Interns.PhoneNo, MentorName = x.Projects.MentorProjectRelation?.FirstOrDefault().Mentor.Name }); if (!response.Any()) { response = this.internRepository.FindByCondition(x => x.InternsId == request.InternId) .Select(x => new InternRatingResponse() { InternId = x.InternsId, InternName = x.Name, ProjectName = "-", ProjectDescription = "-", TechnologyNameList = new List <string>(), Email = x.EmailId, PhoneNo = x.PhoneNo }); } return(response); } return(Enumerable.Empty <InternRatingResponse>()); }
public IActionResult GetInternRating(InternRatingRequest request) { try { return(Ok(ratingService.GetInternRatings(request))); } catch (Exception ex) { this.logger.Error(ex); throw; } }
public IActionResult Post(InternRatingRequest request) { try { var response = ratingService.AddInternRating(request); if (response == true) { return(Ok(response)); } else { return(BadRequest()); } } catch (Exception ex) { this.logger.Error(ex); throw; } }