Ejemplo n.º 1
0
        public static DataSet TaskCRUD(TaskManagement task)
        {
            DataSet dsresult = new DataSet();

            try
            {
                task.t_SubTasks = task.t_SubTasks.TrimEnd('|');

                if (!string.IsNullOrEmpty(task.t_FileIds))
                {
                    string userProfilePicBase64 = string.Empty;

                    var files = task.t_FileIds.Split(new string[] { "," }, StringSplitOptions.None);

                    if (files.Count() == 1)
                    {
                        userProfilePicBase64 = files[0];
                    }
                    else
                    {
                        userProfilePicBase64 = files[1];
                    }
                    byte[] imageBytes = Convert.FromBase64String(userProfilePicBase64);

                    string fileName = task.t_UserId + "_" + Guid.NewGuid() + "." + Utility.GetFileExtension(userProfilePicBase64);
                    string filePath = HttpContext.Current.Server.MapPath("~/Files/Task/" + fileName);
                    File.WriteAllBytes(filePath, imageBytes);

                    DataSet dsFile = UserBL.CreateFile(fileName, HttpContext.Current.Server.MapPath("~/Files/Task/"), false, "Task", task.t_FileName);
                    if (dsFile.Tables.Count > 0 && dsFile.Tables[0].Rows.Count > 0)
                    {
                        task.t_FileIds = dsFile.Tables[0].Rows[0]["UniqueID"].ToString().Trim();
                    }
                }
                dsresult = TaskDAL.TaskCRUD(task);
            }
            catch (Exception ex)
            {
                Log(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                throw ex;
            }
            return(dsresult);
        }
Ejemplo n.º 2
0
        public static DataSet SubmitAnswers(int compId, string userId, int surveyId, JObject responseDetail)
        {
            DataSet ds = new DataSet();

            try
            {
                List <Question> questionAnswerList = new List <Question>();
                var             dataSet            = GetContentDetails(compId, userId, Convert.ToInt32(responseDetail["TopicID"]),
                                                                       Convert.ToInt32(responseDetail["ModuleID"]), Convert.ToInt32(responseDetail["ContentID"]), ref questionAnswerList);

                double totalScore        = 0;
                double passingPercentage = 0;
                if (Convert.ToString(responseDetail["ContentType"]) != "SURVEY")
                {
                    totalScore = Convert.ToDouble(dataSet.Tables[0].Rows[0]["TotalScore"].ToString());
                }

                if (Convert.ToString(responseDetail["ContentType"]) == "FINALQUIZ")
                {
                    passingPercentage = Convert.ToDouble(dataSet.Tables[0].Rows[0]["PassingPercent"].ToString());
                }

                double scoreEarned = 0, percentageEarned = 0;
                List <AnswerOption> lstAnswers = new List <AnswerOption>();


                // Flashcard & Final Quiz
                for (int i = 0; i < responseDetail["Questions"].Count(); i++)
                {
                    bool   isCorrect      = false;
                    double correctScore   = 0;
                    double inCorrectScore = 0;
                    var    questionid     = Convert.ToInt32(responseDetail["Questions"][i]["QuestionID"]);
                    var    answerIds      = Convert.ToString(responseDetail["Questions"][i]["AnswerIDs"]);
                    var    value_text     = Convert.ToString(responseDetail["Questions"][i]["Value_Text"]);

                    var answer = questionAnswerList.SingleOrDefault(p => p.QuestionID == questionid);
                    if (answer != null)
                    {
                        // Single Select
                        if (answer.QuestionTypeID == 2 || answer.QuestionTypeID == 3)
                        {
                            var correctAnswer = answer.AnswerOptions.SingleOrDefault(p => p.AnswerID == Convert.ToInt32(answerIds));
                            if (correctAnswer != null)
                            {
                                if (correctAnswer.IsCorrect)
                                {
                                    // Correct Answer
                                    correctScore = correctAnswer.CorrectScore;
                                    isCorrect    = true;
                                }
                                else
                                {
                                    // Incorrect Answer
                                    inCorrectScore = correctAnswer.InCorrectScore;
                                    isCorrect      = false;
                                }
                                AnswerOption ansOption = new AnswerOption();
                                ansOption.QuestionID     = questionid;
                                ansOption.Value_Text     = value_text;
                                ansOption.AnswerID       = correctAnswer.AnswerID;
                                ansOption.IsCorrect      = isCorrect;
                                ansOption.CorrectScore   = correctAnswer.CorrectScore;
                                ansOption.InCorrectScore = correctAnswer.InCorrectScore;
                                lstAnswers.Add(ansOption);
                            }
                        }
                        // Multiple Select
                        else if (answer.QuestionTypeID == 1)
                        {
                            var selectedAnswerIds = answerIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            var allAnswers        = answer.AnswerOptions;
                            foreach (var answerOption in allAnswers)
                            {
                                if (selectedAnswerIds.Contains(answerOption.AnswerID.ToString()))
                                {
                                    if (answerOption.IsCorrect)
                                    {
                                        // Correct Answer
                                        correctScore += answerOption.CorrectScore;
                                        isCorrect     = true;
                                    }
                                    else
                                    {
                                        // Incorrect Answer
                                        inCorrectScore += answerOption.InCorrectScore;
                                        isCorrect       = false;
                                    }
                                    AnswerOption ansOption = new AnswerOption();
                                    ansOption.QuestionID     = questionid;
                                    ansOption.Value_Text     = value_text;
                                    ansOption.AnswerID       = answerOption.AnswerID;
                                    ansOption.IsCorrect      = isCorrect;
                                    ansOption.CorrectScore   = answerOption.CorrectScore;
                                    ansOption.InCorrectScore = answerOption.InCorrectScore;
                                    lstAnswers.Add(ansOption);
                                }
                            }
                        }
                        else
                        {
                            AnswerOption ansOption = new AnswerOption();
                            if (answer.QuestionTypeID == 4) //File Upload
                            {
                                var userProfilePicBase64 = "";
                                var base64Image          = Convert.ToString(responseDetail["Questions"][i]["Base64"]);
                                if (!string.IsNullOrEmpty(base64Image))
                                {
                                    var files = base64Image.Split(new string[] { "," }, StringSplitOptions.None);
                                    if (files.Count() == 1)
                                    {
                                        userProfilePicBase64 = files[0];
                                    }
                                    else
                                    {
                                        userProfilePicBase64 = files[1];
                                    }
                                    byte[] imageBytes = Convert.FromBase64String(userProfilePicBase64);
                                    string fileName   = Guid.NewGuid() + "." + Utility.GetFileExtension(userProfilePicBase64);
                                    string filePath   = HttpContext.Current.Server.MapPath("~/Files/Survey/" + fileName);
                                    File.WriteAllBytes(filePath, imageBytes);

                                    DataSet dsFile = UserBL.CreateFile("~/Files/Survey/" + fileName, filePath, false, "ProfilePic");
                                    if (dsFile.Tables.Count > 0 && dsFile.Tables[0].Rows.Count > 0)
                                    {
                                        ansOption.FileID = Convert.ToInt32(dsFile.Tables[0].Rows[0]["UniqueID"].ToString());
                                    }
                                }
                            }
                            ansOption.QuestionID = questionid;
                            ansOption.Value_Text = value_text;
                            lstAnswers.Add(ansOption);
                        }
                    }
                    scoreEarned += correctScore - inCorrectScore;
                }

                if (totalScore == 0)
                {
                    percentageEarned = 0;
                }
                else
                {
                    percentageEarned = (scoreEarned / totalScore) * 100;
                }

                var isPassed = false;
                if (percentageEarned >= passingPercentage)
                {
                    isPassed = true;
                }

                //Submit response in DB
                ds = TrainningDAL.SubmitResponse(compId, userId, surveyId, totalScore, scoreEarned, percentageEarned, isPassed, Utility.GetClientIPaddress());

                if (ds.Tables.Count > 0)
                {
                    // Call SubmitAnswers
                    var fileId     = 0;
                    var responseId = Convert.ToInt32(ds.Tables[0].Rows[0]["ResponseID"]);
                    foreach (var answer in lstAnswers)
                    {
                        TrainningDAL.SubmitAnswers(compId, userId, surveyId, responseId, answer.QuestionID, answer.AnswerID, fileId,
                                                   answer.Value_Text, answer.IsCorrect, answer.CorrectScore, answer.InCorrectScore, "");
                    }
                }
            }
            catch (Exception ex)
            {
                Log(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
            return(ds);
        }