Esempio n. 1
0
        public long SaveUpdateLessonPlanner(LessonPlannerModel lessonPlannerModel)
        {
            long result = 0;

            if (lessonPlannerModel != null)
            {
                if (lessonPlannerModel.LessonPlannerID == 0)  //Add
                {
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append("DECLARE @SeedValue INT ");
                    strSql.Append("SET @SeedValue = (SELECT ISNULL(MAX(LessonPlannerID), 0) FROM dbo.LessonPlanner) ");
                    strSql.Append("DBCC CHECKIDENT('dbo.LessonPlanner',RESEED,@SeedValue)");
                    strSql.Append("INSERT INTO LessonPlanner(");
                    strSql.Append("GradeID,Grade,SubjectID,Introduction,Objectives,");
                    strSql.Append("Material,CreatedOn,CreatedBy,ModifiedOn,ModifiedBy)");
                    strSql.Append(" VALUES (");
                    strSql.Append("@GradeID,@Grade,@SubjectID,@Introduction,@Objectives,@Material,");
                    strSql.Append("@CreatedOn,@CreatedBy,@ModifiedOn,@ModifiedBy)");
                    strSql.Append(";SELECT SCOPE_IDENTITY()");
                    SqlParameter[] parameters =
                    {
                        new SqlParameter("@GradeID",      SqlDbType.BigInt),
                        new SqlParameter("@Grade",        SqlDbType.NVarChar, 300),
                        new SqlParameter("@SubjectID",    SqlDbType.BigInt),
                        new SqlParameter("@Introduction", SqlDbType.NVarChar,  -1),
                        new SqlParameter("@Objectives",   SqlDbType.NVarChar,  -1),
                        new SqlParameter("@Material",     SqlDbType.NVarChar,  -1),
                        new SqlParameter("@CreatedOn",    SqlDbType.DateTime),
                        new SqlParameter("@CreatedBy",    SqlDbType.Int),
                        new SqlParameter("@ModifiedOn",   SqlDbType.DateTime),
                        new SqlParameter("@ModifiedBy",   SqlDbType.Int)
                    };
                    parameters[0].Value = lessonPlannerModel.GradeID;
                    parameters[1].Value = lessonPlannerModel.GradeName;
                    parameters[2].Value = lessonPlannerModel.SubjectID;
                    parameters[3].Value = lessonPlannerModel.Introduction;
                    parameters[4].Value = lessonPlannerModel.Objectives;
                    parameters[5].Value = lessonPlannerModel.Material;
                    parameters[6].Value = lessonPlannerModel.CreatedOn;
                    parameters[7].Value = lessonPlannerModel.CreatedBy;
                    parameters[8].Value = lessonPlannerModel.ModifiedOn;
                    parameters[9].Value = lessonPlannerModel.ModifiedBy;

                    object obj = DbHelper.GetSingle(strSql.ToString(), parameters);
                    if (obj == null)
                    {
                        result = 0;
                    }
                    else
                    {
                        result = Convert.ToInt64(obj);
                    }
                }
                else
                {
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append("UPDATE LessonPlanner SET ");
                    strSql.Append("GradeID=@GradeID,Grade=@Grade,SubjectID=@SubjectID,");
                    strSql.Append("Introduction=@Introduction,Objectives=@Objectives,");
                    strSql.Append("Material=@Material,ModifiedOn=@ModifiedOn,ModifiedBy=@ModifiedBy");
                    strSql.Append(" where LessonPlannerID=@LessonPlannerID");

                    SqlParameter[] parameters =
                    {
                        new SqlParameter("@GradeID",         SqlDbType.Int),
                        new SqlParameter("@Grade",           SqlDbType.NVarChar, 300),
                        new SqlParameter("@SubjectID",       SqlDbType.Int),
                        new SqlParameter("@Introduction",    SqlDbType.NVarChar,  -1),
                        new SqlParameter("@Objectives",      SqlDbType.NVarChar,  -1),
                        new SqlParameter("@Material",        SqlDbType.NVarChar,  -1),
                        new SqlParameter("@CreatedOn",       SqlDbType.DateTime),
                        new SqlParameter("@CreatedBy",       SqlDbType.Int),
                        new SqlParameter("@ModifiedOn",      SqlDbType.DateTime),
                        new SqlParameter("@ModifiedBy",      SqlDbType.Int),
                        new SqlParameter("@LessonPlannerID", SqlDbType.BigInt, 4)
                    };
                    parameters[0].Value  = lessonPlannerModel.GradeID;
                    parameters[1].Value  = lessonPlannerModel.GradeName;
                    parameters[2].Value  = lessonPlannerModel.SubjectID;
                    parameters[3].Value  = lessonPlannerModel.Introduction;
                    parameters[4].Value  = lessonPlannerModel.Objectives;
                    parameters[5].Value  = lessonPlannerModel.Material;
                    parameters[6].Value  = lessonPlannerModel.CreatedOn;
                    parameters[7].Value  = lessonPlannerModel.CreatedBy;
                    parameters[8].Value  = lessonPlannerModel.ModifiedOn;
                    parameters[9].Value  = lessonPlannerModel.ModifiedBy;
                    parameters[10].Value = lessonPlannerModel.LessonPlannerID;

                    result = DbHelper.ExecuteSql(strSql.ToString(), parameters);
                    result = lessonPlannerModel.LessonPlannerID;
                }
            }

            if (result > 0)
            {
                AddUpdateMainTopic(lessonPlannerModel, result);
            }

            return(result);
        }
