예제 #1
0
        // Menu Strip ---------------------------------------------------------------------

        // # Adding items from menu

        // ## Add course from menu

        /// <summary>
        /// The classToolStripMenuItem method is used to instantiate the CourseAdd
        /// Form and handle some other functionality.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void classToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //suspend current window, load new course add window
            this.SuspendLayout();
            CourseAdd newClass = new CourseAdd(ref courseList);

            newClass.ShowDialog();

            //check if action was canceled ie.is getCourse null?
            if (newClass.NewCourse == null)
            {
                return;
            }

            //Add course from course add form to object
            Course newCourse = newClass.NewCourse;

            //add new course object to course list
            courseList.Add(newCourse);

            //update viewer
            updateCourseViewer();

            //update prefixes
            updatePrefixes();
        }
예제 #2
0
        // Add new item
        public Course AddCourse(CourseAdd Course)
        {
            // Map from DTO object to domain (POCO) object
            var p = ds.Courses.Add(Mapper.Map <ICTGWS.Models.Course>(Course));

            ds.SaveChanges();
            // Map to DTO object
            return(Mapper.Map <Course>(p));
        }
예제 #3
0
        /// <summary>
        /// This function is triggered while adding course button is clicked.
        /// </summary>
        /// <param name="a_sender">It holds the sender.</param>
        /// <param name="a_event">It holds the event.</param>
        private void AddCourse_Click(object a_sender, EventArgs a_event)
        {
            // Open the new form to get the info of the course.
            // The info would be the courseID.
            CourseAdd courseAdd = new CourseAdd(m_parentProfile.m_userEmail);

            courseAdd.ShowDialog();

            ExecuteGetRequest();
        }
예제 #4
0
        public IActionResult Delete(string id)
        {
            CourseAdd courseAdd = new CourseAdd();
            Course    course    = _courseData.Find(id);

            courseAdd.CourseID     = course.ID;
            courseAdd.Name         = course.Name;
            courseAdd.ActivityType = course.ActivityTypes.ToList();
            courseAdd.ESPB         = course.ESPB;
            return(View(courseAdd));
        }
예제 #5
0
        public ActionResult Create(CourseAdd model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateCourseService();

            service.AddCourse(model);
            return(RedirectToAction("Index"));
        }
예제 #6
0
        public IActionResult AddPost(CourseAdd courseAdd)
        {
            Course course = new Course();

            course.Name = courseAdd.Name;
            course.ID   = courseAdd.CourseID;
            course.ESPB = courseAdd.ESPB;
            JArray typesArray = JArray.Parse(courseAdd.JsonString);

            course.ActivityTypes = typesArray.ToObject <List <ActivityType> >();
            _courseData.Add(course);
            return(RedirectToAction("Courses", "Course"));
        }
예제 #7
0
        public IActionResult Update(string id)
        {
            CourseAdd courseAdd = new CourseAdd();
            Course    course    = _courseData.Find(id);

            courseAdd.CourseID     = course.ID;
            courseAdd.Name         = course.Name;
            courseAdd.ActivityType = course.ActivityTypes.ToList();
            courseAdd.ESPB         = course.ESPB;
            ////////////////////////////////////////why is this here
            foreach (ActivityType activityType in courseAdd.ActivityType)
            {
                activityType.Course = null;
            }
            return(View(courseAdd));
        }
예제 #8
0
        public IActionResult UpdatePost(CourseAdd courseAdd)
        {
            Course course = new Course();

            course.Name = courseAdd.Name;
            course.ID   = courseAdd.CourseID;
            course.ESPB = courseAdd.ESPB;
            JArray typesArray = JArray.Parse(courseAdd.JsonString);

            course.ActivityTypes = typesArray.ToObject <List <ActivityType> >();
            foreach (ActivityType type in course.ActivityTypes)
            {
                type.CourseID = course.ID;
                type.Course   = course;
            }
            _courseData.Update(course);
            return(RedirectToAction("Courses", "Course"));
        }
