Beispiel #1
0
 public VisitPresenter(IVisitView visitView)
 {
     this.visitView = visitView;
     visitModel = new VisitModel();
     visitView.LoadForm += LoadVisits;
     visitView.ClearClick += LoadVisits;
     visitView.SearchClick += SearchVisits;
 }
Beispiel #2
0
 public VisitPresenter(IVisitView visitView)
 {
     this.visitView         = visitView;
     visitModel             = new VisitModel();
     visitView.LoadForm    += LoadVisits;
     visitView.ClearClick  += LoadVisits;
     visitView.SearchClick += SearchVisits;
 }
Beispiel #3
0
        public IVisitDto Map(IVisitModel visit)
        {
            if (visit == null)
            {
                throw new ArgumentNullException("visit");
            }

            return new VisitDto
            {
                LessonId = visit.Lesson.LessonId,
                Note = visit.Note,
                Status = visit.Status,
                UserId = visit.Visitor.UserId
            };
        }
Beispiel #4
0
        public async Task UpdateVisitAsync(IVisitModel visit)
        {
            if (visit == null)
            {
                throw new ArgumentNullException("visit");
            }

            EntityValidationResult result = _entityValidator.ValidateEntity(visit);
            if (result.IsValid == false)
            {
                throw new InvalidVisitException(result.ValidationResults);
            }

            IUserDto user = await _userRepository.GetUserById(visit.Visitor.UserId);
            if (user == null)
            {
                throw new InvalidVisitException(new[] {new ValidationResult("Visitor does not exists") });
            }

            ILessonDto lesson = _lessonRepository.GetLessonById(visit.Lesson.LessonId);
            if (lesson == null)
            {
                throw new InvalidVisitException(new[] { new ValidationResult("Lesson does not exists") });
            }

            IVisitDto visitDto = await _visitRepository.GetVisitAsync(user.UserId, lesson.LessonId);
            if (visitDto == null)
            {
                _visitRepository.CreateVisit(_visitDtoMapper.Map(visit));
            }
            else
            {
                await _visitRepository.UpdateVisitAsync(_visitDtoMapper.Map(visit));
            }
        }
        public Task UpdateVisitAsync(IVisitModel visit)
        {
            if (visit == null)
            {
                throw new ArgumentNullException("visit");
            }

            EntityValidationResult result = _entityValidator.ValidateEntity(visit);
            if (result.IsValid == false)
            {
                throw new InvalidLessonException(result.ValidationResults);
            }

            IUserDto user = _userStore.FindByNameAsync(_principal.Identity.Name).Result;
            if (_authorizationManager.CheckAccess(new AuthorizationContext(_principal, "Visit", "Update")))
            {
                if (user.GroupId == null)
                {
                    throw new SecurityException("User doesn't have enough permission for update visit");
                }
            }

            return  _visitService.UpdateVisitAsync(visit);
        }