I am new to programming so i don't know what i am doing. I am pulling enum value from different class and set them as getter and setter.
namespace DataLayer.Entities
{
public enum CourseModeOfDelivery
{
Online, ClassRoom, ELearning,
}
public class Course
{
public int ID { get; set; }
public String CourseName { get; set; }
public String Description { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public CourseModeOfDelivery CourseMode { get; set; }
}
reading this value in courseRepository
public static Course GetCourse(int id)
{
Course a = new Course();
String GetCommand = "Select CourseName, Description, StartDate, EndDate, CourseMode from Course" + "Where ID = @CourseID";
SqlConnection connection = DBManager.GetSqlConnection();
SqlCommand command = new SqlCommand(GetCommand, connection);
command.Parameters.AddWithValue("@StudentID", id);
try
{
var reader = command.ExecuteReader();
//Read the Command Object and then return details
if (reader.HasRows)
{
while (reader.Read())
{
a.ID = Convert.ToInt32(reader["ID"]);
a.CourseName = reader["CourseName"].ToString();
a.Description = reader["Description"].ToString();
a.StartDate = DateTime.Parse(reader["StartDate"].ToString());
a.EndDate = DateTime.Parse(reader["EndDate"].ToString());
var selection = CourseModeOfDelivery.ClassRoom;
switch (selection)
{
case CourseModeOfDelivery.ClassRoom:
a.CourseMode = CourseModeOfDelivery.ClassRoom;
return a.CourseMode;
case CourseModeOfDelivery.ELearning:
a.CourseMode = CourseModeOfDelivery.ELearning;
return a.CourseMode;
case CourseModeOfDelivery.Online:
a.CourseMode = CourseModeOfDelivery.Online;
return a.CourseMode;
}
a.CourseMode =
}
}
else
{
reader.Close();
}
}
The requirement is to use switch but don't know how to pull data in there.
Aucun commentaire:
Enregistrer un commentaire