예제 #9
0
        public bool AddCourse(CourseAdd model)
        {
            var entity =
                new Course()
            {
                OwnerID          = _userId,
                CourseName       = model.CourseName,
                CourseAddress    = model.CourseAddress,
                NineHoleCost     = model.NineHoleCost,
                EighteenHoleCost = model.EighteenHoleCost,
                AlcoholFriendly  = model.AlcoholFriendly,
                BeginnerFriendly = model.BeginnerFriendly
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Courses.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #10
0
        /// <summary>
        /// This function is triggered when enrolling in a course.
        /// </summary>
        /// <param name="a_sender">It holds the sender.</param>
        /// <param name="a_event">It holds the event.</param>
        private void EnrollCourseTile_Click(object a_sender, EventArgs a_event)
        {
            CourseAdd addCourse = new CourseAdd(m_parent.m_userEmail);

            addCourse.ShowDialog();
        }
예제 #11
0
        protected override void Seed(ApplicationDbContext context)
        {
            if (context.Programs.Count() == 0)
            {
                // File system path to the data file (in this project's App_Data folder)
                string path = HttpContext.Current.Server.MapPath("~/App_Data/ict-programs.csv");

                // Create a stream reader object, to read from the file system
                StreamReader sr = File.OpenText(path);

                // Create the CsvHelper object
                var csv = new CsvReader(sr);

                // Process the file contents in a loop

                while (csv.Read())
                {
                    ProgramAdd addProgram = csv.GetRecord <ProgramAdd>();
                    context.Programs.Add(Mapper.Map <Program>(addProgram));
                }

                // Clean up
                sr.Close();
                sr = null;

                // Deliver or otherwise process the results
                context.SaveChanges();
            }

            if (context.Courses.Count() == 0)
            {
                // File system path to the data file (in this project's App_Data folder)
                string path = HttpContext.Current.Server.MapPath("~/App_Data/ict-courses-bsd.csv");

                // Create a stream reader object, to read from the file system
                StreamReader sr = File.OpenText(path);

                // Create the CsvHelper object
                var csv = new CsvReader(sr);

                // Process the file contents in a loop

                while (csv.Read())
                {
                    CourseAdd addCourse = csv.GetRecord <CourseAdd>();
                    context.Courses.Add(Mapper.Map <Course>(addCourse));
                }

                // Clean up
                sr.Close();
                sr = null;

                // Deliver or otherwise process the results
                context.SaveChanges();
            }

            /*
             * var bsd = new Program();
             * bsd.Code = "BSD";
             * bsd.Name = "Bachelor of Software Development";
             * bsd.Description = "Welcome to Bachelor of Software Development...";
             * bsd.Credential = "Bachelor degree";
             * context.Programs.Add(bsd);
             * context.SaveChanges();
             *
             * var cpa = new Program();
             * cpa.Code = "CPA";
             * cpa.Name = "Computer Programmer Analyst";
             * cpa.Description = "Welcome to Computer Programmer Analyst...";
             * cpa.Credential = "Advanced Diploma";
             * context.Programs.Add(cpa);
             * context.SaveChanges();
             *
             * var cpp = new Course();
             * cpp.Code = "cpp";
             * cpp.Name = "C++";
             * cpp.Description = "Intro to C++";
             * context.Courses.Add(cpp);
             * context.SaveChanges();
             *
             * var oop = new Course();
             * oop.Code = "oop";
             * oop.Name = "Object Oriented Programming";
             * oop.Description = "Programming with Objects";
             * context.Courses.Add(oop);
             * context.SaveChanges();
             *
             * var btc = new Course();
             * btc.Code = "btc";
             * btc.Name = "Communication";
             * btc.Description = "Written and verbal communicaiton course";
             * context.Courses.Add(btc);
             * context.SaveChanges();
             */
        }
예제 #12
0
        public IActionResult Add()
        {
            CourseAdd course = new CourseAdd();

            return(View(course));
        }