Пример #1
0
 public UnitOfWork(AppDbContext context)
 {
     _context   = context;
     Rooms      = new RoomRepository(_context);
     Clinicians = new ClinicianRepository(_context);
     Parents    = new ParentRepository(_context);
 }
        public ParentChildTests(ITestOutputHelper output) : base(output)
        {
            _parentRepository = new ParentRepository(_configuration);
            _childRepository  = new ChildRepository(_configuration);

            RemoveDataAsync().GetAwaiter().GetResult();
        }
Пример #3
0
        /// <summary>Gets an inner mapper from the repository.</summary>
        /// <exception cref="InvalidOperationException">
        ///     Thrown when the mapper does not have a parent repository.
        /// </exception>
        /// <typeparam name="TInnerSource">Type of the source property.</typeparam>
        /// <typeparam name="TInnerTarget">Type of the target property.</typeparam>
        /// <returns>
        ///     A mapper capable of translating <typeparamref name="TInnerSource" /> objects into
        ///     <typeparamref name="TInnerTarget" /> ones.
        /// </returns>
        protected IMapper GetInnerMapper <TInnerSource, TInnerTarget>()
        {
            if (ParentRepository == null)
            {
                // TODO: review approach here -- this branch could lead to mapper "cloning"
                throw new InvalidOperationException(
                          "Mapper must be contained in a repository in order to allow inner mappers.");
            }

            Type enumerableType  = typeof(IEnumerable);
            Type innerSourceType = typeof(TInnerSource);
            Type innerTargetType = typeof(TInnerTarget);

            if (enumerableType.IsAssignableFrom(typeof(TInnerSource)) &&
                enumerableType.IsAssignableFrom(typeof(TInnerTarget)))
            {
                Type genericEnumerableType = typeof(IEnumerable <>);
                Type ts = innerSourceType.GetGenericTypeDefinition();
                Type tt = innerTargetType.GetGenericTypeDefinition();

                if ((tt != null) &&
                    (ts != null) &&
                    genericEnumerableType.IsAssignableFrom(tt) &&
                    genericEnumerableType.IsAssignableFrom(ts))
                {
                    Type    innerSource = innerSourceType.GetGenericArguments()[0];
                    Type    innerTarget = innerTargetType.GetGenericArguments()[0];
                    IMapper realMapper  = ParentRepository.ResolveMapper(innerSource, innerTarget);
                    return(new MultiMappingAdapter(realMapper, innerSourceType));
                }
            }

            return(ParentRepository.ResolveMapper <TInnerSource, TInnerTarget>());
        }
Пример #4
0
        private void SendEmail(string confirmed_canceled)
        {
            string date               = ParentMeetingDateTimePicker.Value.ToShortDateString();
            string time               = TimeComboBox.Text;
            string SchoolMail         = "*****@*****.**";
            string SchoolName         = "Skola";
            string SchoolMailPassword = "******";

            int    TeacherId    = CurrentTeacher.Id;
            int    DepartmentId = DepartmentsRepository.GetIdByTeacherId(TeacherId);
            string StudentIds   = StudentRepository.GetStudentIds(DepartmentId);

            string[] parts = StudentIds.Split(',');
            Email    email = new Email();

            for (int i = 0; i < parts.Length; i++)
            {
                Parent CurrentParent      = ParentRepository.GetParentByStudentId(int.Parse(parts[i]));
                string currentParentEmail = CurrentParent.Email;
                string currentParentName  = CurrentParent.Name;
                string message            = "Poštovani " + CurrentParent.Name + " " + CurrentParent.Surname + "\n"
                                            + "Obavještavam Vas da je" + " " + confirmed_canceled + " " + "roditeljski sastanak dana " + date + " u " + time
                                            + "\n" + "Nastavnik : " + CurrentTeacher.Name + " " + CurrentTeacher.Surname
                ;
                email.SendEmailInBackground(SchoolMail, SchoolName, SchoolMailPassword, currentParentEmail, currentParentName, message);
            }
            MessageBox.Show("Roditelji su uspješno obaviješteni");
        }
