protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.HasDefaultSchema("StudyTraining");

            AnswerMapping.Configure(builder);
            QuestionMapping.Configure(builder);
            SubjectMapping.Configure(builder);
        }
示例#2
0
 public ActionResult HasDeleteAccess(int id)
 {
     try
     {
         if (isAdmin)
         {
             object          response;
             var             data = (from cat in _auditToolContext.QuestionMapping.Where(a => a.IsActive == true) select cat).ToList();
             QuestionMapping obj  = data.Find(a => a.SubCatgId == id);
             response = obj == null ? "NoRecords" : "HasRecords";
             return(Json(response));
         }
     }
     catch (Exception ex)
     {
         _logger.LogInformation($"Exception in HasDeleteAccess method");
         _log.WriteErrorLog(new LogItem {
             ErrorType = "Error", ErrorSource = "SubCategoryController_HasDeleteAccess", ErrorDiscription = ex.InnerException != null ? ex.InnerException.ToString() : ex.Message
         });
     }
     return(RedirectToAction("Index", "Home"));
 }
        public JsonResult SaveQuestionForMaster(string subcatgid)
        {
            if (isAdmin)
            {
                try
                {
                    if (subcatgid.Contains('^'))
                    {
                        string[] data = subcatgid.Split('^');
                        if (data.Any() && data[0] != null && data[1] != null && data[2] != null && data[3] != null)
                        {
                            var questionbankdata = _auditToolContext.QuestionBank.Where(x => x.QuestionName.Trim() == data[1].ToString().Trim() &&
                                                                                        x.IsActive == true).FirstOrDefault();
                            if (questionbankdata == null)//condition to restrict questions which is not available in questionBank table
                            {
                                QuestionBank objNewQuestion = new QuestionBank();
                                objNewQuestion.QuestionName        = data[1].ToString().Trim();
                                objNewQuestion.QuestionDescription = data[2].ToString().Trim();
                                objNewQuestion.IsActive            = true;
                                objNewQuestion.CreatedBy           = _authService.LoggedInUserInfo().Result.LoggedInFullName;
                                objNewQuestion.CreatedDate         = DateTime.Now;
                                objNewQuestion.ModifiedBy          = _authService.LoggedInUserInfo().Result.LoggedInFullName;
                                objNewQuestion.ModifiedDate        = DateTime.Now;
                                _auditToolContext.QuestionBank.Add(objNewQuestion);
                                _auditToolContext.SaveChanges();
                                questionbankdata = objNewQuestion;
                            }
                            QuestionMapping objtbQuestionMaster = new QuestionMapping();
                            objtbQuestionMaster.QuestionId   = questionbankdata.QuestionId;
                            objtbQuestionMaster.SubCatgId    = Convert.ToInt32(data[0]);
                            objtbQuestionMaster.SeqNumber    = Convert.ToInt32(data[3]);
                            objtbQuestionMaster.CreatedBy    = _authService.LoggedInUserInfo().Result.LoggedInFullName;
                            objtbQuestionMaster.CreatedDate  = DateTime.Now;
                            objtbQuestionMaster.ModifiedBy   = _authService.LoggedInUserInfo().Result.LoggedInFullName;
                            objtbQuestionMaster.ModifiedDate = DateTime.Now;
                            objtbQuestionMaster.IsActive     = true;
                            _logger.LogInformation($"Request for Adding Question to DB with SubCategoryID: {data[0]} and Question Text as: {data[1]}");

                            _auditToolContext.QuestionMapping.Add(objtbQuestionMaster);
                            int insertstatus = _auditToolContext.SaveChanges();
                            if (insertstatus > 0)
                            {
                                _logger.LogInformation($"Inserted Sucessfully.");
                            }
                            else
                            {
                                _logger.LogInformation($"Inserted failed.");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogInformation($"Exception in SaveQuestionForMaster method");
                    _log.WriteErrorLog(new LogItem {
                        ErrorType = "Error", ErrorSource = "QuestionsController_SaveQuestionForMaster", ErrorDiscription = ex.InnerException != null ? ex.InnerException.ToString() : ex.Message
                    });
                }

                return(Json(""));
            }
            else
            {
                return(Json(new { Success = "False", responseText = "Authorization Error" }));
            }
        }
        public JsonResult CopyQuestionMappingToCategory(string subCategoryId, string categoryId)
        {
            _logger.LogInformation($"Request to Insert Subcategory for {subCategoryId} and its Question Mapping to Category: {categoryId}");
            try
            {
                if (isAdmin)
                {
                    var subCat = _auditToolContext.SubCategory.Where(a => a.SubCatgId == Convert.ToInt32(subCategoryId) && a.IsActive == true).FirstOrDefault();

                    if (subCat != null && Convert.ToInt32(categoryId) > 0)
                    {
                        SubCategory category = new SubCategory
                        {
                            CatgId             = Convert.ToInt32(categoryId),
                            CreatedBy          = _authService.LoggedInUserInfo().Result.LoggedInFullName,
                            CreatedDate        = DateTime.Now,
                            ModifiedBy         = _authService.LoggedInUserInfo().Result.LoggedInFullName,
                            ModifiedDate       = DateTime.Now,
                            IsActive           = true,
                            SubCatgDescription = subCat.SubCatgDescription
                        };

                        _auditToolContext.SubCategory.Add(category);

                        var questionMapping = _auditToolContext.QuestionMapping.Where(a => a.SubCatgId == subCat.SubCatgId && a.IsActive == true).ToList();

                        foreach (var item in questionMapping)
                        {
                            QuestionMapping question = new QuestionMapping
                            {
                                SubCatg      = category,
                                SeqNumber    = item.SeqNumber,
                                QuestionId   = item.QuestionId,
                                IsActive     = true,
                                CreatedBy    = _authService.LoggedInUserInfo().Result.LoggedInFullName,
                                CreatedDate  = DateTime.Now,
                                ModifiedBy   = _authService.LoggedInUserInfo().Result.LoggedInFullName,
                                ModifiedDate = DateTime.Now
                            };

                            _auditToolContext.QuestionMapping.Add(question);
                        }

                        int insertstatus = _auditToolContext.SaveChanges();
                        if (insertstatus > 0)
                        {
                            _logger.LogInformation($"Inserted Sucessfully.");
                        }
                        else
                        {
                            _logger.LogInformation($"Inserted failed.");
                        }
                        return(Json(""));
                    }
                    else
                    {
                        return(Json(new { Success = "False", responseText = "Subcategory not Found" }));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation($"Exception in CopyQuestionMappingToCategory method");
                _log.WriteErrorLog(new LogItem {
                    ErrorType = "Error", ErrorSource = "QuestionsController_CopyQuestionMappingToCategory", ErrorDiscription = ex.InnerException != null ? ex.InnerException.ToString() : ex.Message
                });
            }
            return(Json(new { Success = "False", responseText = "Authorization Error" }));
        }