Exemple #1
0
        public void Get()
        {
            // Arrange
            StudentsRepository repository = new StudentsRepository(new StudentsEntities());

            // Act
            IEnumerable<Student> result = repository.All();

            // Assert
            Student expectedStudent = new Student()
            {
                firstName = "pesho",
                lastName = "peshev",
                age = 20,
                grade = 5
            };

            var resultStudentAtOne = result.ElementAt(1);

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual(expectedStudent.firstName, resultStudentAtOne.firstName);
            Assert.AreEqual(expectedStudent.firstName, resultStudentAtOne.firstName);
            Assert.AreEqual(expectedStudent.lastName, resultStudentAtOne.lastName);
            Assert.AreEqual(expectedStudent.age, resultStudentAtOne.age);
            Assert.AreEqual(expectedStudent.grade, resultStudentAtOne.grade);
        }
        public StudentsController()
        {
            var coursesContext = new CoursesContext();
            var coursesUnitOfWork = new CoursesUnitOfWork(coursesContext);
            var studentsRespository = new StudentsRepository(coursesUnitOfWork);

            this._studentsAppService = new StudentsAppService(studentsRespository);
        }
Exemple #3
0
 protected Command(string input, string[] data, Tester judge, StudentsRepository repository, DownloadManager downloadManager, IOManager inputOutputManager)
 {
     this.Input = input;
     this.Data = data;
     this.judge = judge;
     this.repository = repository;
     this.downloadManager = downloadManager;
     this.inputOutputManager = inputOutputManager;
 }
Exemple #4
0
        public ActionResult SaveStudent(StudentsViewModel data)
        {
            try
            {
                StudentsRepository.AddStudent(data.StudentToAdd, this.CurrentUser.Class_id);
                TempData["userAdded"] = "1";
            }
            catch (Exception ex)
            {
                TempData["userAdded"] = "0";
                //log to the databse
            }

            return(RedirectToAction("Show"));
        }
        public void Run()
        {
            List <Student> students = StudentsRepository.ChooseTypeOfGettingStudents();

            List <Student> selectedStudents = students
                                              .Where(student => GetAge(student) < 16)
                                              .ToList();

            Console.WriteLine($"Number of students younger than 16: {selectedStudents.Count}\n");

            foreach (var student in selectedStudents)
            {
                PrintData(student);
            }
        }
        public static async Task <IActionResult> OnGetStudentAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "students/{studentId:guid}")] HttpRequest req
            , string studentId
            , ILogger log
            , CancellationToken ct)
        {
            log.LogInformation($"Request for student with ID {studentId} is being handled.");

            IStudentsRepository repository = new StudentsRepository();
            var student = await repository.GetByIdAsync(Guid.Parse(studentId), ct);

            return((null == student) ?
                   (IActionResult) new NotFoundObjectResult($"Student ({studentId}) not found.") :
                   new OkObjectResult(student));
        }
        public void Update_StudentNotFound_Fail()
        {
            // Arrange
            var id = StudentsRepository.NotFoundEntity();

            // Act
            var result = _service.Update(new StudentDetails
            {
                Id = id,
            });

            // Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Succeed, Is.False);
        }
        public bool IsDuplicateStudentId(string studentId)
        {
            IStudentsRepository studentsRepository = new StudentsRepository();

            if (EditMode && OrigStudentId.ToUpper().Trim().Equals(studentId.ToUpper().Trim()))
            {
                return(true);
            }

            if (studentsRepository.GetStudent(studentId) != null)
            {
                return(false);
            }

            return(true);
        }
