예제 #1
0
		public void TestLoadEmptyPersons()
		{
			var mock = new Mock<IRepository<Person>>();
			mock.Setup(repo => repo.SaveChanges());
			mock.Setup(repo => repo.GetAll()).Returns(new List<Person>());

			var personDataAccess = new PersonDataAccess(mock.Object);
			List<Person> persons = personDataAccess.LoadAllPeople();
			Assert.AreEqual(0, persons.Count);
		}
예제 #2
0
        public void TestLoadEmptyPersons()
        {
            var mock = new Mock <IRepository <Person> >();

            mock.Setup(repo => repo.SaveChanges());
            mock.Setup(repo => repo.GetAll()).Returns(new List <Person>());

            var           personDataAccess = new PersonDataAccess(mock.Object);
            List <Person> persons          = personDataAccess.LoadAllPeople();

            Assert.AreEqual(0, persons.Count);
        }
예제 #3
0
    public IHttpActionResult GetById(int id)
    {
        PersonDataAccess person = PersonDataAccess.Data.FirstOrDefault(p => p.Id = id);

        if (person != null)
        {
            return(Ok(person));
        }
        else
        {
            return(NotFound());
        }
    }
예제 #4
0
		public void TestSavePerson()
		{
			Person p = CreatePersons(1)[0];

			var mock = new Mock<IRepository<Person>>();
			mock.Setup(repo => repo.SaveChanges());
			mock.Setup(repo => repo.GetQuery()).Returns(new List<Person> { p }.AsQueryable);

			var personDataAccess = new PersonDataAccess(mock.Object);
			personDataAccess.SavePerson(p);

			Person loadedPerson = personDataAccess.LoadPerson(p.Id);
			ValidatePerson(p, loadedPerson);
		}
예제 #5
0
파일: MainViewModel.cs 프로젝트: acid84/UHS
        public MainViewModel()
        {
            var personData  = new PersonDataAccess(RepositoryFactory <Person> .GetRepository());
            var companyData = new CompanyDataAccess(RepositoryFactory <Company> .GetRepository());
            var invoiceData = new InvoiceDataAccess(RepositoryFactory <Invoice> .GetRepository(), RepositoryFactory <InvoiceRow> .GetRepository());
            var userData    = new UserDataAccess(RepositoryFactory <User> .GetRepository());

            RegistratePersonViewModel  = new RegistratePersonViewModel(personData);
            RegistrateCompanyViewModel = new RegistrateCompanyViewModel(companyData);
            RegisterInvoiceViewModel   = new RegistrateInvoiceViewModel(invoiceData, companyData, personData);
            InvoiceViewModel           = new InvoiceViewModel(invoiceData);


            userData.AddUser("admin", "admin");
            LoginViewModel = new LoginViewModel(userData);
        }
예제 #6
0
파일: MainViewModel.cs 프로젝트: acid84/UHS
		public MainViewModel()
		{
			var personData = new PersonDataAccess(RepositoryFactory<Person>.GetRepository());
			var companyData = new CompanyDataAccess(RepositoryFactory<Company>.GetRepository());
			var invoiceData = new InvoiceDataAccess(RepositoryFactory<Invoice>.GetRepository(), RepositoryFactory<InvoiceRow>.GetRepository());
			var userData = new UserDataAccess(RepositoryFactory<User>.GetRepository());

			RegistratePersonViewModel = new RegistratePersonViewModel(personData);
			RegistrateCompanyViewModel = new RegistrateCompanyViewModel(companyData);
			RegisterInvoiceViewModel = new RegistrateInvoiceViewModel(invoiceData, companyData, personData);
			InvoiceViewModel = new InvoiceViewModel(invoiceData);


			userData.AddUser("admin", "admin");
			LoginViewModel = new LoginViewModel(userData);
		}
예제 #7
0
        public static void Main(string[] args)
        {
            IDataAccess <Person> db = new PersonDataAccess();

            db.SaveItem(new Person {
                Firstname = "Chris",
                Lastname  = "White",
                Age       = 32
            });

            var people = db.GetItems();

            foreach (var person in people)
            {
                Console.WriteLine("Firstname {0}, Lastname {1}, Age {2}", person.Firstname, person.Lastname, person.Age);
            }
        }