Пример #5
0
        public void FillData()
        {
            BasicRepository _basic = new BasicRepository();

            BasicContants.StoredProcedure = "GetGender";
            Genders    = _basic.Get();
            GenderList = Genders.ToGenderSelectListItems(GenderID);

            BasicContants.StoredProcedure = "GetStudentType";
            Students    = _basic.Get();
            StudentList = Students.ToStudentTypeSelectListItems(StudentTypeID);

            SectionsRepository _section = new SectionsRepository();

            BasicContants.StoredProcedure = "GetFullSectionName";
            Sections    = _section.Get();
            SectionList = Sections.ToSectionSelectListItems(SectionID);

            ParentRepository _parent = new ParentRepository();

            Parents    = _parent.Get();
            ParentList = Parents.ToParentSelectListItems(ParentID);

            TransportRepository _transport = new TransportRepository();

            Transports    = _transport.Get();
            TransportList = Transports.ToTransportSelectListItems(TransportID);
        }
Пример #6
0
        private Parent CurrentParent()
        {
            Parent  parent;
            Student student   = CurrentStudent();
            int     studentId = StudentRepository.GetIdByJmbg(student.Jmbg);

            parent = ParentRepository.GetParentByStudentId(studentId);
            return(parent);
        }
        private ICollection <TRelationshipEntity> GetRelationshipCollection(TRelationshipDTO relationship)
        {
            var parentId     = ParentDTOKeySelector(relationship);
            var includes     = AdditionalParentIncludes.Concat(new[] { ConvertToIncludesExpression(RelationshipCollectionSelector) }).ToArray();
            var parentEntity = ParentRepository.GetById(parentId, includes);

            ValidateModifyPermissions(parentEntity);

            var relationshipCollection = RelationshipCollectionSelector.Compile()(parentEntity);

            return(relationshipCollection);
        }
Пример #8
0
 public UnitOfWork(DbContext context, ClassRoomRepository classRoomRepository, CommentRepository commentRepository, MailRepository mailRepository, ParentRepository parentRepository, PupilRepository pupilRepository, RequisitionRepository requisitionRepository, RoleRepository roleRepository, TeacherRepository teacherRepository, UserRepository userRepository)
 {
     Context = context;
     this.classRoomRepository   = classRoomRepository;
     this.commentRepository     = commentRepository;
     this.mailRepository        = mailRepository;
     this.parentRepository      = parentRepository;
     this.pupilRepository       = pupilRepository;
     this.requisitionRepository = requisitionRepository;
     this.roleRepository        = roleRepository;
     this.teacherRepository     = teacherRepository;
     this.userRepository        = userRepository;
 }
Пример #9
0
 public UnitOfWork(LogDbContext dbContext)
 {
     _dbContext      = dbContext;
     Classes         = new SchoolClassRepository(dbContext);
     Users           = new UserRepository(dbContext);
     Students        = new StudentRepository(dbContext);
     Teachers        = new TeacherRepository(dbContext);
     Parents         = new ParentRepository(dbContext);
     Subjects        = new SubjectRepository(dbContext);
     SchoolGrades    = new SchoolGradeRepository(dbContext);
     Messages        = new MessageRepository(dbContext);
     Advertisements  = new AdvertisementRepository(dbContext);
     Files           = new FileRepository(dbContext);
     Questions       = new QuestionRepository(dbContext);
     QuestionAnswers = new QuestionAnswerRepository(dbContext);
     Tests           = new TestRepository(dbContext);
 }
        public TRelationshipDTO GetDetail(TKey id)
        {
            using (UnitOfWorkProvider.Create())
            {
                var entity = Repository.GetById(id);
                if (entity == null)
                {
                    return(default(TRelationshipDTO));
                }

                var parentId     = ParentEntityKeySelector(entity);
                var includes     = AdditionalParentIncludes.Concat(new [] { ConvertToIncludesExpression(RelationshipCollectionSelector) }).ToArray();
                var parentEntity = ParentRepository.GetById(parentId, includes);
                ValidateReadPermissions(parentEntity);
                return(entityMapper.MapToDTO(entity));
            }
        }
Пример #11
0
        public EntityService()
        {
            weekDayRepository     = new WeekDayRepository();
            roomLectureRepository = new RoomLectureRepository();
            roomRepository        = new RoomRepository();

            lectureRepository         = new LectureRepository();
            parentRepository          = new ParentRepository();
            postponedLessonRepository = new PostponedLessonRepository();
            programRepository         = new ProgramRepository();
            recievedPaymentRepository = new RecievedPaymentRepository();

            studentRepository        = new StudentRepository();
            teacherLectureRepository = new TeacherLectureRepository();
            teacherPaymentRepository = new TeacherPaymentRepository();
            teacherRepository        = new TeacherRepository();
            userRepository           = new UserRepository();
        }