Exemple #9
0
 static Unit()
 {
     _context = new MyAppDbContext("MyAppConnStr");
     DepartmentsRepository  = new DepartmentsRepository(_context);
     TeachersRepository     = new TeachersRepository(_context);
     SubjectsRepository     = new SubjectsRepository(_context);
     SpecialitiesRepository = new SpecialitiesRepository(_context);
     GroupsRepository       = new GroupsRepository(_context);
     PhonesRepository       = new PhonesRepository(_context);
     StudentsRepository     = new StudentsRepository(_context);
     AudiencesRepository    = new AudiencesRepository(_context);
     AudLectRepository      = new AudLectRepository(_context);
     LectionsRepository     = new LectionsRepository(_context);
     MarksRepository        = new MarksRepository(_context);
     TeachSubjRepository    = new TeachSubjRepository(_context);
 }
        public async Task <ActionResult <List <Student> > > GetAllStudents()
        {
            using (var connection = new SqlConnection(Configuration.GetConnectionString("DefaultConnection")))
            {
                try
                {
                    connection.Open();

                    return(await StudentsRepository.GetAllStudentsAsync(connection));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
        }
Exemple #11
0
        public CreateEditLoan(Loan loanToEdit)
        {
            InitializeComponent();

            var context = new LibraryContext();

            _loansRepository    = new LoansRepository(context);
            _studentsRepository = new StudentsRepository(context);
            _booksRepository    = new BooksRepository(context);
            _loanToEdit         = loanToEdit;

            createButton.Text = @"Edit";
            RefreshStudentsAndBooksList();
            FillInputFields();
            SearchAutoComplete();
        }
        private dynamic Enrol_BothFound()
        {
            // Arrange
            var course  = CoursesRepository.FoundEntity();
            var student = StudentsRepository.FoundEntity();

            // Act
            var result = _service.Enrol(student.Id, course.Id);

            return(new
            {
                Result = result,
                Course = course,
                Student = student
            });
        }
Exemple #13
0
        public void AddUser(Users entityToAdd)
        {
            IUsersRepository repo = new UsersRepository(getEntities());

            Entities.Users entityToAdd2 = Mapper.Map <Users, Entities.Users>(entityToAdd);
            repo.Add(entityToAdd2);
            switch (entityToAdd.UserType.ToUpper())
            {
            case "ADMINISTRATOR":
                IAdministratorsRepository adminRepo = new AdministratorsRepository(getEntities());
                Entities.Administrators   admin     = new Entities.Administrators()
                {
                    UserId = entityToAdd.Id
                };
                adminRepo.Add(admin);
                break;

            case "MANAGER":
                IManagersRepository managerRepo = new ManagersRepository(getEntities());
                Entities.Managers   manager     = new Entities.Managers()
                {
                    UserId = entityToAdd.Id
                };
                managerRepo.Add(manager);
                break;

            case "STUDENT":
                IStudentsRepository studentRepo = new StudentsRepository(getEntities());
                Entities.Students   student     = new Entities.Students()
                {
                    UserId = entityToAdd.Id
                };
                studentRepo.Add(student);
                break;

            case "TEACHER":
                ITeachersRepository teacherRepo = new TeachersRepository(getEntities());
                Entities.Teachers   teacher     = new Entities.Teachers()
                {
                    UserId = entityToAdd.Id
                };
                teacherRepo.Add(teacher);
                break;

            default:; break;
            }
        }
Exemple #14
0
        public PartialViewResult StudentDetails(string id)
        {
            var student   = StudentsRepository.GetStudent(id);
            var subjects  = ScheduleRepository.GetAllSchedule(student.Class_id);
            var schedule1 = ScheduleRepository.GetSchedule(1, student.Class_id);
            var schedule2 = ScheduleRepository.GetSchedule(2, student.Class_id);

            IndexViewModel vm = new IndexViewModel()
            {
                CurrentStudent = student,
                Subjects       = subjects,
                Schedule1      = schedule1,
                Schedule2      = schedule2
            };

            return(PartialView("_StudentDetails", vm));
        }
Exemple #15
0
 private static void TryShowWantedData(string input, string[] data)
 {
     if (data.Length == 2)
     {
         string courseName = data[1];
         StudentsRepository.GetAllStudentsFromCourse(courseName);
     }
     else if (data.Length == 3)
     {
         string courseName = data[1];
         string userName   = data[2];
         StudentsRepository.GetStudentScoresFromCourse(courseName, userName);
     }
     else
     {
         DisplayInvalidCommandMessage(input);
     }
 }
Exemple #16
0
 static Unit()
 {
     _context                  = new MyAppDbContext("MyAppConnStr");
     AddressesRepository       = new AddressesRepository(_context);
     ClassroomsRepository      = new ClassroomsRepository(_context);
     DepartmentsRepository     = new DepartmentsRepository(_context);
     GroupsRepository          = new GroupsRepository(_context);
     GroupTimetablesRepository = new GroupTimetablesRepository(_context);
     MarksRepository           = new MarksRepository(_context);
     PairTimetablesRepository  = new PairTimetablesRepository(_context);
     PhonesRepository          = new PhonesRepository(_context);
     SpecialitiesRepository    = new SpecialitiesRepository(_context);
     StudentsRepository        = new StudentsRepository(_context);
     SubjectsRepository        = new SubjectsRepository(_context);
     TeachSubjsRepository      = new TeachSubjsRepository(_context);
     TeachersRepository        = new TeachersRepository(_context);
     TimetablesRepository      = new TimetablesRepository(_context);
 }
        private dynamic RemoveStudentFromCourse_CourseFoundAndStudentInCourse()
        {
            // Arrange
            var course  = CoursesRepository.FoundEntity();
            var student = StudentsRepository.FoundEntity();

            course.AddStudent(student);

            // Act
            var result = _service.RemoveStudentFromCourse(student.Id, course.Id);

            return(new
            {
                Result = result,
                Course = course,
                Student = student
            });
        }
Exemple #18
0
 private static void TryShowWantedData(string input, string[] data)
 {
     if (data.Length == 2)
     {
         string courseName = data[1];
         StudentsRepository.GetAllStudentsFromCourse(courseName);
     }
     else if (data.Length == 3)
     {
         string courseName  = data[1];
         string studentName = data[2];
         StudentsRepository.GetStudentScoresFromCourse(courseName, studentName);
     }
     else
     {
         OutputWriter.DisplayExeptions(ExceptionMessages.InvalidCommandMessage(input));
     }
 }
Exemple #19
0
        public string SendEmail(int id)
        {
            var     repo   = new StudentsRepository(_connectionString);
            Student s      = repo.GetStudentById(id);
            var     result = repo.SendEmail(s.Email);

            if (result == "Mail has been successfully sent!")
            {
                CallOrEmail c = new CallOrEmail
                {
                    StudentId = id,
                    Type      = CallOrEmailType.Email,
                    Date      = DateTime.Now,
                    Notes     = "sent automatic email"
                };
                repo.AddCallOrEmail(c);
            }
            return(result);
        }
        public ScheduleRepository(string connectionString)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<ScheduleContext, Configuration>());

            Auditoriums = new AuditoriumsRepository();
            Buildings = new BuildingsRepository();
            Calendars = new CalendarsRepository();
            Disciplines = new DisciplinesRepository();
            DisciplineNames = new DisciplineNameRepository();
            Lessons = new LessonsRepository(this);
            Rings = new RingsRepository();
            Students = new StudentsRepository();
            StudentGroups = new StudentGroupsRepository();
            StudentsInGroups = new StudentsInGroupsRepository();
            Teachers = new TeachersRepository();
            TeacherForDisciplines = new TeacherForDisciplinesRepository();
            ConfigOptions = new ConfigOptionRepository();

            AuditoriumEvents = new AuditoriumEventsRepository();

            Faculties = new FacultiesRepository();
            GroupsInFaculties = new GroupsInFacultiesRepository();

            ScheduleNotes = new ScheduleNotesRepository();

            LessonLogEvents = new LessonLogEventsRepository();

            TeacherWishes = new TeacherWishesRepository();

            CustomTeacherAttributes = new CustomTeacherAttributesRepository();
            CustomDisciplineAttributes = new CustomDisciplineAttributesRepository();
            CustomStudentGroupAttributes = new CustomStudentGroupAttributesRepository();

            Shifts = new ShiftsRepository();
            ShiftRings = new ShiftRingsRepository();

            Exams = new ExamsRepository();
            LogEvents = new LogEventsRepository();

            CommonFunctions = new CommonFunctions(this);

            SetConnectionString(connectionString);
        }
        public void DeleteItemTest()
        {
            var repo = new StudentsRepository(_context);
            var item = new Student
            {
                FirstName     = "Kurt",
                MiddleName    = "Unknown",
                LastName      = "Wallander",
                Address       = "Ystad",
                Birthday      = new DateTime(1961, 05, 23),
                Email         = "*****@*****.**",
                LogbookNumber = 4366,
                Group         = _context.Groups.FirstOrDefault()
            };
            int Id = _context.Students.FirstOrDefault(x => x.LogbookNumber == item.LogbookNumber).Id;

            Assert.AreEqual(item.LogbookNumber, repo.GetItem(Id).LogbookNumber);
            repo.DeleteItem(Id);
            var deleted = repo.GetItem(Id).LogbookNumber;
        }
