Пример #1
0
        public static void ParseRubricContent(UploadRubricContent rubricContentData, AppDbContext context)
        {
            IEnumerable <string> content = Upload.ReadAsList(rubricContentData.Upload);
            string rubricInfo            = content.First();
            var    matchedRubric         = getRubricName(rubricInfo, context);

            content = content.Skip(1).ToList();
            foreach (string line in content)
            {
                // split csv with double quote having double quote "" in column
                var            column = Regex.Split(line, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
                RubricCriteria crit   = new RubricCriteria {
                    CriteriaText = column[0]
                };
                List <RubricCriteriaElement> elementList = new List <RubricCriteriaElement>();
                for (int i = column.Length - 1; i > 0; i--)
                {
                    if (column[i].Length == 0)
                    {
                        continue;                        // skip empty column which is ,,
                    }
                    var critElement = new RubricCriteriaElement {
                        CriteriaText = column[i], ScoreValue = 5 - i
                    };                                                                                          // someone please help with this. I dont know why my code worked
                    elementList.Add(critElement);
                }

                var existingCriteria = context.RubricCriteria.Include(criteria => criteria.RubricCriteriaElements).Where(criteria => criteria.CriteriaText.Equals(crit.CriteriaText)).FirstOrDefault();
                if (existingCriteria != null)
                {
                    existingCriteria.RubricId = matchedRubric.Id;
                    existingCriteria.RubricCriteriaElements = elementList;
                }
                else
                {
                    crit.RubricId = matchedRubric.Id;
                    crit.RubricCriteriaElements = elementList;
                    context.Add(crit);
                }

                context.SaveChanges();
            }
        }
Пример #2
0
        public string ParseUploadFileToRubrics(UploadRubricIdData rubricIdData)
        {
            IEnumerable <string> content = Upload.ReadAsList(rubricIdData.uploadFile);
            var rubrics = content.Skip(1).Where(line => line.Length > 0).Select(line => MapLineToRubric(line)).ToList();

            foreach (var rubric in rubrics)
            {
                var matchedRubric = _appDbContext.Rubrics.Find(rubric.Id);
                if (matchedRubric == null)
                {
                    _appDbContext.Add(rubric);
                }
                else
                {
                    matchedRubric.Name = rubric.Name;
                }
            }

            _appDbContext.SaveChanges();
            return(null);
        }
Пример #3
0
        //private CourseSection MapLineToCourseSection(string line)
        //{
        //    string[] column = line.Split(',');
        //    return new CourseSection { FacultyId = Convert.ToInt32(column[0]), Name = column[3], CRN = Convert.ToInt32(column[4])};
        //}


        public void ParseUploadFileToFacultyAndCourse(UploadCourseAndFacultyData facultyData)
        {
            IEnumerable <string> content = Upload.ReadAsList(facultyData.uploadFile);
            var faculties = content.Skip(1).Where(line => line.Length > 0).Select(line => MapLineToFaculty(line)).ToList();

            foreach (var faculty in faculties)
            {
                var matchedFaculty = _appDbContext.Faculty.Include(f => f.CourseSections).Where(f => f.Id == faculty.Id).FirstOrDefault();

                if (matchedFaculty != null)
                {
                    matchedFaculty.FirstName      = faculty.FirstName;
                    matchedFaculty.LastName       = faculty.LastName;
                    matchedFaculty.CourseSections = faculty.CourseSections;
                }
                else
                {
                    _appDbContext.Add(faculty);
                }
            }
            _appDbContext.SaveChanges();
        }
Пример #4
0
        public void ParseUploadFileToFaculty(UploadRubricAndFacultyData facultyData)
        {
            IEnumerable <string> content = Upload.ReadAsList(facultyData.uploadFile);

            content.Skip(1).Where(line => line.Length > 0).Select(line => MapLineToFaculty(line)).ToList();
        }