예제 #8
0
        private bool CanChangeUserLogin(User user)
        {
            var res = UserSecurity.CanModify(Context, user);

            if (!res && Context.DistrictId.HasValue && user.SisUserId.HasValue && BaseSecurity.IsTeacher(Context))
            {
                int roleId;
                var personId = PersonDataAccess.GetPersonDataForLogin(Context.DistrictServerUrl, Context.DistrictId.Value, user.SisUserId.Value, out roleId);
                if (roleId == CoreRoles.STUDENT_ROLE.Id)
                {
                    var schooLocator = ServiceLocator.SchoolServiceLocator(Context.DistrictId.Value, Context.SchoolLocalId);
                    res = (Context.PersonId.HasValue && Context.SchoolYearId.HasValue &&
                           schooLocator.StudentService.IsTeacherStudent(Context.PersonId.Value, personId, Context.SchoolYearId.Value));
                }
            }
            return(res);
        }
예제 #9
0
 public void ActivatePerson(int id)
 {
     if (!BaseSecurity.IsDistrictAdminOrCurrentPerson(id, Context))
     {
         throw new ChalkableSecurityException();
     }
     using (var uow = Update())
     {
         var da     = new PersonDataAccess(uow);
         var person = GetPerson(id);
         //TODO: change school status
         person.Active = true;
         //person.FirstLoginDate = Context.NowSchoolTime;
         da.Update(person);
         uow.Commit();
     }
 }
예제 #10
0
		public void TestLoadPersons()
		{
			const int nbrOfPersons = 150;
			List<Person> personList = CreatePersons(nbrOfPersons);

			var mock = new Mock<IRepository<Person>>();
			mock.Setup(repo => repo.SaveChanges());
			mock.Setup(repo => repo.GetAll()).Returns(personList.AsQueryable);

			var personDataAccess = new PersonDataAccess(mock.Object);

			foreach (Person person in personList)
			{
				personDataAccess.SavePerson(person);
			}

			List<Person> persons = personDataAccess.LoadAllPeople();
			Assert.AreEqual(nbrOfPersons, persons.Count);
		}
예제 #11
0
        public void TestSavePerson()
        {
            Person p = CreatePersons(1)[0];

            var mock = new Mock <IRepository <Person> >();

            mock.Setup(repo => repo.SaveChanges());
            mock.Setup(repo => repo.GetQuery()).Returns(new List <Person> {
                p
            }.AsQueryable);

            var personDataAccess = new PersonDataAccess(mock.Object);

            personDataAccess.SavePerson(p);

            Person loadedPerson = personDataAccess.LoadPerson(p.Id);

            ValidatePerson(p, loadedPerson);
        }
예제 #12
0
        public void TestLoadPersons()
        {
            const int     nbrOfPersons = 150;
            List <Person> personList   = CreatePersons(nbrOfPersons);

            var mock = new Mock <IRepository <Person> >();

            mock.Setup(repo => repo.SaveChanges());
            mock.Setup(repo => repo.GetAll()).Returns(personList.AsQueryable);

            var personDataAccess = new PersonDataAccess(mock.Object);

            foreach (Person person in personList)
            {
                personDataAccess.SavePerson(person);
            }

            List <Person> persons = personDataAccess.LoadAllPeople();

            Assert.AreEqual(nbrOfPersons, persons.Count);
        }
예제 #13
0
		public void TestSaveMultiplePersons()
		{
			List<Person> personList = CreatePersons(100);

			var mock = new Mock<IRepository<Person>>();
			mock.Setup(repo => repo.SaveChanges());
			mock.Setup(repo => repo.GetQuery()).Returns(personList.AsQueryable);

			var personDataAccess = new PersonDataAccess(mock.Object);

			foreach(Person person in personList)
			{
				personDataAccess.SavePerson(person);				
			}

			foreach(Person person in personList)
			{
				Person loadedPerson = personDataAccess.LoadPerson(person.Id);				
				ValidatePerson(person, loadedPerson);
			}
		}
