Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task AddTutorialGroupAsync(TutorialGroup tutorialGroup)
        {
            var course = await this.dbContext.Courses.FindAsync(tutorialGroup.CourseId);

            if (course == null)
            {
                throw new QBotException(HttpStatusCode.NotFound, ErrorCode.CourseNotFound, $"{nameof(this.AddTutorialGroupAsync)}: Course not found!");
            }

            var tutorialGroupEntity = this.mapper.Map <TutorialGroupEntity>(tutorialGroup);

            course.TutorialGroups.Add(tutorialGroupEntity);

            try
            {
                // Save
                await this.dbContext.SaveChangesAsync();
            }
            catch (DbUpdateException exception)
            {
                var message = $"Failed to add tutorial group. Tutorial group: {tutorialGroup.Id}.";
                this.logger.LogError(exception, message);
                throw new QBotException(HttpStatusCode.InternalServerError, ErrorCode.Unknown, message, exception);
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public async Task UpdateTutorialGroupAsync(TutorialGroup tutorialGroup)
        {
            var cachedEntity = await this.dbContext.TutorialGroups.FindAsync(tutorialGroup.Id);

            if (cachedEntity == null)
            {
                throw new QBotException(HttpStatusCode.NotFound, ErrorCode.TutorialGroupNotFound, $"{nameof(this.UpdateTutorialGroupAsync)}: Tutorial group not found!");
            }

            var newEntity = this.mapper.Map <TutorialGroupEntity>(tutorialGroup);

            cachedEntity.DisplayName = newEntity.DisplayName;
            this.dbContext.Update(cachedEntity);

            try
            {
                // Save
                await this.dbContext.SaveChangesAsync();
            }
            catch (DbUpdateException exception)
            {
                var message = $"Failed to update tutorial groups. Tutorial group: {tutorialGroup.Id}.";
                this.logger.LogError(exception, message);
                throw new QBotException(HttpStatusCode.InternalServerError, ErrorCode.Unknown, message, exception);
            }
        }
        /// <inheritdoc/>
        public async Task UpdateTutorialGroupAsync(TutorialGroup tutorialGroup)
        {
            if (!this.tutorialGroupValidator.IsValid(tutorialGroup))
            {
                throw new QBotException(System.Net.HttpStatusCode.BadRequest, ErrorCode.InvalidTutorialGroup, "Invalid tutorial group definition.");
            }

            await this.tutorialGroupRepository.UpdateTutorialGroupAsync(tutorialGroup);
        }
Ejemplo n.º 4
0
    public TutorialGroupOutputs(TutorialManager t, TutorialGroup tutoGroup)
    {
        _tutoManager = t;
        _tutoGroup   = tutoGroup;

        _amountOfFunctionPerListener = new Dictionary <string, int>();
        _currentAmountOfFunctionsTriggeredPerListener = new Dictionary <string, int>();
        _docUICanvas = GameObject.FindObjectOfType <DocUICanvas>();
    }
Ejemplo n.º 5
0
 public async Task <List <TutorialGroupModel> > DeleteTutorialGroup([FromBody] TutorialGroup tutorial)
 {
     try
     {
         return(SQLService.DeleteTutorialGroup(tutorial));
     }
     catch (Exception e)
     {
         Trace.TraceError(e.ToString());
         return(null);
     }
 }
Ejemplo n.º 6
0
 public static List <TutorialGroupModel> DeleteTutorialGroup(TutorialGroup tutorial)
 {
     try
     {
         var tutorialGroups      = SQLAdapter.DeleteTutorialGroup(tutorial);
         var tutorialGroupModels = ModelMapper.MapToTutorialGroupsModel(tutorialGroups);
         return(tutorialGroupModels);
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Ejemplo n.º 7
0
        public async Task <ActionResult <TutorialGroup> > CreateTutorialGroupAsync([FromBody] TutorialGroup tutorialGroup)
        {
            if (tutorialGroup == null)
            {
                this.logger.LogWarning("Invalid request data.");
                return(new BadRequestResult());
            }

            // Authorize
            var course = await this.courseReader.GetCourseAsync(tutorialGroup.CourseId).ConfigureAwait(false);

            await this.authorizationService.AuthorizeAsync(this.User, course, AuthZPolicy.CourseManagerPolicy).ConfigureAwait(false);

            await this.courseSetup.AddTutorialGroupsAsync(tutorialGroup.CourseId, new List <TutorialGroup>() { tutorialGroup });

            return(new OkObjectResult(tutorialGroup));
        }
Ejemplo n.º 8
0
        public static TutorialGroupModel MapToTutorialGroupModel(TutorialGroup tutorialGroup)
        {
            if (tutorialGroup == null)
            {
                return(null);
            }

            return(new TutorialGroupModel()
            {
                ID = tutorialGroup.Id,
                Code = tutorialGroup.Code,
                CourseId = tutorialGroup.CourseId,
                Name = tutorialGroup.Name
                       //Class = tutorialGroup.Class,
                       //Location = tutorialGroup.Location,
            });
        }
Ejemplo n.º 9
0
        /// <inheritdoc/>
        public bool IsValid(TutorialGroup tutorialGroup)
        {
            if (tutorialGroup == null)
            {
                throw new ArgumentNullException(nameof(tutorialGroup));
            }

            if (string.IsNullOrEmpty(tutorialGroup.DisplayName))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(tutorialGroup.CourseId))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(tutorialGroup.ShortCode))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> UpdateTutorialGroupAsync(string tutorialGroupId, [FromBody] TutorialGroup tutorialGroup)
        {
            if (string.IsNullOrEmpty(tutorialGroupId) || tutorialGroup == null || tutorialGroupId != tutorialGroup.Id)
            {
                this.logger.LogWarning("Invalid request data.");
                return(new BadRequestResult());
            }

            // Authorize
            var course = await this.courseReader.GetCourseAsync(tutorialGroup.CourseId).ConfigureAwait(false);

            await this.authorizationService.AuthorizeAsync(this.User, course, AuthZPolicy.CourseManagerPolicy).ConfigureAwait(false);

            await this.tutorialGroupSetup.UpdateTutorialGroupAsync(tutorialGroup);

            return(await Task.FromResult(new StatusCodeResult(204)));
        }
Ejemplo n.º 11
0
 public TutorialGroupActions(TutorialManager t, TutorialGroup g)
 {
     _tutoManager = t;
     _tutoGroup   = g;
     _docUICanvas = GameObject.FindObjectOfType <DocUICanvas>();
 }
Ejemplo n.º 12
0
 void ExecuteGroupActions(TutorialGroup g)
 {
     _gameManager.canPressBackButton = false;
     g.ExecuteActions();
     tutorialGroupsDone.Add(g.tutorialGroupId);
 }