Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THIS IS CODE FOR A C# CLASS I\'M WORKING ON I WOULD LIKE YOU TO PUT COMMENTS for

ID: 3597680 • Letter: T

Question

THIS IS CODE FOR A C# CLASS I'M WORKING ON I WOULD LIKE YOU TO PUT COMMENTS for CActivatorList : List TO HELP ME UNDERSTAND BETTER

public class CActivator
{
public Guid Id { get; set; }
public Guid QuestionId { get; set; }
public string ActivatorCode { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }

public CActivator()
{

}

// Custom constructor
public CActivator(Guid id)
{
Id = id;
}

public CActivator(string activatorcode)
{
ActivatorCode = activatorcode;
}
public CActivator(Guid id,
string activatorcode)
{
Id = id;
ActivatorCode = activatorcode;
}

public CActivator(string activatorcode,
Guid questionid,
DateTime startdate,
DateTime enddate)
{
ActivatorCode = activatorcode;
QuestionId = questionid;
StartDate = startdate;
EndDate = enddate;
}

public CActivator(Guid id,
string activatorcode,
Guid questionid,
DateTime startdate,
DateTime enddate)
{
Id = id;
ActivatorCode = activatorcode;
QuestionId = questionid;
StartDate = startdate;
EndDate = enddate;
}

public void Insert()
{
try
{
QuestionsDataContext oDc = new QuestionsDataContext();

tblActivation activation = new tblActivation();
activation.Id = Guid.NewGuid();
activation.ActivationCode = this.ActivatorCode;
activation.StartDate = this.StartDate;
activation.EndDate = this.EndDate;
activation.QuestionId = this.QuestionId;

// Needed to assign the Id to the class
// Otherwise, it's empty.
this.Id = activation.Id;

oDc.tblActivations.InsertOnSubmit(activation);
oDc.SubmitChanges();
}
catch (Exception ex)
{

throw ex;
}
}

}

public class CActivatorList : List<CActivator>
{
public void Load()
{
try
{
QuestionsDataContext oDc = new QuestionsDataContext();

var results = (from a in oDc.tblActivations
select a).ToList();

foreach (var activator in results)
{
CActivator oActivator = new CActivator();
oActivator.Id = activator.Id;
oActivator.ActivatorCode = activator.ActivationCode;
oActivator.QuestionId = activator.QuestionId;
oActivator.StartDate = activator.StartDate;
oActivator.EndDate = activator.EndDate;
  
Add(oActivator);
}

}
catch (Exception ex)
{

throw ex;
}
}
}

public class CActivator public Guid Id { get; set; ) public Guid QuestionId get; set; public string ActivatorCode { get; set public DateTime StartDate get; set; ) public DateTime EndDate get; set; ) public CActivator() // Custom constructor public CActivator(Guid id) Id = id; public CActivator(string activatorcode) ActivatorCode activat°rcode; =

Explanation / Answer

Please find the updated code below including comments. Comments are added wherever necessary.

//this class is to create a List of type CActivator i.e. CActivatorList : List<CActivator>
public class CActivatorList : List<CActivator>
{
public void Load()
{
try
{
QuestionsDataContext oDc = new QuestionsDataContext();
               //executing a query to fetch all the Activations records and converting into a list using ToList() method.
var results = (from a in oDc.tblActivations
select a).ToList();
                             
               //iterating through all the Activations objects (i.e. results object)
foreach (var activator in results)
{
                   //fetching the data from each 'activator' and setting to CActivator object
CActivator oActivator = new CActivator();
oActivator.Id = activator.Id;
oActivator.ActivatorCode = activator.ActivationCode;
oActivator.QuestionId = activator.QuestionId;
oActivator.StartDate = activator.StartDate;
oActivator.EndDate = activator.EndDate;
  
                   //Adding the CActivator object to the CActivatorList which is a List of type CActivator
Add(oActivator);
}
}
catch (Exception ex)
{
throw ex;
}
}
}