Пример #12
0
        public void GetByUSIShouldReturnFirstMatchingParentWithDependencies()
        {
            var       mockDbContext = new Mock <INglDbContext>();
            var       repo = new ParentRepository(mockDbContext.Object);
            const int parentUSI = 3;
            var       parentBuilder = new ParentBuilder();
            var       parents = new List <Parent> {
                parentBuilder.WithUSI(1).Build(), parentBuilder.WithUSI(parentUSI).Build(), parentBuilder.WithUSI(2).Build()
            }.AsQueryable();
            var mockSet = new Mock <IDbSet <Parent> >();

            mockSet.As <IQueryable <Parent> >().Setup(m => m.Provider).Returns(parents.Provider);
            mockSet.As <IQueryable <Parent> >().Setup(m => m.Expression).Returns(parents.Expression);
            mockDbContext.Setup(dbContext => dbContext.Set <Parent>()).Returns(mockSet.Object);

            var returnedParent = repo.GetByUSI(parentUSI);

            Assert.Equal(parentUSI, returnedParent.ParentUSI);
        }
        private void AddStudentButton_Click(object sender, EventArgs e)
        {
            bool isEmail = Regex.IsMatch(ParentEmailTextBox.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);

            if (StudentNameTextBox.Text.Length == 0 ||
                StudentSurnameTextBox.Text.Length == 0 ||
                StudentJmbgTextBox.Text.Length == 0 ||
                ParentNameTextBox.Text.Length == 0 ||
                ParentSurnameTextBox.Text.Length == 0)
            {
                Warning();
            }
            else if (ParentEmailTextBox.Text.Length > 0 && isEmail == false)
            {
                MessageBox.Show("Molimo unesite validan email!");
            }
            else
            {
                string currentDepartmentTitle = GetCurrentDepartmentTitle();
                bool   isParentAdded          = ParentRepository.AddParent(ParentNameTextBox.Text, ParentSurnameTextBox.Text, ParentAddressTextBox.Text, ParentEmailTextBox.Text, ParentPhoneTextBox.Text, StudentJmbgTextBox.Text, int.Parse(currentDepartmentTitle),
                                                                           StudentNameTextBox.Text, StudentSurnameTextBox.Text, StudentJmbgTextBox.Text, StudentAddressTextBox.Text, StudentPhoneTextBox.Text
                                                                           );
                if (isParentAdded == true)
                {
                    ParentNameTextBox.Text    = "";
                    ParentSurnameTextBox.Text = "";
                    ParentAddressTextBox.Text = "";
                    ParentEmailTextBox.Text   = "";
                    ParentPhoneTextBox.Text   = "";
                    StudentJmbgTextBox.Text   = "";

                    StudentNameTextBox.Text    = "";
                    StudentSurnameTextBox.Text = "";
                    StudentJmbgTextBox.Text    = "";
                    StudentAddressTextBox.Text = "";
                    StudentPhoneTextBox.Text   = "";
                    DepartmentComboBox.Text    = "";
                }
            }
        }
Пример #14
0
        //IGenericRepository IUnitOfWork.Repository => throw new NotImplementedException();

        public UnitOfWork()
        {
            dbContext                  = new DatabaseContext();
            Repository                 = new GenericRepository(dbContext);
            SchoolRepository           = new SchoolRepository(dbContext);
            ExceptionLoggerRepository  = new ExceptionLoggerRepository(dbContext);
            ApiLogRepository           = new ApiLogRepository(dbContext);
            ImageFileTypeRepository    = new ImageFileTypeRepository(dbContext);
            AssessmentRepository       = new AssessmentRepository(dbContext);
            AttendanceRepository       = new AttendanceRepository(dbContext);
            BookRepository             = new BookRepository(dbContext);
            BookTransactionRepository  = new BookTransactionRepository(dbContext);
            EventRepository            = new EventRepository(dbContext);
            HomeworkRepository         = new HomeworkRepository(dbContext);
            ImageFileUrlRepository     = new ImageFileUrlRepository(dbContext);
            ParentRepository           = new ParentRepository(dbContext);
            StandardRepository         = new StandardRepository(dbContext);
            StudentRepository          = new StudentRepository(dbContext);
            SubjectRepository          = new SubjectRepository(dbContext);
            TeacherRepository          = new TeacherRepository(dbContext);
            YearRepository             = new YearRepository(dbContext);
            OperationalStaffRepository = new OperationalStaffRepository(dbContext);
        }
        public ParentChildTests(ITestOutputHelper output) : base(output) {
            _parentRepository = new ParentRepository(_configuration);
            _childRepository = new ChildRepository(_configuration);

            RemoveDataAsync().GetAwaiter().GetResult();
        }