Esempio n. 2
0
        public long AddUpdateMainTopic(LessonPlannerModel lessonPlannerModel, long lessonPlannerID)
        {
            long result = 0;

            if (lessonPlannerModel != null)
            {
                if (lessonPlannerModel.MainTopicID == 0)  //Add
                {
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append("DECLARE @SeedValue INT ");
                    strSql.Append("SET @SeedValue = (SELECT ISNULL(MAX(MainTopicID), 0) FROM dbo.MainTopic) ");
                    strSql.Append("DBCC CHECKIDENT('dbo.MainTopic',RESEED,@SeedValue)");
                    strSql.Append("INSERT INTO MainTopic(");
                    strSql.Append("MainTopicNumber,MainTopicTitle,LessonPlannerID,Introduction,Objectives,Material,");
                    strSql.Append("CreatedOn,CreatedBy,ModifiedOn,ModifiedBy)");
                    strSql.Append(" VALUES (");
                    strSql.Append("@MainTopicNumber,@MainTopicTitle,@LessonPlannerID,@Introduction,@Objectives,@Material,");
                    strSql.Append("@CreatedOn,@CreatedBy,@ModifiedOn,@ModifiedBy)");
                    strSql.Append(";SELECT SCOPE_IDENTITY()");

                    SqlParameter[] parameters =
                    {
                        new SqlParameter("@MainTopicNumber", SqlDbType.NVarChar,  50),
                        new SqlParameter("@MainTopicTitle",  SqlDbType.NVarChar,  -1),
                        new SqlParameter("@LessonPlannerID", SqlDbType.BigInt),
                        new SqlParameter("@Introduction",    SqlDbType.NVarChar,  -1),
                        new SqlParameter("@Objectives",      SqlDbType.NVarChar,  -1),
                        new SqlParameter("@Material",        SqlDbType.NVarChar,  -1),
                        new SqlParameter("@CreatedOn",       SqlDbType.DateTime),
                        new SqlParameter("@CreatedBy",       SqlDbType.Int),
                        new SqlParameter("@ModifiedOn",      SqlDbType.DateTime),
                        new SqlParameter("@ModifiedBy",      SqlDbType.Int)
                    };
                    parameters[0].Value = lessonPlannerModel.MainTopicNumber;
                    parameters[1].Value = lessonPlannerModel.TitleMainTopic;
                    parameters[2].Value = lessonPlannerID;
                    parameters[3].Value = lessonPlannerModel.Introduction;
                    parameters[4].Value = lessonPlannerModel.Objectives;
                    parameters[5].Value = lessonPlannerModel.Material;
                    parameters[6].Value = lessonPlannerModel.CreatedOn;
                    parameters[7].Value = lessonPlannerModel.CreatedBy;
                    parameters[8].Value = lessonPlannerModel.ModifiedOn;
                    parameters[9].Value = lessonPlannerModel.ModifiedBy;

                    object obj = DbHelper.GetSingle(strSql.ToString(), parameters);
                    if (obj == null)
                    {
                        result = 0;
                    }
                    else
                    {
                        result = Convert.ToInt64(obj);
                    }
                }
                else
                {
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append("UPDATE MainTopic SET ");
                    strSql.Append("MainTopicNumber=@MainTopicNumber,MainTopicTitle=@MainTopicTitle,");
                    strSql.Append("LessonPlannerID=@LessonPlannerID,Introduction=@Introduction,Objectives=@Objectives,");
                    strSql.Append("Material=@Material,ModifiedOn=@ModifiedOn,ModifiedBy=@ModifiedBy");
                    strSql.Append(" where MainTopicID=@MainTopicID");

                    SqlParameter[] parameters =
                    {
                        new SqlParameter("@MainTopicNumber", SqlDbType.NVarChar,  50),
                        new SqlParameter("@MainTopicTitle",  SqlDbType.NVarChar,  -1),
                        new SqlParameter("@LessonPlannerID", SqlDbType.BigInt),
                        new SqlParameter("@Introduction",    SqlDbType.NVarChar,  -1),
                        new SqlParameter("@Objectives",      SqlDbType.NVarChar,  -1),
                        new SqlParameter("@Material",        SqlDbType.NVarChar,  -1),
                        new SqlParameter("@CreatedOn",       SqlDbType.DateTime),
                        new SqlParameter("@CreatedBy",       SqlDbType.Int),
                        new SqlParameter("@ModifiedOn",      SqlDbType.DateTime),
                        new SqlParameter("@ModifiedBy",      SqlDbType.Int),
                        new SqlParameter("@MainTopicID",     SqlDbType.BigInt),
                    };
                    parameters[0].Value  = lessonPlannerModel.MainTopicNumber;
                    parameters[1].Value  = lessonPlannerModel.TitleMainTopic;
                    parameters[2].Value  = lessonPlannerModel.LessonPlannerID;
                    parameters[3].Value  = lessonPlannerModel.Introduction;
                    parameters[4].Value  = lessonPlannerModel.Objectives;
                    parameters[5].Value  = lessonPlannerModel.Material;
                    parameters[6].Value  = lessonPlannerModel.CreatedOn;
                    parameters[7].Value  = lessonPlannerModel.CreatedBy;
                    parameters[8].Value  = lessonPlannerModel.ModifiedOn;
                    parameters[9].Value  = lessonPlannerModel.ModifiedBy;
                    parameters[10].Value = lessonPlannerModel.MainTopicID;

                    result = DbHelper.ExecuteSql(strSql.ToString(), parameters);
                    result = lessonPlannerModel.MainTopicID;
                }

                if (result > 0)
                {
                    DataTable dataTableSubTopics = TranslateSubToicListToDataTable(lessonPlannerModel.subTopicModels, result);

                    DataTable dataTableGames = TranslateGamesListToDataTable(lessonPlannerModel.gamesModels, result);

                    DataTable dataTableMovies = TranslateMoviesListToDataTable(lessonPlannerModel.moviesModels, result);

                    DataTable dataTableDocumentaries = TranslateDocumentariesListToDataTable(lessonPlannerModel.documentariesModels, result);

                    DataTable dataTableBooks = TranslateBooksListToDataTable(lessonPlannerModel.booksModels, result);

                    SaveSubTopicsAndExtras(dataTableSubTopics, dataTableGames, dataTableMovies, dataTableDocumentaries, dataTableBooks);
                }
            }



            return(result);
        }