Ejemplo n.º 1
0
        public ILessonDto Map(ILessonModel lesson)
        {
            if (lesson == null)
            {
                throw new ArgumentNullException("lesson");
            }

            return new LessonDto
            {
                Date = lesson.Date,
                LessonId = lesson.LessonId,
                GroupId = lesson.Group.GroupId
            };
        }
Ejemplo n.º 2
0
        public void CreateLesson(ILessonModel lesson)
        {
            if (lesson == null)
            {
                throw new ArgumentNullException("lesson");
            }

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

            if (_lessonRepository.GetLessons().Any(l => l.Date == lesson.Date && l.GroupId == lesson.Group.GroupId))
            {
                throw new LessonDateOverlappingException();
            }

            _lessonRepository.CreateLesson(_lessonDtoMapper.Map(lesson));
        }
Ejemplo n.º 3
0
 public void CreateLesson(ILessonModel lesson)
 {
     try
     {
         _lessonService.CreateLesson(lesson);
         _logger.Debug("User created lesson");
     }
     catch (ArgumentNullException)
     {
         _logger.Info("Lesson is null");
     }
     catch (ModelValidationException)
     {
         _logger.Info("Model of lesson is not valid");
     }
     catch (SecurityException)
     {
         _logger.Info("User doesn't have enough permission for created lesson.");
     }
 }
Ejemplo n.º 4
0
        public void CreateLesson(ILessonModel lesson)
        {
            if (lesson == null)
            {
                throw new ArgumentNullException("lesson");
            }

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

            IUserDto user =_userStore.FindByNameAsync(_principal.Identity.Name).Result;
            if (user.GroupId != lesson.Group.GroupId)
            {
                if (!_authorizationManager.CheckAccess(new AuthorizationContext(_principal, "Lesson", "Create")))
                {
                    throw new SecurityException("User doesn't have enough permission for creating lesson");
                }
            }

               _lessonService.CreateLesson(lesson);
        }
Ejemplo n.º 5
0
 public void UpdateLesson(ILessonModel lesson)
 {
     try
     {
         _lessonService.UpdateLesson(lesson);
         _logger.Debug("User updated lesson");
     }
     catch (ArgumentNullException)
     {
         _logger.Info("Lesson is null");
     }
     catch (ModelValidationException)
     {
         _logger.Info("Model of lesson is not valid");
     }
     catch (SecurityException)
     {
         _logger.Info("User doesn't have enough permission for updated lesson.");
     }
     catch (EntityNotFoundException)
     {
         _logger.Info("Lesson not found");
     }
     catch (LessonDateOverlappingException)
     {
         _logger.Info("Lesson date overlapping");
     }
 }
Ejemplo n.º 6
0
 private static LessonViewModel MapLessonToView(ILessonModel l)
 {
     return new LessonViewModel
     {
         LessonId = l.LessonId,
         GroupId = l.Group.GroupId,
         Date = l.Date
     };
 }