コード例 #1
0
        public JsonResult Add(ClassModel classModel)
        {
            using (var classRepository = new ClassRepository())
            {
                classRepository.Add(new ClassDTO {
                    Name = classModel.Name, Username = HttpContext.User.Identity.Name
                });
            }

            return(Json("ok"));
        }
コード例 #2
0
        public static void Import(string path, ClassRepository classRepository, LessonRepository lessonRepository, ScheduleRepository scheduleRepository, TeacherRepository teacherRepository)
        {
            List <Lesson>   lessons   = null;
            List <Teacher>  teachers  = null;
            List <Class>    classes   = null;
            List <Schedule> schedules = null;

            IWorkbook workbook = null;

            var fs = File.OpenRead(path);

            if (path.IndexOf(".xlsx") > 0) // 2007版本
            {
                workbook = new XSSFWorkbook(fs);
            }
            else if (path.IndexOf(".xls") > 0) // 2003版本
            {
                workbook = new HSSFWorkbook(fs);
            }

            var courses = GetCourses(workbook.GetSheet("科目"));

            // TODO: 导入Lesson
            lessons = GetLessons(workbook.GetSheet("课程表"));

            // TODO: 导入Class
            teachers = new List <Teacher>();
            classes  = GetClasses(workbook.GetSheet("班级"), courses, teachers);

            // TODO: 导入Schedule
            schedules = new List <Schedule>();

            lessons.ForEach(lesson =>
            {
                lessonRepository.Add(lesson);
            });

            teachers.ForEach(teacher =>
            {
                teacherRepository.Add(teacher);
            });

            classes.ForEach(@class =>
            {
                classRepository.Add(@class);
            });

            schedules.ForEach(schedule =>
            {
                scheduleRepository.Add(schedule);
            });
        }
コード例 #3
0
        public ActionResult Create(ClassModel model)
        {
            if (ModelState.IsValid)
            {
                // Map the class view model to a domain model and add it.
                var @class = Mapper.Map <Class>(model);
                _classRepository.Add(@class);
                return(RedirectToAction("List"));
            }

            PrepareClassModel(model);
            return(View(model));
        }
コード例 #4
0
 public void Add(Class entities)
 {
     sqlClassRepository.Add(entities);
 }
コード例 #5
0
        public ActionResult New(ClassVM vm)
        {
            if (vm.PosterUpload.ContentLength == 0)
            {
                ViewBag.err = "Class poster not uploaded";
                return(View(vm));
            }


            if (repo.GetByTitle(vm.Title) != null)
            {
                ViewBag.err = "A Class with the same title exits. Try a different title";
                return(View(vm));
            }


            //check file size and dimensions using a class & a static method


            if (!ModelState.IsValid)
            {
                return(View(vm));
            }


            try
            {
                //if we got here it means everything is OK!
                var cls = new Class
                {
                    Title          = vm.Title,
                    Description    = vm.Description,
                    UserId         = "1",
                    Price          = vm.Price,
                    DateCreated    = DateTime.UtcNow,
                    CategoryId     = vm.CategoryId,
                    TypeId         = vm.TypeId,
                    LevelId        = vm.LevelId,
                    Requirements   = vm.Requirements,
                    TargetStudents = vm.TargetStudents
                };



                //upload the file
                var ext  = Path.GetExtension(vm.PosterUpload.FileName);
                var guid = Guid.NewGuid();
                var file = cls.UserId + guid + ext.ToLower();
                cls.PosterSrc = "~/Assets/Uploads/ClassCoverArts/" + file;
                vm.PosterUpload.SaveAs(Path.Combine(Server.MapPath("~/Assets/Uploads/ClassCoverArts/"), file));
                repo.Add(cls);
                repo.db.SaveChanges();
                return(RedirectToAction("Edit", "Class", new { id = cls.ClassId }));
            }

            catch (Exception e)
            {
                ViewBag.err = e.Message; //+ ". Ensure that you have uploaded class image ... In production, do not expose e.Message";
                return(View(vm));
            }
        }