コード例 #1
0
        public async Task <CoursesInformation> Update(CoursesInformation coursesInformation)
        {
            var course = _context.Attach(coursesInformation);

            course.State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(coursesInformation);
        }
コード例 #2
0
        public async Task <IActionResult> Delete(CoursesInformation coursesInformation)
        {
            try
            {
                var course = await _repository.Delete(coursesInformation.Id);

                return(Ok(course));
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #3
0
        public async Task <IActionResult> Add(CoursesInformation coursesInformation)
        {
            try
            {
                var course = await _repository.Insert(coursesInformation);

                return(Ok(course));
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #4
0
        public async Task <CoursesInformation> Insert(CoursesInformation coursesInformation)
        {
            try
            {
                var course = await _context.AddAsync(coursesInformation);

                await _context.SaveChangesAsync();

                return(coursesInformation);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #5
0
        public ActionResult CourseInfo()
        {
            List <CoursesInformation> listcourse = new List <CoursesInformation>();

            CoursesInformation information1 = new CoursesInformation();

            {
                information1.CourseID   = "ISM6155";
                information1.CourseName = "Enterprise Info Sys Management";
                information1.Location   = "BSN230";
                information1.Teacher    = "Deepak Sainanee";
                information1.Time       = "R 6:30PM-9:15PM";
            }
            listcourse.Add(information1);

            CoursesInformation information2 = new CoursesInformation();

            {
                information2.CourseID   = "ISM6218";
                information2.CourseName = "Advanced Database Management";
                information2.Location   = "BSN2300";
                information2.Teacher    = "Don Berndt";
                information2.Time       = "M 6:30PM-10:15PM";
            }
            listcourse.Add(information2);

            CoursesInformation information3 = new CoursesInformation();

            {
                information3.CourseID   = "ISM6225";
                information3.CourseName = "Distributed Information System";
                information3.Location   = "CIS2084";
                information3.Teacher    = "Clinton Daniel";
                information3.Time       = "T 6:30PM-9:15PM";
            }
            listcourse.Add(information3);

            return(View(listcourse));
        }
コード例 #6
0
        private void LoadCourses()
        {
            using (var package = new ExcelPackage(new FileInfo(courseInformationSpreadsheetLocation)))
            {
                #region Courses Sheet
                var coursesSheet = package.Workbook.Worksheets[0];

                var courses = new List <Course>();

                // This is awful, but the whole process is awful too
                int currentRow = 3;
                int semester   = 6;
                while (true)
                {
                    var code = coursesSheet.Cells[currentRow, 1].Value?.ToString();

                    if (string.IsNullOrEmpty(code))
                    {
                        break;
                    }

                    var name       = coursesSheet.Cells[currentRow, 2].Value.ToString();
                    var ects       = int.Parse(coursesSheet.Cells[currentRow, 3].Value.ToString());
                    var hours      = int.Parse(coursesSheet.Cells[currentRow, 4].Value.ToString());
                    var stringType = coursesSheet.Cells[currentRow, 5].Value.ToString();

                    var streams = new AvailableCourseStreams();
                    for (int i = 0; i < 9; i++)
                    {
                        var availability = coursesSheet.Cells[currentRow, 6 + i].Value?.ToString();
                        streams[i] = availability switch
                        {
                            "Υ" => CourseStreamAvailability.Mandatory,
                            "Ε" => CourseStreamAvailability.Optional,
                            _ => CourseStreamAvailability.None
                        };
                    }

                    var professor1 = coursesSheet.Cells[currentRow, 15].Value.ToString();

                    string professor2 = null;
                    if (!coursesSheet.Cells[currentRow, 15].Merge)
                    {
                        professor2 = coursesSheet.Cells[currentRow, 16].Value.ToString();
                    }

                    var type = stringType switch
                    {
                        "ΥΚΕ" => CourseType.MandatoryInCourseStream,
                        "ΓΕ" => CourseType.Mandatory,
                        "Ε" => CourseType.Optional,
                    };

                    var course = new Course(code, name, ects, hours, type, semester, streams, professor1, professor2);
                    courses.Add(course);

                    if (coursesSheet.Cells[currentRow, 1].Style.Border.Bottom.Style != ExcelBorderStyle.None)
                    {
                        semester++;
                    }

                    currentRow++;
                }
                #endregion

                #region Course Streams Sheet
                var courseStreamsSheet = package.Workbook.Worksheets[1];

                var courseStreams = new Dictionary <string, string>(9);
                for (int i = 0; i < 9; i++)
                {
                    var streamIndex = courseStreamsSheet.Cells[2, 2 + i * 2].Value.ToString();
                    var streamTitle = courseStreamsSheet.Cells[2, 3 + i * 2].Value.ToString();

                    courseStreams.Add(streamIndex, streamTitle);
                }
                #endregion

                CoursesInformation = new CoursesInformation(courses, courseStreams);
            }
        }