Example #1
0
        public static void Main()
        {
            using (var connection = new SqliteConnection("DataSource=:memory:"))
            {
                connection.Open();

                var context = StudentDbContext.Create(connection);

                var classes = new ClassRepository(context);
                classes.Create(new Class {
                    Id = 1, Name = "Math"
                });
                classes.Create(new Class {
                    Id = 2, Name = "History"
                });

                var students = new StudentRepository(context);

                var math    = classes.Get(1);
                var history = classes.Get(2);

                var jim = new Student
                {
                    Id      = 1,
                    Name    = "Jim Doe",
                    Classes = new List <Class> {
                        math, history
                    }
                };
                students.Create(jim);

                var nextOfKins = students.Get(1);
                nextOfKins.NextOfKins =
                    new List <NextOfKin> {
                    NextOfKin.Create("John Doe"), NextOfKin.Create("Jane Doe")
                };
                students.Update(nextOfKins);

                var residence = students.Get(1);
                nextOfKins.Hometown = City.Create("Oslo");
                students.Update(nextOfKins);

                new StudentReport(connection, 1).Write();
                new ClassesReport(connection).Write();

                Console.Out.WriteLine("Classes: " + context.Classes.Count());
                Console.Out.WriteLine("Students: " + context.Students.Count());
            }
        }
Example #2
0
        public async Task <ActionResult> Create(ClassViewModel viewModel)
        {
            var courseRepository = new CourseRepository(_context);
            var userRepository   = new UserRepository(_context);

            if (ModelState.IsValid)
            {
                try
                {
                    var course          = courseRepository.GetById(viewModel.CourseId);
                    var teacher         = (Teacher)userRepository.GetById(viewModel.TeacherId);
                    var classRepository = new ClassRepository(_context);
                    classRepository.Create(ClassViewModel.ToEntity(viewModel, course, teacher));

                    var affectedClassrooms = ResumeConcludedDeliveryPlans(course);
                    await SyncAccessesAsync(affectedClassrooms);

                    _context.Save(_loggedUser);
                    TempData["MessageType"]  = "success";
                    TempData["MessageTitle"] = Resource.ContentManagementToastrTitle;
                    TempData["Message"]      = Resource.ClassCreatedToastrMessage;
                    return(Redirect(TempData["BackURL"].ToString()));
                }
                catch (Exception ex)
                {
                    TempData["MessageType"]  = "error";
                    TempData["MessageTitle"] = Resource.ContentManagementToastrTitle;
                    TempData["Message"]      = ex.Message;
                }
            }

            const ContentType classType = ContentType.Vimeo;

            ViewBag.ContentTypes = new SelectList(classType.ToDataSource <ContentType>(), "Key", "Value");

            var activeCourses = courseRepository.ListActiveCourses();

            ViewBag.Courses = new SelectList(activeCourses, "Id", "Name");
            var activeTeachers = userRepository.ListActiveTeachers();

            ViewBag.Teachers = new SelectList(activeTeachers, "Id", "Name");

            return(View(viewModel));
        }
Example #3
0
        [HttpPost] /*POSTMAN OK*/
        public IActionResult Create([FromBody] Class studentClass)
        {
            switch (_classRepo.Create(studentClass.ApiToDal()))
            {
            case DBErrors.Success:
                return(Ok());

            case DBErrors.Name_Exist:
                return(Problem("This name already exist.", statusCode: (int)HttpStatusCode.BadRequest));

            case DBErrors.YearCategoryId_NotFound:
                return(Problem("A valid CategoryId is needed.", statusCode: (int)HttpStatusCode.NotFound));

            case DBErrors.NullExeption:
                return(Problem("A mandatory field does not support 'null' value or is missing", statusCode: (int)HttpStatusCode.BadRequest));

            default:
                return(Problem("?", statusCode: (int)HttpStatusCode.NotFound));
            }
        }