public async Task <IActionResult> GetSchoolYear(int id)
        {
            var subject = await subjectRepository.Get(id);

            if (subject == null)
            {
                return(NotFound(new { status = ResultStatus.STATUS_NOT_FOUND, message = "Không tìm thấy môn học" }));
            }
            return(Ok(new { status = ResultStatus.STATUS_OK, data = subject }));
        }
        public Subject Get(int id)
        {
            var rs = repository.Get(id);

            if (rs != null && rs.Status == (int)SubjectEnums.STATUS_DISABLE)
            {
                rs = null;
            }
            return(rs);
        }
        public void GetByWrongId_Null()
        {
            // Arrange
            SubjectRepository subjectRepository = new SubjectRepository(dbContext);
            Guid    wrongId = default(Guid);
            Subject expectedSubjectFromDb = null;

            // Act
            Subject actualSubjectFromDb = subjectRepository.Get(wrongId);

            // Assert
            Assert.AreEqual(expectedSubjectFromDb, actualSubjectFromDb);
        }
        public void GetById()
        {
            // Arrange
            SubjectRepository subjectRepository = new SubjectRepository(dbContext);
            Guid    idToSearch      = dbContext.Subjects.First().Id;
            Subject expectedSubject = dbContext.Subjects.Find(idToSearch);

            // Act
            Subject subjectFromDB = subjectRepository.Get(idToSearch);

            // Assert
            Assert.AreEqual(expectedSubject, subjectFromDB);
        }
        public void GetFilterByMessageAmount()
        {
            // Arrange
            SubjectRepository subjectRepository = new SubjectRepository(dbContext);
            int expectedSubjectInDb             = 2;

            // Act
            Subject[] subjectFromDb     = subjectRepository.Get(filter: subject => subject.Messages.Count > 2).ToArray();
            int       actualSubjectInDb = subjectFromDb.Length;

            // Assert
            Assert.AreEqual(expectedSubjectInDb, actualSubjectInDb);
            CollectionAssert.IsSubsetOf(subjectFromDb, dbContext.Subjects.ToArray());
        }
        public void GetAll()
        {
            // Arrange
            SubjectRepository subjectRepository = new SubjectRepository(dbContext);
            int expectedSubjectInDb             = Resources.Classes.DbFiller.Instance.SubjectAmount;

            // Act
            Subject[] subjectFromDB     = subjectRepository.Get().ToArray();
            int       actualSubjectInDb = subjectFromDB.Length;

            // Assert
            Assert.AreEqual(expectedSubjectInDb, actualSubjectInDb);
            CollectionAssert.AreEquivalent(dbContext.Subjects.ToArray(), subjectFromDB);
        }
        public void GetOrder()
        {
            // Arrange
            SubjectRepository subjectRepository = new SubjectRepository(dbContext);
            int expectedSubjectInDb             = Resources.Classes.DbFiller.Instance.SubjectAmount;

            // Act
            Subject[] subjectFromDb  = subjectRepository.Get(orderBy: subject => subject.OrderBy(s => s.Name)).ToArray();
            int       actualUserInDb = subjectFromDb.Length;

            // Assert
            Assert.AreEqual(expectedSubjectInDb, actualUserInDb);
            CollectionAssert.AreEqual(dbContext.Subjects.OrderBy(s => s.Name).ToArray(), subjectFromDb);
        }
        static void Main(string[] args)
        {
            string connString = ConfigurationManager.ConnectionStrings["TrainingDB"].ToString();

            try
            {
                SQLHelper.Initialize(connString);
                SQLHelper.AssureDatabase("Subjects");
                SQLHelper.AssureDatabase("Students");
                SQLHelper.AssureDatabase("StudentsXSubjects");
                StudentRepository studentRepository = new StudentRepository();

                //StudentEntity student = new StudentEntity();
                //student.Name = "Draghici";
                //student.Surname = "Alice";
                //student.PhoneNo = "0724059799";
                //studentRepository.Add(student);

                //StudentEntity student2 = new StudentEntity();
                //student2.Name = "Pavel";
                //student2.Surname = "Marcela";
                //student2.PhoneNo = "0729874154";
                //studentRepository.Add(student2);

                SubjectRepository subjectRepository = new SubjectRepository();

                //SubjectEntity subject1 = new SubjectEntity();
                //subject1.Description = "Matematica";
                //SubjectEntity subject2 = new SubjectEntity();
                //subject2.Description = "Algebra";
                //subjectRepository.Add(subject1);
                //subjectRepository.Add(subject2);
                //subject2.Description = "Franceza";
                //subjectRepository.Update(1, subject2);
                //subjectRepository.Delete(4);
                //subjectRepository.Delete(5);
                //subjectRepository.Delete(6);

                var subjects    = subjectRepository.Get();
                var subjectById = subjectRepository.GetById(2);
                studentRepository.AssignToSubject(7, 2);
                Console.Read();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
            }
        }
        public void GetFilterAndOrder()
        {
            // Arrange
            SubjectRepository subjectRepository = new SubjectRepository(dbContext);
            int expectedSubjectInDB             = Resources.Classes.DbFiller.Instance.SubjectAmount;

            Subject[] valuesInDataBase = dbContext.Subjects.Where(s => s.Messages.Count > 0).OrderByDescending(s => s.Name).ToArray();

            // Act
            Subject[] subjectFromDb       = subjectRepository.Get(filter: subject => subject.Messages.Count > 0, orderBy: o => o.OrderByDescending(s => s.Name)).ToArray();
            int       actualSubjectFromDb = subjectFromDb.Length;

            // Assert
            Assert.AreEqual(expectedSubjectInDB, actualSubjectFromDb);
            CollectionAssert.AreEqual(valuesInDataBase, subjectFromDb);
        }
        public IEnumerable <ClassSubject> AddSubjectToClass(int classId, List <ClassSubjectModel> subjectIds)
        {
            var origin = repository.Get(classId);
            var rs     = new List <ClassSubject>();

            //add subject to class
            subjectIds.ForEach(i =>
            {
                var found = origin.ClassSubjects.Where(cs => cs.SubjectId == i.SubjectId).FirstOrDefault();
                if (found == null)
                {
                    var classSubject = new ClassSubject
                    {
                        Id        = 0,
                        Status    = (int)ClassSubjectEnums.STATUS_ACTIVE,
                        ClassId   = classId,
                        SubjectId = i.SubjectId,
                        Teacher   = i.TeacherId
                    };
                    origin.ClassSubjects.Add(classSubject);
                    rs.Add(classSubject);
                }
                else
                {
                    if (found.Status == (int)ClassSubjectEnums.STATUS_DISABLE)
                    {
                        rs.Add(found);
                    }
                    found.Status  = (int)ClassSubjectEnums.STATUS_ACTIVE;
                    found.Teacher = i.TeacherId;
                }
            });
            repository.Update(origin);
            //update transcript of class
            var subjectRepository = new SubjectRepository();

            rs.ForEach(cs =>
            {
                cs.Subject = subjectRepository.Get(cs.SubjectId);
            });
            var transcriptService = new TranscriptService();

            transcriptService.AddSubjectToClassTranscript(classId, rs);
            return(rs);
        }
Exemple #11
0
        public void testGet()
        {
            // Arrange
            int count = repo.All().Count();

            this.repo.Add(entity);
            this.repo.SaveChanges();


            // Act
            Subject actual = repo.Get(x => (x.Name == n)).FirstOrDefault();

            // Assert

            Assert.NotNull(actual);

            this.repo.HardDelete(entity);
            this.repo.SaveChanges();
        }
        // GET api/values/5
        public IHttpActionResult Get(int id)
        {
            var subject = repo.Get(id);

            return(new ResponseClass(JsonConvert.SerializeObject(subject), Request));
        }
Exemple #13
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     cbOil.DisplayMember = "Name";
     cbOil.DataSource    = _subjectsRepository.Get();
 }
Exemple #14
0
        public async Task <List <SubjectDTO> > Get()
        {
            var repository = new SubjectRepository();

            return(await repository.Get());
        }