Example #1
0
        public ActionResult <IEnumerable <ReviewDisplayRow> > Get(int id)
        {
            var reviewRows = new List <ReviewDisplayRow>();

            using (var context = new DoctorRatingContext())
            {
                var reviews = (
                    from d in context.Doctors
                    join rv in context.PatientRatings on d.Id equals rv.DoctorId
                    where rv.DoctorId == id
                    select new
                {
                    Id = rv.Id,
                    DoctorId = rv.DoctorId,
                    Comments = rv.Comments,
                    Rating = rv.Rating
                }).ToList();

                foreach (var review in reviews)
                {
                    ReviewDisplayRow revRow = new ReviewDisplayRow();
                    revRow.Id       = review.Id.ToString();
                    revRow.DoctorId = review.DoctorId.ToString();
                    revRow.Comments = review.Comments;
                    revRow.Rating   = review.Rating.ToString();
                    reviewRows.Add(revRow);
                }
            }
            return(reviewRows.ToArray());
        }
Example #2
0
 public Startup(IConfiguration configuration)
 {
     Configuration = configuration;
     using (var client = new DoctorRatingContext())
     {
         client.Database.EnsureCreated();
     }
 }
        public ActionResult <IEnumerable <DoctorDisplayRow> > Get()
        {
            var doctorRows = new List <DoctorDisplayRow>();

            using (var context = new DoctorRatingContext())
            {
                var doctors = (
                    from d in context.Doctors
                    join ln in context.Languages on d.LanguageId equals ln.Id
                    join md in context.MedicalSchools on d.MedicalSchoolId equals md.Id
                    join dxs in context.DoctorSpecialties on d.Id equals dxs.DoctorId
                    join sp in context.Specialties on dxs.SpecialtyId equals sp.Id
                    group sp.Name by new
                {
                    d.Id,
                    d.Name,
                    d.Gender,
                    Language = ln.Name,
                    School = md.Name
                } into zrx
                    select new
                {
                    Id = zrx.Key.Id,
                    Name = zrx.Key.Name,
                    Gender = zrx.Key.Gender,
                    Language = zrx.Key.Language,
                    School = zrx.Key.School,
                    Specialties = string.Join(", ", zrx.ToArray())
                }).ToList();

                foreach (var doctor in doctors)
                {
                    DoctorDisplayRow docRow = new DoctorDisplayRow();
                    docRow.Id          = doctor.Id.ToString();
                    docRow.Name        = doctor.Name;
                    docRow.Gender      = doctor.Gender;
                    docRow.Language    = doctor.Language;
                    docRow.School      = doctor.School;
                    docRow.Specialties = doctor.Specialties;
                    double avgScore = DoctorReviews.GetAverageRating(doctor.Id);
                    docRow.AvgRating = avgScore.ToString();
                    docRow.SuperStar = DoctorReviews.IsSuperStar(avgScore).ToString();
                    doctorRows.Add(docRow);
                }
            }
            return(doctorRows.ToArray());
        }
        public ActionResult <DoctorDisplayRow> Get(int id)
        {
            var doctorRow = new DoctorDisplayRow();

            using (var context = new DoctorRatingContext())
            {
                var doctor = (
                    from d in context.Doctors
                    join ln in context.Languages on d.LanguageId equals ln.Id
                    join md in context.MedicalSchools on d.MedicalSchoolId equals md.Id
                    join dxs in context.DoctorSpecialties on d.Id equals dxs.DoctorId
                    join sp in context.Specialties on dxs.SpecialtyId equals sp.Id
                    group sp.Name by new
                {
                    d.Id,
                    d.Name,
                    d.Gender,
                    Language = ln.Name,
                    School = md.Name
                } into zrx
                    where zrx.Key.Id == id
                    select new
                {
                    Id = zrx.Key.Id,
                    Name = zrx.Key.Name,
                    Gender = zrx.Key.Gender,
                    Language = zrx.Key.Language,
                    School = zrx.Key.School,
                    Specialties = string.Join(",", zrx.ToArray())
                }).FirstOrDefault();

                if (doctor != null)
                {
                    doctorRow.Id          = doctor.Id.ToString();
                    doctorRow.Name        = doctor.Name;
                    doctorRow.Gender      = doctor.Gender;
                    doctorRow.Language    = doctor.Language;
                    doctorRow.School      = doctor.School;
                    doctorRow.Specialties = doctor.Specialties;
                    double avgScore = DoctorReviews.GetAverageRating(doctor.Id);
                    doctorRow.AvgRating = avgScore.ToString();
                    doctorRow.SuperStar = DoctorReviews.IsSuperStar(avgScore).ToString();
                }
            }
            return(doctorRow);
        }
        public static double GetAverageRating(int doctorId)
        {
            double result = 0;

            using (var context = new DoctorRatingContext())
            {
                var avgRating = (
                    from d in context.Doctors
                    join rv in context.PatientRatings on d.Id equals rv.DoctorId
                    where rv.DoctorId == doctorId
                    group rv.Rating by rv.DoctorId into avr
                    select new
                {
                    AvgRating = avr.Average()
                }).FirstOrDefault();

                if (avgRating != null)
                {
                    result = avgRating.AvgRating;
                }
            }
            return(result);
        }