예제 #14
0
 public void ProcessPersonFirstLogin(int id)
 {
     if (Context.PersonId != id)
     {
         throw new ChalkableSecurityException();
     }
     DoUpdate(uow =>
     {
         var da = new PersonDataAccess(uow);
         var p  = da.GetById(id);
         if (p.FirstLoginDate.HasValue)
         {
             return;
         }
         p.FirstLoginDate = Context.NowSchoolTime;
         da.Update(p);
         ServiceLocator.ClassAnnouncementService.SetAnnouncementsAsComplete(Context.NowSchoolTime, true);
         LessonPlanService.SetAnnouncementsAsComplete(uow, ServiceLocator, Context.NowSchoolTime, true);
         AdminAnnouncementService.SetAnnouncementsAsComplete(uow, ServiceLocator, Context.NowSchoolTime, true);
     });
 }
예제 #15
0
        public void TestSaveMultiplePersons()
        {
            List <Person> personList = CreatePersons(100);

            var mock = new Mock <IRepository <Person> >();

            mock.Setup(repo => repo.SaveChanges());
            mock.Setup(repo => repo.GetQuery()).Returns(personList.AsQueryable);

            var personDataAccess = new PersonDataAccess(mock.Object);

            foreach (Person person in personList)
            {
                personDataAccess.SavePerson(person);
            }

            foreach (Person person in personList)
            {
                Person loadedPerson = personDataAccess.LoadPerson(person.Id);
                ValidatePerson(person, loadedPerson);
            }
        }
예제 #16
0
        public IList <Person> GetAnnouncementRecipientPersons(int announcementId, int teacherId, int filterStudentType, int schoolYearId, int start, int count)
        {
            var parameters = new Dictionary <string, object>
            {
                ["announcementId"]      = announcementId,
                ["start"]               = start,
                ["count"]               = count,
                ["teacherId"]           = teacherId,
                ["filterStudentType"]   = filterStudentType,
                ["currentSchoolYearId"] = schoolYearId
            };

            using (var reader = ExecuteStoredProcedureReader(GET_ANNOUNCEMENT_RECIPIENT_PERSON, parameters))
            {
                var res = new List <Person>();
                while (reader.Read())
                {
                    res.Add(PersonDataAccess.ReadPersonData(reader));
                }

                return(res);
            }
        }
예제 #17
0
        public AnnouncementQnA Answer(int announcementQnAId, AnnouncementTypeEnum announcementType, string question, string answer)
        {
            Trace.Assert(Context.PersonId.HasValue);

            using (var uow = Update())
            {
                var da     = new AnnouncementQnADataAccess(uow);
                var annQnA = GetAnnouncementQnA(announcementQnAId);
                // todo: think about security
                if (!CanEditQuestion(annQnA, uow))
                {
                    throw new ChalkableSecurityException();
                }

                annQnA.State    = AnnouncementQnAState.Answered;
                annQnA.Question = question;
                if ((BaseSecurity.IsDistrictOrTeacher(Context)) && (!annQnA.AnswererRef.HasValue || annQnA.AnswererRef == Context.PersonId))
                {
                    var answerer = new PersonDataAccess(uow).GetById(Context.PersonId.Value);
                    annQnA.Answerer     = answerer;
                    annQnA.AnswererRef  = answerer.Id;
                    annQnA.AnsweredTime = Context.NowSchoolTime;
                    annQnA.Answer       = answer;
                }
                da.Update(annQnA);
                uow.Commit();
                var  ann = ServiceLocator.GetAnnouncementService(announcementType).GetAnnouncementById(annQnA.AnnouncementRef);
                bool visibleForStudent = (ann is LessonPlan && (ann as LessonPlan).VisibleForStudent) ||
                                         (ann is ClassAnnouncement && (ann as ClassAnnouncement).VisibleForStudent) ||
                                         (ann is AdminAnnouncement);
                if (visibleForStudent)
                {
                    ServiceLocator.NotificationService.AddAnnouncementNotificationAnswerToStudent(annQnA.Id, annQnA.AnnouncementRef, announcementType);
                }
                return(annQnA);
            }
        }
