public async Task CanUpdateSession()
        {
            var authorizedClient = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory);

            var updateSessionCommand = new UpdateSessionCommand
            {
                Id          = 1,
                GameId      = 1,
                ClassroomId = 1,
                Name        = "test"
            };

            var serializedUpdateCommand = JsonConvert.SerializeObject(updateSessionCommand);

            // The endpoint or route of the controller action.
            var httpResponse = await authorizedClient.PutAsync(requestUri : "/Session",
                                                               content : new StringContent(content: serializedUpdateCommand,
                                                                                           encoding: Encoding.UTF8,
                                                                                           mediaType: StringConstants.ApplicationJson));

            //Must be successful
            httpResponse.EnsureSuccessStatusCode();

            Assert.True(httpResponse.IsSuccessStatusCode);
            Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateSession(int id, UpdateSessionCommand updateCommand)
        {
            updateCommand.Id = id;
            _ = await Mediator.Send(updateCommand);

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Update(Guid id, UpdateSessionCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
Ejemplo n.º 4
0
        public async Task ShouldThrowErrorWhenInvalidInformation()
        {
            var updateSessionCommand = new UpdateSessionCommand
            {
                UpdatedBy   = _adminUserId,
                TenantId    = _tenantId,
                Id          = _sessionId + 1,
                GameId      = _gameId,
                ClassroomId = _classroomId,
                Name        = "test"
            };

            await Assert.ThrowsAsync <NotFoundException>(async() =>
                                                         await _commandHandler.Handle(updateSessionCommand, CancellationToken.None));
        }
Ejemplo n.º 5
0
        public async Task ShouldGetModelForValidInformation()
        {
            var updateSessionCommand = new UpdateSessionCommand
            {
                UpdatedBy   = _adminUserId,
                TenantId    = _tenantId,
                Id          = _sessionId,
                GameId      = _gameId,
                ClassroomId = _classroomId,
                Name        = "test"
            };

            var sessionResponseModel = await _commandHandler.Handle(updateSessionCommand, CancellationToken.None);

            Assert.Null(sessionResponseModel.Errors);
            Assert.Equal(expected: updateSessionCommand.Name, actual: sessionResponseModel.Items.Single().Name, ignoreCase: true);
        }
Ejemplo n.º 6
0
        public async Task <CommandResult> UpdateSession(UpdateSessionCommand cmd)
        {
            var session = await _db.Sessions.FindAsync(cmd.SessionId);

            if (session == null)
            {
                return(CommandResult.NotFound(cmd, "Session not found."));
            }

            session.Description        = cmd.Description;
            session.OrganizationId     = cmd.OrganizationId;
            session.Overview           = cmd.Overview;
            session.RequestedTimeFrame = cmd.RequestedTimeFrame;
            session.Title = cmd.Title;

            await _db.SaveChangesAsync();

            return(CommandResult.Success(cmd));
        }
Ejemplo n.º 7
0
        public Task <HttpResponseMessage> Put([FromBody] dynamic body)
        {
            List <Job> listJob         = _serviceJob.AddJobToSession(body.job);
            var        user            = _serviceUser.GetOne((string)body.idUser);
            var        coachingProcess = _serviceCoachingProcess.GetOne(Guid.Parse((string)body.idCoachingProcess));

            var session = _serviceSession.GetOne(Guid.Parse((string)body.id));

            session = _serviceJob.CheckJobRemovedOfSession(listJob, session);

            var commandSession = new UpdateSessionCommand(
                Guid.Parse((string)body.id),
                coachingProcess,
                (string)body.theme,
                user,
                (DateTime)body.date,
                (TimeSpan)body.startTime,
                (TimeSpan)body.endTime,
                (ESessionClassification)body.classification,
                (string)body.observation,
                session.Job,
                session.EvaluationCoach,
                session.EvaluationCoachee
                );

            session = _serviceSession.Update(commandSession);
            var listEvaluationCoach = _serviceEvaluationCoach.AddToSession(body.coach, session.Id);

            _serviceEvaluationCoach.CheckEvaluationCoachRemoved(listEvaluationCoach, session.Id);

            var listEvaluationCoachee = _serviceEvaluationCoachee.AddToSession(body.coachee, session.Id);

            _serviceEvaluationCoachee.CheckEvaluationCoacheeRemoved(listEvaluationCoachee, session.Id);

            return(CreateResponse(HttpStatusCode.Created, session));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <ResponseModel <UpdateSessionModel> > > Put([FromBody] UpdateSessionCommand command)
        {
            try
            {
                command.UpdatedBy = Claims[ClaimTypes.Sid].ToInt();
                command.TenantId  = Guid.Parse(Claims[ClaimTypes.UserData]);

                var updateSessionModel = await Mediator.Send(command);

                return(Ok(updateSessionModel));
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
            catch (ObjectAlreadyExistsException ex)
            {
                return(Conflict(new ResponseModel <UpdateSessionModel>(new Error(HttpStatusCode.Conflict, ex))));
            }
            catch
            {
                return(StatusCode(HttpStatusCode.InternalServerError.ToInt()));
            }
        }
        public Session Update(UpdateSessionCommand command)
        {
            var session = _repositorySession.GetOne(command.Id);

            if (command.Classification != 0)
            {
                session.ChangeClassification(command.Classification);
            }
            if (command.Date != DateTime.MinValue)
            {
                session.ChangeDate(command.Date);
            }
            if (command.EndTime != TimeSpan.MinValue)
            {
                session.ChangeEndTime(command.EndTime);
            }
            if (command.StartTime != TimeSpan.MinValue)
            {
                session.ChangeStartTime(command.StartTime);
            }
            if (command.Theme != null)
            {
                session.ChangeTheme(command.Theme);
            }
            if (command.CoachingProcess != null)
            {
                session.ChangeCoachingProcess(command.CoachingProcess);
            }
            if (!string.IsNullOrEmpty(command.Observation))
            {
                session.ChangeObservation(command.Observation);
            }

            if (command.Coach != null)
            {
                foreach (var coach in command.Coach)
                {
                    session.AddEvaluationCoach(coach);
                }
            }

            if (command.Coachee != null)
            {
                foreach (var coachee in command.Coachee)
                {
                    session.AddEvaluationCoachee(coachee);
                }
            }

            if (command.Job != null)
            {
                foreach (var job in command.Job)
                {
                    session.AddJob(job);
                }
            }


            _repositorySession.Update(session);

            if (Commit())
            {
                return(session);
            }

            return(null);
        }
Ejemplo n.º 10
0
 public async Task <IActionResult> UpdateSession([FromBody] UpdateSessionCommand command) =>
 await HandleCommandAsync(command, _commandService.CreateSession);