Exemple #22
0
        public async Task Handle_should_create_entity()
        {
            await using var dbContext = _fixture.BuildDbContext();

            var studentsRepo       = new StudentsRepository(dbContext);
            var coursesRepo        = new CoursesRepository(dbContext);
            var messagesRepository = NSubstitute.Substitute.For <IMessagesRepository>();
            var eventSerializer    = NSubstitute.Substitute.For <IEventSerializer>();

            var unitOfWork = new SchoolUnitOfWork(dbContext, coursesRepo, studentsRepo, messagesRepository, eventSerializer);

            var sut = new CreateCourseHandler(new FakeValidator <CreateCourse>(), unitOfWork);

            var command = new CreateCourse(Guid.NewGuid(), "new course");
            await sut.Handle(command, CancellationToken.None);

            var createdCourse = await coursesRepo.FindByIdAsync(command.CourseId, CancellationToken.None);

            createdCourse.Should().NotBeNull();
            createdCourse.Id.Should().Be(command.CourseId);
            createdCourse.Title.Should().Be(command.CourseTitle);
        }
        public static PromotionSituationVM GetPromotionStatistics(List <PromotionSituationTableAux> auxTable, PromotionSituation promotionSituation)
        {
            StudentsRepository studentsRepo = new StudentsRepository();

            var finalsituation = new PromotionSituationVM();

            var promotionsTable = GetPromotionTable(auxTable);

            finalsituation.PromotionSituationTable = promotionsTable.OrderByDescending(p => p.StudentName).ToList();

            finalsituation.PromotionAverage = studentsRepo.GetPromotionAverage(auxTable).ToString("F2");

            finalsituation.HighestAverage = studentsRepo.GetHighestAverage(auxTable).ToString("F2");

            finalsituation.Scholarships = studentsRepo.GetScholarships(auxTable);

            finalsituation.Specialization = (Specialization)promotionSituation.Specialization;

            finalsituation.YearOfStudy = (YearOfStudy)promotionSituation.YearOfStudy;

            return(finalsituation);
        }
