Ejemplo n.º 1
0
        /// <summary>
        /// Create interview async
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="dialogflowGeneratedIntentId"></param>
        /// <param name="botResponse"></param>
        /// <param name="createdBy"></param>
        /// <returns></returns>
        public async Task <int> CreateResponseAsync(int userId, string dialogflowGeneratedIntentId, string botResponse, string createdBy)
        {
            try
            {
                Model.Interview interview = new Model.Interview()
                {
                    UserId      = userId,
                    IntentId    = await GetIntentIdByDialogflowGeneratedIntentIdAsync(dialogflowGeneratedIntentId),
                    BotResponse = botResponse,
                    CreatedBy   = createdBy,
                    CreatedOn   = DateTime.Now
                };

                _chatbotDataContext.Interview.Add(interview);
                await _chatbotDataContext.SaveChangesAsync();

                int interviewId = interview.Id;

                return(interviewId);
            }
            catch (Exception)
            {
                return(0);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update interview async
        /// </summary>
        /// <param name="interviewId"></param>
        /// <param name="dialogflowGeneratedIntentId"></param>
        /// <param name="userResponse"></param>
        /// <param name="timeTaken"></param>
        /// <param name="modifiedBy"></param>
        /// <returns></returns>
        public async Task <Response> UpdateResponseAsync(int interviewId, string userResponse, int?timeTaken, string modifiedBy)
        {
            try
            {
                Model.Interview i = await GetInterviewByInterviewIdAsync(interviewId);

                i.UserResponse = userResponse;
                if (timeTaken.HasValue)
                {
                    i.TimeTaken = timeTaken.Value;
                }
                i.ModifiedOn = DateTime.UtcNow.Date;
                i.ModifiedBy = modifiedBy;

                _chatbotDataContext.Interview.Attach(i);
                await _chatbotDataContext.SaveChangesAsync();

                return(Response.Ok());
            }
            catch (Exception)
            {
                return(Response.Fail("InvalidRequest", ResponseType.InvalidRequest));
            }
        }