예제 #18
0
        public IList <StudentDetailsInfo> GetClassStudentsDetails(int classId, bool?isEnrolled = null)
        {
            Trace.Assert(Context.SchoolLocalId.HasValue);

            using (var uow = Read())
            {
                var studentsDetails = new StudentDataAccess(uow).GetDetailsByClass(classId, isEnrolled);
                var ethnicitiesIds  = studentsDetails
                                      .Where(x => x.PrimaryPersonEthnicity != null)
                                      .Select(x => x.PrimaryPersonEthnicity.EthnicityRef).ToList();
                var ethnicities = new DataAccessBase <Ethnicity, int>(uow).GetByIds(ethnicitiesIds);

                var languagesIds = studentsDetails
                                   .Where(x => x.PrimaryPersonLanguage != null)
                                   .Select(x => x.PrimaryPersonLanguage.LanguageRef).ToList();
                var languages = new DataAccessBase <Language, int>(uow).GetByIds(languagesIds);

                var countriesIds = studentsDetails
                                   .Where(x => x.PrimaryPersonNationality != null)
                                   .Select(x => x.PrimaryPersonNationality.CountryRef).ToList();
                var countries = new DataAccessBase <Country, int>(uow).GetByIds(countriesIds);

                IList <int> counselorsIds = new List <int>();

                foreach (var student in studentsDetails)
                {
                    var currentStudentSchool = student.StudentSchools.FirstOrDefault(x => x.SchoolRef == Context.SchoolLocalId);
                    if (currentStudentSchool?.CounselorRef != null)
                    {
                        counselorsIds.Add(currentStudentSchool.CounselorRef.Value);
                    }
                }
                var counselors = new PersonDataAccess(uow).GetByIds(counselorsIds);

                return(StudentDetailsInfo.Create(studentsDetails, ethnicities, languages, countries, counselors, Context.SchoolLocalId.Value));
            }
        }
예제 #19
0
        private bool CanTeacherSendMessage(int personId, UnitOfWork uow)
        {
            Trace.Assert(Context.PersonId.HasValue);
            Trace.Assert(Context.SchoolLocalId.HasValue);

            bool canSend  = false;
            var  toPerson = new PersonDataAccess(uow).GetPersonDetails(personId, Context.SchoolLocalId.Value);

            if (toPerson == null)
            {
                return(false);
            }

            if (toPerson.RoleRef == CoreRoles.TEACHER_ROLE.Id)
            {
                return(true);
            }

            if (toPerson.RoleRef == CoreRoles.STUDENT_ROLE.Id)
            {
                if (Context.TeacherStudentMessaginEnabled)
                {
                    canSend = true;
                    if (Context.TeacherClassMessagingOnly)
                    {
                        var toPersonClasses = new ClassDataAccess(uow).GetStudentClasses(Context.SchoolYearId.Value,
                                                                                         personId, null);
                        var currPersonClasses = new ClassDataAccess(uow).GetTeacherClasses(Context.SchoolYearId.Value,
                                                                                           Context.PersonId.Value, null);

                        canSend = currPersonClasses.Any(x => toPersonClasses.Any(y => x.Id == y.Id));
                    }
                }
            }

            return(canSend);
        }
예제 #20
0
        private static UserContext CreateUserContext(SchoolUser schoolUser, Data.School.Model.SchoolYear schoolYear = null)
        {
            int roleId;

            int personId = schoolUser.User.IsDemoUser
                ? DemoPersonService.GetPersonDataForLogin(schoolUser.User, out roleId)
                : PersonDataAccess.GetPersonDataForLogin(schoolUser.User.District.ServerUrl,
                                                         schoolUser.DistrictRef, schoolUser.UserRef, out roleId);
            var user   = schoolUser.User;
            var school = schoolUser.School;
            var role   = CoreRoles.GetById(roleId);

            Guid?developerId = null;

            if (schoolUser.User.IsDemoUser)
            {
                var developer = CreateMasterSysAdmin().UserService.GetById(user.District.Id);
                if (developer != null)
                {
                    developerId = developer.Id;
                }
            }
            return(new UserContext(user, role, user.District, school, developerId, personId, null, schoolYear));
        }
