这是作业。该任务是创建一个网站,用户可以通过点击单选按钮等控件对医生进行评级,并选择他们喜欢的网站。
评级和收藏需要存储在会话中。对象应该 存储在应用程序中。
它应该有一个Admin页面,允许在应用程序集合中添加和删除新对象。我实现了大部分教师代码而没有评级位,但我得到一个错误,'MidtermApplication.Models.TestDoctorRepository'没有实现接口成员'MidtermApplication.Models.IRepository.GetDoctorByDoctorPicture(string)'G:\ ITMD563 \ MidtermApplication \ MidtermApplication \ Models \ TestDoctorRepository.cs提前致谢!
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MidtermApplication.Models
{
interface IRepository<T>
{
T GetDoctorByDoctorPicture(string DoctorPicture); //database specific
List<T> GetItems();
void Add(T entity);
void Remove(T entity);
void Update(T entity);
}
}
TestDoctorRepository类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MidtermApplication.Models
{
public class TestDoctorRepository : IDoctorRepository
{
List<Doctor> doctors;
public TestDoctorRepository()
{
doctors = new List<Doctor> {
new Doctor { DoctorPicture = "0cropped.jpg", DoctorName = "Michael Shores", DoctorSpecialty = "Opthamology", /*times = 0, rating = 0, rated = true, fave = true */},
new Doctor { DoctorPicture = "1cropped.jpg", DoctorName = "Ming Wu", DoctorSpecialty = "Cardiology"/*, times = 0, rating = 0, rated = true, fave = true*/ },
new Doctor { DoctorPicture = "2.cropped.jpg", DoctorName = "Susan McInerney", DoctorSpecialty = "Gynecology"/*, times = 0, rating = 0, rated = true, fave = true*/ },
new Doctor { DoctorPicture = "4.cropped.jpg", DoctorName = "Michelle Adkins", DoctorSpecialty = "Dermatology"/*, times = 0, rating = 0, rated = true, fave = true*/ },
new Doctor { DoctorPicture = "5.cropped.jpg", DoctorName = "Kathy Powers", DoctorSpecialty = "Gynecology"/*, times = 0, rating = 0, rated = true, fave = true*/ }
};
}
public List<Doctor> GetDoctor()
{
return doctors;
}
public Doctor GetDoctorByName(string name)
{
Doctor currentDoctor = null;
foreach (Doctor d in doctors)
{
if (d.DoctorName == name)
{
currentDoctor = d;
}
}
currentDoctor = (from d in doctors
where d.DoctorName.Contains(name)
select d).FirstOrDefault();
var anotherWay = doctors.Select(d => d.DoctorName.Contains(name)).FirstOrDefault();
if (currentDoctor == null)
{
currentDoctor = new Doctor { DoctorPicture = "", DoctorName = "No Name", DoctorSpecialty = "We didn't find that doctor." };
}
return currentDoctor;
}
public Doctor PairDoctorWithPatient(string patientName)
{
Doctor current = null;
switch (patientName)
{
case "Mary Rowe":
return doctors[0];
break;
default:
return doctors[1];
break;
}
return current;
}
public Doctor GetDoctorByDoctorPicure(string DoctorPicure)
{
var selectedDoctor = from d in doctors
where d.DoctorPicture == DoctorPicure
select d;
return selectedDoctor.FirstOrDefault();
}
public List<Doctor> GetItems()
{
return this.GetDoctor();
}
public virtual void Add(Doctor entity)
{
doctors.Add(entity);
}
public virtual void Remove(Doctor entity)
{
doctors.Remove(entity); // doctors.Add(entity);
}
public virtual void Update(Doctor entity)
{
Doctor doctor = (from d in doctors where d.DoctorPicture == entity.DoctorPicture select d).FirstOrDefault();
doctor.DoctorPicture = entity.DoctorPicture;
doctor.DoctorName = entity.DoctorName;
doctor.DoctorSpecialty = entity.DoctorSpecialty;
}
public void Remove(string DoctorPicture)
{
var doctor = from d in doctors where d.DoctorPicture == DoctorPicture select d;
doctors.Remove(doctor.FirstOrDefault());
}
}
}
IDoctorRepository接口
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MidtermApplication.Models
{
interface IDoctorRepository : IRepository<Doctor>
{
List<Doctor> GetDoctor(); //break my basic repo syntax
Doctor GetDoctorByName(string DoctorName);
Doctor GetDoctorByDoctorPicture(string DoctorPicture);
Doctor PairDoctorWithPatient(string PatientName);
}
}