Пример #16
0
 //===============================================================
 public IEnumerator <T> GetEnumerator()
 {
     return(new CallbackEnumerator <T>(Objects.GetEnumerator(), x => ParentRepository.AddChangeTracker(x)));
 }
 public static void Configure()
 {
     _addressRepository  = new AddressRepository();
     _childrenRepository = new ChildrenRepository();
     _parentRepository   = new ParentRepository();
 }
Пример #18
0
        public async Task <Result <DataPoint[]> > UpsertAsync(Criteria <IEnumerable <DataPoint> > dataPointsCriteria)
        {
            // Validate the criteria.
            if (dataPointsCriteria?.Value == null || dataPointsCriteria.Value.Count() == 0)
            {
                return(new Result <DataPoint[]>()
                {
                    Message = "Invalid criteria"
                });
            }

            // Validate models.
            var validationErrors = new List <string>();
            var dataPoints       = dataPointsCriteria.Value.ToList();

            dataPoints.ForEach(m =>
            {
                string[] messages;
                if (!m.TryValidateModel(out messages))
                {
                    validationErrors.AddRange(messages);
                }
            });
            if (validationErrors.Count > 0)
            {
                return(new Result <DataPoint[]>()
                {
                    Message = $"Model validation errors: {String.Join("; ", validationErrors)}"
                });
            }

            // Ensure all CategoryId values are valid.
            List <Task <Category> > categoryTasks = new List <Task <Category> >();

            dataPoints.GroupBy(d => d.CategoryId)
            .Select(g => g.Key)
            .ToList()
            .ForEach(id => categoryTasks.Add(ParentRepository.GetAsync(id)));
            var categories = await Task.WhenAll(categoryTasks);

            if (categories.Any(c => c == null))
            {
                return(new Result <DataPoint[]>()
                {
                    Message = "Data point references missing category."
                });
            }

            // Get tasks to search for current matching DataPoints then await all.
            List <Task <DataPoint> > tasks = new List <Task <DataPoint> >();

            dataPoints.ForEach(m =>
            {
                tasks.Add(Repository.GetAsync(m.Id));
            });
            var currentDataPoints = (await Task.WhenAll(tasks)).Where(d => d != null).Where(m => m != null).ToList();

            // For all new DataPoints ensure we have a valid new Id.
            dataPoints.Where(d => !currentDataPoints.Any(c => c.Id == d.Id))
            .ToList()
            .ForEach(d => { d.Id = Guid.NewGuid().ToString(); });

            // Control which fields are updated.
            currentDataPoints.ForEach(c =>
            {
                var dataPoint        = dataPoints.First(d => d.Id == c.Id);
                dataPoint.CategoryId = c.CategoryId;    // Ensure parent is never changed
            });

            // Get tasks to upsert each new model then await all.
            tasks = new List <Task <DataPoint> >();
            dataPoints.ForEach(m =>
            {
                tasks.Add(Repository.UpsertAsync(m));
            });
            var result = new Result <DataPoint[]>();

            result.Value = (await Task.WhenAll(tasks))?.Where(d => d != null).ToArray();

            // Handle results.
            if (result.Value == null || result.Value.Count() == 0)
            {
                result.Message = "Data points failed to save.";
            }
            else
            {
                result.Message = $"Successfully upserted {result.Value.Count()} of {dataPointsCriteria.Value.Count()} requested data points.";
                result.Success = true;
            }
            return(result);
        }
Пример #19
0
 public void Invalidate()
 {
     IsValid = false;
     ParentRepository.Invalidate();
     OwnerCollection.NotifyValidCountChanged();
 }