public List<SubCategoryAdmin> CreateSubCategory(SubCategory subCategory)
        {
            List<SubCategoryAdmin> subcategories = new List<SubCategoryAdmin>();

            int result = 0;
            try
            {
                ctx.SubCategorys.Add(subCategory);
                result = ctx.SaveChanges();
                subcategories = GetAllSubCatAdmin();

                return subcategories;
            }
            catch (SqlException sqlex)
            {
                exceptionMessage = sqlex.Message;
            }
            catch (OASCustomException customex)
            {
                exceptionMessage = customex.Message;
            }
            catch (Exception ex)
            {
                exceptionMessage = ex.Message;
            }
            return subcategories;
        }
        public int CreateUserTest(UserTest usertest)
        {
            int    result = 0;
            string exceptionMessage;

            try
            {
                ctx.UserTests.Add(usertest);
                result = ctx.SaveChanges();
                return(result);
            }
            catch (SqlException sqlex)
            {
                exceptionMessage = sqlex.Message;
            }
            catch (OASCustomException customex)
            {
                exceptionMessage = customex.Message;
            }
            catch (Exception ex)
            {
                exceptionMessage = ex.Message;
            }
            return(result);
        }
Exemple #3
0
        public List <TopicAdmin> CreateTopic(Topic topic)
        {
            List <TopicAdmin> topicslist = new List <TopicAdmin>();

            int result = 0;

            try
            {
                ctx.Topics.Add(topic);
                result     = ctx.SaveChanges();
                topicslist = GetAllTopicAdmin();

                return(topicslist);
            }
            catch (SqlException sqlex)
            {
                exceptionMessage = sqlex.Message;
            }
            catch (OASCustomException customex)
            {
                exceptionMessage = customex.Message;
            }
            catch (Exception ex)
            {
                exceptionMessage = ex.Message;
            }
            return(topicslist);
        }
Exemple #4
0
        public int UpdateQuestionBank(QuestionBank questionBank)
        {
            int result = 0;

            try
            {
                QuestionBank existingQuestionBank = ctx.QuestionBanks.FirstOrDefault(questionbanks => questionbanks.QuestionBankID == questionbanks.QuestionBankID);
                if (existingQuestionBank != null)
                {
                    existingQuestionBank.Question          = questionBank.Question;
                    existingQuestionBank.Option1           = questionBank.Option1;
                    existingQuestionBank.Option2           = questionBank.Option2;
                    existingQuestionBank.Option3           = questionBank.Option3;
                    existingQuestionBank.Option4           = questionBank.Option4;
                    existingQuestionBank.Answer            = questionBank.Answer;
                    existingQuestionBank.DifficultyLevelID = questionBank.DifficultyLevelID;
                    existingQuestionBank.TopicID           = questionBank.TopicID;
                    existingQuestionBank.Marks             = questionBank.Marks;

                    result = ctx.SaveChanges();
                }
                return(result);
            }
            catch (SqlException sqlex)
            {
                exceptionMessage = sqlex.Message;
            }
            catch (OASCustomException customex)
            {
                exceptionMessage = customex.Message;
            }
            catch (Exception ex)
            {
                exceptionMessage = ex.Message;
            }
            return(result);
        }
Exemple #5
0
        public int CreateTest(Test test)
        {
            int result = 0;

            try
            {
                ctx.Tests.Add(test);
                result = ctx.SaveChanges();
                return(result);
            }
            catch (SqlException sqlex)
            {
                exceptionMessage = sqlex.Message;
            }
            catch (OASCustomException customex)
            {
                exceptionMessage = customex.Message;
            }
            catch (Exception ex)
            {
                exceptionMessage = ex.Message;
            }
            return(result);
        }
        public int CreateCategory(Category category)
        {
            int result = 0;

            try
            {
                ctx.Categorys.Add(category);
                result = ctx.SaveChanges();
                return(result);
            }
            catch (SqlException sqlex)
            {
                exceptionMessage = sqlex.Message;
            }
            catch (OASCustomException customex)
            {
                exceptionMessage = customex.Message;
            }
            catch (Exception ex)
            {
                exceptionMessage = ex.Message;
            }
            return(result);
        }
Exemple #7
0
        public int CreateQuestionBank(int id)
        {
            int    result      = 0;
            string excelFile   = null;
            var    httpRequest = HttpContext.Current.Request;
            string filePath    = string.Empty;

            var postedFile = httpRequest.Files[0];

            try
            {
                if (postedFile != null)
                {
                    string path = HttpContext.Current.Server.MapPath("~/Uploads/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    excelFile = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-");
                    excelFile = excelFile + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName);
                    filePath  = path + excelFile;

                    postedFile.SaveAs(filePath);
                    string extension = Path.GetExtension(postedFile.FileName);
                    string conString = string.Empty;
                    switch (extension)
                    {
                    case ".xls":     //Excel 97-03.
                        conString = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
                        break;

                    case ".xlsx":     //Excel 07 and above.
                        conString = ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString;
                        break;

                    default:
                        break;
                    }

                    DataTable dt = new DataTable();
                    conString = string.Format(conString, filePath);

                    using (OleDbConnection connExcel = new OleDbConnection(conString))
                    {
                        using (OleDbCommand cmdExcel = new OleDbCommand())
                        {
                            using (OleDbDataAdapter odaExcel = new OleDbDataAdapter())
                            {
                                cmdExcel.Connection = connExcel;

                                //Get the name of First Sheet.
                                connExcel.Open();
                                DataTable dtExcelSchema;
                                dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                                string sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
                                connExcel.Close();

                                //Read Data from First Sheet.
                                connExcel.Open();
                                cmdExcel.CommandText   = "SELECT * From [" + sheetName + "]";
                                odaExcel.SelectCommand = cmdExcel;
                                odaExcel.Fill(dt);
                                connExcel.Close();
                            }
                        }
                    }

                    //Insert records to database table.
                    OASContext ctx = new OASContext();
                    foreach (DataRow row in dt.Rows)
                    {
                        ctx.QuestionBanks.Add(new QuestionBank
                        {
                            QuestionBankID    = Convert.ToInt32(row["QuestionBankID"]),
                            Question          = Convert.ToString(row["Question"]),
                            Option1           = Convert.ToString(row["Option1"]),
                            Option2           = Convert.ToString(row["Option2"]),
                            Option3           = Convert.ToString(row["Option3"]),
                            Option4           = Convert.ToString(row["Option4"]),
                            Answer            = Convert.ToString(row["Answer"]),
                            Marks             = Convert.ToInt32(row["Marks"]),
                            DifficultyLevelID = Convert.ToInt32(row["DifficultyLevelID"]),
                            //TopicID = Convert.ToInt32(row["TopicID"])
                            TopicID = id
                        });
                    }
                    result = ctx.SaveChanges();
                }
                else
                {
                    return(result);
                }
            }
            catch (SqlException sqlex)
            {
                exceptionMessage = sqlex.Message;
            }
            catch (OASCustomException customex)
            {
                exceptionMessage = customex.Message;
            }
            catch (Exception ex)
            {
                exceptionMessage = ex.Message;
            }
            return(result);
        }