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

Using C#, please help with fixing/resolving the namespace issues in this code an

ID: 3886841 • Letter: U

Question

Using C#, please help with fixing/resolving the namespace issues in this code and ensure that the CRUD views are correct. Also ensure that any directive or assembly references are in place.

using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using ExamsAndAverages.Models;

namespace ExamsAndAverages.Controllers
                          
{
    public class ExamsAndAverages
    {
        static int uniqueID = 1;
        static List testEntryList = new List();

        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to Exams and Averages:";

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "About Exams and Averages:";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult List()
        {
            ViewBag.Message = "The List of the Exams:";
            return View(testEntryList);
        }

        public ActionResult Details(int id)
        {
            ViewBag.Message = "Details of this Exam:";
            
            TestEntry entry = null;
            foreach (TestEntry e in testEntryList)
            {
                if (id == e.ID)
                {
                    entry = e;
                    break;
                }
            }
            return View(entry);
        }

        public ActionResult Create()
        {
            ViewBag.Message = "Fill in the Exam's Name:";

            return View();
        }

        [HttpPost]
        public ActionResult Create(TestEntry entry)
        {
            if (!ModelState.IsValid)
            {
                return View("Create", entry);
            }
            testEntryList.Add(new TestEntry(entry.Name, ++uniqueID));
            return RedirectToAction("List");
        }


        public ActionResult Edit(int ID)
        {
            ViewBag.Message = "Add New Score:";

            TestEntry theEntry = null;

            foreach (TestEntry e in testEntryList)
            {
                if (e.ID == ID)
                {
                    theEntry = new TestEntry(e.Name, ID);
                    break;
                }
            }
            if (theEntry == null)
                return RedirectToAction("Error");
            else
            {
                ViewBag.Message = "Add New " + theEntry.Name + " Score:";
                return View(theEntry);
            }
        }

        [HttpPost]
        public ActionResult Edit(TestEntry entry)
        {
            Contract.Ensures(Contract.Result() != null);
            if (!ModelState.IsValid)
            {
                ViewBag.Message = "There was an editing error:";
                return View("Edit", entry);
            }
            foreach (TestEntry e in testEntryList)
            {
                if (e.ID == entry.ID)
                {
                    e.Sum += entry.Sum;
                    e.Amount++;
                    break;
                }
            }
            return RedirectToAction("List");
        }

        public ActionResult Delete(int ID)
        {
            TestEntry theEntry = null;

            ViewBag.Message = "Delete the following Exam:";
            foreach (TestEntry e in testEntryList)
            {
                if (e.ID == ID)
                {
                    theEntry = e;
                    break;
                }
            }
            if (theEntry == null)
                return RedirectToAction("Error");
            else
                return View(theEntry);
        }

        [HttpPost]
        public ActionResult Delete(TestEntry entry)
        {
            if (entry == null)
                return RedirectToAction("Error");

            foreach (TestEntry e in testEntryList)
            {
                if (e.ID == entry.ID)
                {
                    testEntryList.Remove(e);
                    break;
                }
            }
            return RedirectToAction("List");
        }

        [HttpPost]
        public ExamsAndAverages Index(string button, string newname, string score, string testNameItems)
        {
            ViewBag.Message = "Exams and Averages:";

            if (button == "Add Exam" && newname != "")
            {
                testNameList.Add(newname);
                testEntryList.Add(new TestEntry(newname));
            }

            if (button == "Add Score" && score != "" && testNameItems != "")
                for (int i = 0; i < testEntryList.Count; ++i)
                {
                    if (testEntryList[i].Name == testNameItems)
                    {
                        testEntryList[i].Amount++;
                        testEntryList[i].Sum += Convert.ToDouble(score);
                    }
                }

            ViewBag.TestNameItems = new SelectList(testNameList);
            ViewBag.TestInfoItems = new SelectList(testEntryList);

            ViewBag.TestListSize = (testNameList.Count == 0) ? 1 : testNameList.Count;

            ModelState.Clear();
            return View();
        }
    }
}

Explanation / Answer

HomeController.cs

=======================================================================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote