예제 #1
0
        public async void ImportDataFromExcel(string path, Guid courseId, string id)
        {
            var existingfile = new FileInfo(path);

            // open and read the xlsx file.
            using (var package = new ExcelPackage(existingfile))
            {
                // get the work book in the file
                var workbook = package.Workbook;
                if (workbook != null)
                {
                    // get the first worksheet
                    var currentworksheet = workbook.Worksheets.First();

                    // read some data
                    int colcount = currentworksheet.Dimension.End.Column;  //get column count
                    int rowcount = currentworksheet.Dimension.End.Row;     //get row count


                    for (var row = 2; row < rowcount - 1; row++)
                    {
                        for (var column = 2; column < colcount; column++)
                        {
                            var usercode = currentworksheet.Cells[row, 1].Value.ToString().Trim();
                            var category = currentworksheet.Cells[1, column].Value.ToString().Trim();
                            var value    = currentworksheet.Cells[row, column].Value.ToString().Trim();

                            var studPotentialUser = _repository.GetByFilter <PotentialUser>(x => x.UserCode == usercode);
                            var profPotentialUser = _repository.GetByFilter <PotentialUser>(x => x.UserCode == id);

                            var student    = _repository.GetByFilter <Student>(x => x.PotentialUserId == studPotentialUser.Id);
                            var prof       = _repository.GetByFilter <Professor>(x => x.PotentialUserId == profPotentialUser.Id);
                            var categoryId = _repository.GetByFilter <GradeCategory>(x => x.Name.ToLower() == category.ToLower()).Id;
                            var grade      = new GradeDto
                            {
                                CourseId   = courseId,
                                StudentId  = student.Id,
                                ProfId     = prof.Id,
                                CategoryId = categoryId,
                                Value      = Int32.Parse(value)
                            };

                            _gradeLogic.Add(grade);
                        }
                    }
                }
            }
        }
예제 #2
0
        public IActionResult Add([FromBody] GradeDto grade)
        {
            _gradeLogic.Add(grade);

            return(Ok(grade));
        }