コード例 #1
0
        public async Task <ComponentResponseDto> SaveComponent(ComponentRequestDto componentRequest)
        {
            var lastItem = _repository.GetComponentsByModule(componentRequest.ModuleId).OrderByDescending(e => e.Order).FirstOrDefault();
            var order    = lastItem == null ? 0 : (lastItem.Order + 1);

            var component      = _mapper.Map <Component>((componentRequest, order));
            var savedComponent = await _repository.SaveComponent(component);

            var componentResponse = _mapper.Map <ComponentResponseDto>(savedComponent);

            return(componentResponse);
        }
        public override ValidationResult Validate(SessionRequestDto entity)
        {
            var validation = base.Validate(entity);

            if (validation.Errors.Any())
            {
                return(validation);
            }

            var hasComponent = _componentRepository.GetComponentsByModule(entity.ModuleId);

            if (!hasComponent.Any())
            {
                validation.Errors.Add("You can't open a session without any components");
            }

            var classroomByModule = _classroomRepository.GetClassroomByModule(entity.ModuleId);

            if (classroomByModule == null)
            {
                validation.Errors.Add($"No classroom was assigned to {entity.ModuleId}");
            }

            var session = _repository.GetOpenSessions(entity.ModuleId).ToList();

            if (session.Count >= 1)
            {
                validation.Errors.Add($"A session for {entity.ModuleId} was already opened");
            }


            return(validation);
        }