예제 #21
0
        public StudentDetailsInfo GetStudentDetailsInfo(int studentId, int syId)
        {
            var sy = ServiceLocator.SchoolYearService.GetSchoolYearById(syId);

            using (var uow = Read())
            {
                var       studentDetails = new StudentDataAccess(uow).GetDetailsById(studentId, syId);
                Ethnicity ethnicity      = null;
                Country   country        = null;
                Language  language       = null;
                Person    counselor      = null;

                if (studentDetails.PrimaryPersonEthnicity != null)
                {
                    ethnicity = new DataAccessBase <Ethnicity, int>(uow).GetById(studentDetails.PrimaryPersonEthnicity.EthnicityRef);
                }

                if (studentDetails.PrimaryPersonLanguage != null)
                {
                    language = new DataAccessBase <Language, int>(uow).GetById(studentDetails.PrimaryPersonLanguage.LanguageRef);
                }

                if (studentDetails.PrimaryPersonNationality != null)
                {
                    country = new DataAccessBase <Country, int>(uow).GetById(studentDetails.PrimaryPersonNationality.CountryRef);
                }

                var studentSchool = studentDetails.StudentSchools.FirstOrDefault(x => x.SchoolRef == sy.SchoolRef);
                if (studentSchool?.CounselorRef != null)
                {
                    counselor = new PersonDataAccess(uow).GetById(studentSchool.CounselorRef.Value);
                }

                return(StudentDetailsInfo.Create(studentDetails, ethnicity, language, country, counselor, studentSchool));
            }
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 public PersonBusinessLogic()
 {
     _personDataAccess = new PersonDataAccess();
 }
 public PersonDataAccessUnitTests()
 {
     _personData = new PersonDataAccess();
 }
예제 #24
0
 public Person CreatePerson(PersonUpdateModel person)
 {
     this.PersonGetService.ValidatePerson(person);
     return(PersonDataAccess.Insert(person));
 }
예제 #25
0
        private UserContext SisUserLogin(User user, UnitOfWork uow, ConnectorLocator iNowConnector = null
                                         , StiConnector.Connectors.Model.User iNowUser             = null, int?schoolYearId = null, string sisRedirectUrl = null)
        {
            if (user == null)
            {
                return(null);
            }
            if (user.SisUserId.HasValue)
            {
                try
                {
                    SaveSisToken(user, uow, ref iNowConnector);
                }
                catch (HttpException)
                {
                    return(null);
                }
                Trace.Assert(user.DistrictRef.HasValue);
                var schoolL = ServiceLocator.SchoolServiceLocator(user.DistrictRef.Value, null);
                Data.School.Model.SchoolYear schoolYear;
                SchoolUser schoolUser;
                var        userAcadSessionsIds = iNowConnector.UsersConnector.GetUserAcadSessionsIds();
                if (userAcadSessionsIds.Length == 0)
                {
                    throw new ChalkableException("Current user does not have access to any of school acadSessions");
                }
                if (!schoolYearId.HasValue && userAcadSessionsIds.Length == 1)
                {
                    schoolYearId = userAcadSessionsIds[0];
                }
                PrepareSchoolData(schoolL, user, schoolYearId, userAcadSessionsIds, out schoolYear, out schoolUser);
                if (!schoolUser.School.IsChalkableEnabled)
                {
                    return(null);
                }
                if (iNowUser == null)
                {
                    iNowUser = iNowConnector.UsersConnector.GetMe();
                }
                int roleId;
                int personId   = PersonDataAccess.GetPersonDataForLogin(user.District.ServerUrl, user.DistrictRef.Value, user.SisUserId.Value, out roleId);
                var claimInfos = ClaimInfo.Create(iNowUser.Claims);
                if (roleId == CoreRoles.TEACHER_ROLE.Id)
                {
                    EnsureTeacherChalkableAccess(claimInfos);
                }
#if DEBUG
                var loginTimeOut = (int?)null;
#else
                var loginTimeOut = schoolL.AppSettingService.GetLoginTimeOut();
#endif

                var res = new UserContext(user, CoreRoles.GetById(roleId), user.District, schoolUser.School, null, personId, loginTimeOut, schoolYear, sisRedirectUrl)
                {
                    Claims        = ClaimInfo.Create(iNowUser.Claims),
                    SisApiVersion = iNowConnector.ApiVersion
                };
                return(res);
            }
            throw new UnknownRoleException();
        }
예제 #26
0
 // For Unit testing purposes.
 public UserController(PersonDataAccess personDataAccess)
 {
     _personDataAccess  = personDataAccess;
     _streetAddressData = new StreetStreetAddressData();
     _factory           = new Models.ModelFactory();
 }