Пример #1
0
        public async Task <int> AchieveNextTrainingGoal(int trainingId)
        {
            try
            {
                _logger.LogInformation($"Achieving goal the next goal of training {trainingId}");
                var goal = await GetCurrentGoalByTrainingId(trainingId);

                // in case there is nothing to achieve anymore
                if (goal == null)
                {
                    return(await GetTotalGoalsCount(trainingId));
                }
                goal.IsAchieved = true;
                _context.Update(goal);
                await _context.SaveChangesAsync();

                _logger.LogInformation($"Achieved goal order: {goal?.Goal?.Order}");
                return(goal.Goal.Order);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An exception was thrown during achieving training goal.");
                return(0);
            }
        }
Пример #2
0
        public async Task <DbExecutionStatus> Add(ChatSession session)
        {
            try
            {
                _context.ChatSessions.Add(session);
                await _context.SaveChangesAsync();

                var strMsg       = "Hi there, my name is Marley and I'm here to help you. You can ask me questions by using the @marley  tag before the question. If you have a general question about the current training use the #abstract or #general tags before the question. Otherwise, no extra tags are needed and the answer to your question will be a hint based on your progress.";
                var firstMessage = new Message
                {
                    Sender        = Consts.MARLEYNAME,
                    Text          = strMsg,
                    ChatSessionId = session.Id,
                    SessionName   = session.Name,
                    TimeStamp     = DateTime.Now,
                    SenderType    = UserType.Bot
                };
                _context.Messages.Add(firstMessage);
                await _context.SaveChangesAsync();

                return(DbExecutionStatus.Succeeded);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed creating new session {ex}");
                return(DbExecutionStatus.Failed);
            }
        }
Пример #3
0
        public async Task <DbExecutionStatus> Add(Training training)
        {
            try
            {
                // use the following statement so that City won't be inserted
                var newTraining = await _context.Trainings.AddAsync(training);

                _context.Entry(training.Scenario).State = EntityState.Unchanged;
                await _context.SaveChangesAsync();

                return(DbExecutionStatus.Succeeded);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed adding training, exception: {ex}");
                return(DbExecutionStatus.Failed);
            }
        }