Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
List all the training registrations for all the courses. The
following information should be displayed.
✓ A list of all courses and their training registrations. After every course training iteration, display a list of
all delegates registered with all their relevant details (e.g address, dietary options etc )
Please ensure that your lab meet the below technology requirements.
✓ The Application should be in a source version control repository e.g GitHub ,GitLab, Bitbucket, Microsoft's
Azure DevOps etc .
✓ Use Entity framework (EF) code first approach or database first approach.
✓ If you chose code first approach use Entity framework (EF) migration to propagate your database
(or to deploy your changes to the database).
✓ Use Entity Framework and Linq to retrieve all the required information that need to be displayed.
✓ Use any plugin / library to read the excel document “Training.xlsx”.
Bonus Task
The application should be able to register a delegate for training

What I have tried:

C#
static void Main(string[] args)
        {
            FileInfo existingFile = new FileInfo(@"C:\Users\tshilidzi.nembilwi\Downloads\WORK STUFF\DATABASE TASK\Training.xlsx");
            //use EPPlus

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            DataTableCollection tableCollection;

            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);

            using (var stream = File.Open(existingFile.FullName, FileMode.Open, FileAccess.Read))

            {

                using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream))
                {
                    DataSet result = reader.AsDataSet(new ExcelDataSetConfiguration()
                    {
                        ConfigureDataTable = (_) => new ExcelDataTableConfiguration() { UseHeaderRow = true }
                    });

                    tableCollection = result.Tables;

                    foreach (System.Data.DataColumn table in tableCollection[0].Columns)
                    {

                        Console.WriteLine(table);
                    }


                }

            }

            DataTable dt = tableCollection[0];
            AdaptItAcaDataContext dbContext = new AdaptItAcaDataContext();

            if (dt != null)
            {

                for (int i = 0; i < dt.Rows.Count; i++)
                {

                    Delegate dl = new Delegate();
                    dl.FirstName = dt.Rows[i]["FirstName"].ToString();
                    dl.LastName = dt.Rows[i]["LastName"].ToString();
                    dl.PhoneNumber = (dt.Rows[i]["PhoneNumber"].ToString());
                    dl.Email = (dt.Rows[i]["Email"].ToString());
                    dl.CompanyName = (dt.Rows[i]["CompanyName"].ToString());
                    dl.DietaryRequirement = (dt.Rows[i]["DietaryRequirement"].ToString());
                    dbContext.Delegates.InsertOnSubmit(dl);
                    dbContext.SubmitChanges();

                    Course cs = new Course();
                    cs.CourseCode = dt.Rows[i]["Course Code"].ToString();
                    cs.CourseName = dt.Rows[i]["Course Name"].ToString();
                    cs.CourseDescription = (dt.Rows[i]["Course Description"].ToString());
                    dbContext.Courses.InsertOnSubmit(cs);
                    dbContext.SubmitChanges();


                }

            }

           

            Console.ReadKey();


        }
    }
    }
Posted
Updated 27-Jul-22 21:44pm
v3
Comments
Richard MacCutchan 28-Jul-22 4:44am    
You forgot to ask a question.
PIEBALDconsult 28-Jul-22 17:36pm    
WE don't do home work, but look into the ACE Engine.

1 solution

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900