Exemple #24
0
 private static void TryParseParametersForOrderAndTake(string takeCommand, string takeQuantiy, string courseName, string order)
 {
     if (takeCommand == "take")
     {
         if (takeQuantiy == "all")
         {
             StudentsRepository.OrderAndTake(courseName, order);
         }
         else
         {
             int  studetsToTake;
             bool isParsed = int.TryParse(takeQuantiy, out studetsToTake);
             if (isParsed)
             {
                 StudentsRepository.OrderAndTake(courseName, order, studetsToTake);
             }
             else
             {
                 OutputWriter.DisplayExeptions(ExceptionMessages.InvalidTakeQuantityParameter);
             }
         }
     }
 }
Exemple #25
0
        public void GetById()
        {
            // Arrange
            StudentsEntities context = new StudentsEntities();
            var repository = new StudentsRepository(context);

            // Act
            Student result = repository.Get(3);

            // Assert
            Student expectedStudent = new Student()
            {
                firstName = "pesho",
                lastName = "peshev",
                age = 20,
                grade = 5
            };

            Assert.AreEqual(expectedStudent.firstName, result.firstName);
            Assert.AreEqual(expectedStudent.lastName, result.lastName);
            Assert.AreEqual(expectedStudent.age, result.age);
            Assert.AreEqual(expectedStudent.grade, result.grade);
        }
        public async Task <IActionResult> DeleteAllStudents()
        {
            using (var connection = new SqlConnection(Configuration.GetConnectionString("DefaultConnection")))
            {
                try
                {
                    connection.Open();

                    var numberOfAffectedRows = await StudentsRepository.DeleteAllStudentsAsync(connection);

                    if (numberOfAffectedRows == 0)
                    {
                        return(NotFound("There aren't any students in database"));
                    }
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }

            return(NoContent());
        }
        private static void TryParseParametersForOrderAndTake(string takeCommand, string takeQuantity, string coursename, string comparison)
        {
            if (takeCommand == "take")
            {
                if (takeQuantity == "all")
                {
                    StudentsRepository.OrderAndTake(coursename, comparison);
                }
                else
                {
                    int  studentsToTake;
                    bool hasParsed = Int32.TryParse(takeQuantity, out studentsToTake);

                    if (hasParsed)
                    {
                        StudentsRepository.OrderAndTake(coursename, comparison, studentsToTake);
                    }
                    else
                    {
                        OutputWriter.DisplayException(ExceptionMessages.InvalidTakeQuantityParameter);
                    }
                }
            }
        }
Exemple #28
0
 public DropDatabaseCommand(string input, string[] data, Tester judge, StudentsRepository repo, IOManager ioManager) : base(input, data, judge, repo, ioManager)
 {
 }
Exemple #29
0
 public ReadDatabaseCommand(string input, string[] data, Tester judge, StudentsRepository repository,
                            DownloadManager downloadManager, IOManager ioManager)
     : base(input, data, judge, repository, downloadManager, ioManager)
 {
 }
 public CompareFilesCommand(string input, string[] data, Tester judge, StudentsRepository repository, IOManager inputOutputManager)
     : base(input, data, judge, repository, inputOutputManager)
 {
 }
Exemple #31
0
        // GET: api/Students
        public IEnumerable <Student> Get()
        {
            var studentsRepository = new StudentsRepository();

            return(studentsRepository.Retrieve());
        }
 public PrintFilteredStudentsCommand(string input, string[] data, Tester judge, StudentsRepository repository, DownloadManager downloadManager, IOManager inputOutputManager)
     : base(input, data, judge, repository, downloadManager, inputOutputManager)
 {
 }
Exemple #33
0
        public void Post()
        {
            // Arrange
            var repository = new StudentsRepository(new StudentsEntities());

            // Act
            Student newStudent = new Student()
            {
                firstName = "kiro",
                lastName = "ivanov",
                age = 20,
                grade = 7
            };

            repository.Add(newStudent);

            // Assert
            var count = repository.All().Count();
            Assert.AreEqual(3, count);
        }
 public StudentController(IStudentSystemDbContext context)
 {
     this.context = context;
     this.repository = new StudentsRepository(this.context);
 }
 public ChangeAbsolutePathCommand(string input, string[] data, Tester judge, StudentsRepository repository, DownloadManager downloadManager, IOManager inputOutputManager)
     : base(input, data, judge, repository, downloadManager, inputOutputManager)
 {
 }
 public StudentController()
 {
     this.repository = new StudentsRepository(new StudentSystemDbContext());
 }
Exemple #37
0
        public void Delete()
        {
            // Arrange
            var repository = new StudentsRepository(new StudentsEntities());

            // Act
            repository.Delete(2);

            // Assert
            var count = repository.All().Count();
            Assert.AreEqual(1, count);
        }
 public ChangeAbsolutePathCommand(string input, string[] data, Tester tester,
                                  StudentsRepository repository, DownloadManager downloadManager, IOManager ioManager)
     : base(input, data, tester, repository, downloadManager, ioManager)
 {
 }
 public DropDatabaseCommand(string input, string[] data, Tester judje, StudentsRepository studentsRepository, IOManager iOManager) : base(input, data, judje, studentsRepository, iOManager)
 {
 }
Exemple #40
0
 public StudentsController()
 {
     dbContext = new StudentsEntities();
     this.repository = new StudentsRepository(dbContext);
 }
 public PrintOrderedStudentsCommand(string input, string[] data, Tester judge, StudentsRepository repository, IOManager inputOutputManager) : base(input, data, judge, repository, inputOutputManager)
 {
 }
    private static void LinqExtensionMethodsExamples()
    {
        var studentsRepository = new StudentsRepository();
        var students = studentsRepository.GetAllStudents();

        // where
        var someStudents = students.Where(st => st.Name == "Ivan" || st.Name == "Pesho");
        PrintCollection(someStudents);

        // first
        Student first = students.FirstOrDefault(st => st.Courses.Count == 4); // First
        Console.WriteLine(first);

        // select
        var projectedItems = students.Select(
            st => new Student { Name = st.Id.ToString(), Courses = new List<Course>() });
        PrintCollection(projectedItems);

        // select to annonymous
        var annStudents = students.Select(st => new { Id = st.Id, Courses = st.Courses.Count });
        PrintCollection(annStudents);

        // order by
        var ordered = students.OrderBy(st => st.Courses.Count).ThenBy(st => st.Name);
        PrintCollection(ordered);

        // any
        bool checkAny = students.Any(st => st.Name.StartsWith("I"));
        Console.WriteLine(checkAny);

        // all
        bool checkAll = students.All(st => st.Name != string.Empty);
        Console.WriteLine(checkAll);
        checkAll = students.All(st => st.Id > 2);
        Console.WriteLine(checkAll);

        // ToList and ToArray
        Student[] arrayOfStudents = students.ToArray();
        PrintCollection(arrayOfStudents);
        List<Student> listOfStudents = arrayOfStudents.ToList();
        PrintCollection(listOfStudents);

        // reading string of numbers separated by space
        int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        PrintCollection(numbers);

        // reverse
        students.Reverse();
        PrintCollection(students);

        // average
        double averageCourses = students.Average(st => st.Courses.Count);
        Console.WriteLine(averageCourses);

        // max
        int max = students.Max(st => st.Courses.Count);
        Console.WriteLine(max);

        // min
        int min = students.Min(st => st.Courses.Count);
        Console.WriteLine(min);

        // count
        int count = students.Count(st => st.Name.Length > 4);
        Console.WriteLine(count);

        // sum
        int sum = students.Sum(st => st.Courses.Count);
        Console.WriteLine(sum);

        // extension methods
        var someCollection =
            students.Where(st => st.Id > 1)
                .OrderBy(st => st.Name)
                .ThenBy(st => st.Courses.Count)
                .Select(st => new { Name = st.Name, Courses = st.Courses.Count })
                .ToArray();

        PrintCollection(someCollection);

        // nesting
        var someOtherStudents = students.Where(st => st.Courses.Any(c => c.Name == "OOP")).OrderBy(st => st.Name);
        PrintCollection(someOtherStudents);
    }
 public ChangeRelativePathCommand(string input, string[] data, Tester judge, StudentsRepository repository, IOManager inputOutputManager) : base(input, data, judge, repository, inputOutputManager)
 {
 }
Exemple #44
0
        public void Put()
        {
            // Arrange
            var repository = new StudentsRepository(new StudentsEntities());

            // Act
            Student updatedStudent = new Student()
            {
                firstName = "stamat",
                lastName = "peshev",
                age = 20,
                grade = 5
            };

            repository.Update(2, updatedStudent);

            // Assert
            var theStudent = repository.Get(2);
            Assert.AreEqual(theStudent.firstName, updatedStudent.firstName);
            Assert.AreEqual(theStudent.lastName, updatedStudent.lastName);
            Assert.AreEqual(theStudent.age, updatedStudent.age);
            Assert.AreEqual(theStudent.grade, updatedStudent.grade);
        }