Beispiel #1
0
        /// <summary>
        /// Insert program requirement data.
        /// </summary>
        /// <param name="programRequirement">The program requirement object.</param>
        /// <param name="programCnt">The program requirement count.</param>
        /// <returns>A value indicating the success of the insert.</returns>
        public bool InsertProgramRequirements(ProgramRequirements programRequirement, ref int programCnt)
        {
            bool result = false;

            if (string.IsNullOrEmpty(this.sourceConnection))
            {
                throw new ApplicationException("Connection string is empty or missing.");
            }

            if (programRequirement != null)
            {
                try
                {
                    programCnt += 1;
                    var connection = new SqlConnection(this.sourceConnection);
                    var parameters = new DynamicParameters(programRequirement);

                    using (var conn = connection)
                    {
                        conn.Open();
                        var sproc = "dbo.ProgramRequirements_Ins";
                        var value = connection.Execute(sproc,
                                                       parameters,
                                                       commandType: CommandType.StoredProcedure);

                        result = true;
                    }
                }
                catch (Exception exp)
                {
                    log.Error($"Failed to insert the program requirement. Program Title {programRequirement.ProgramTitle}, Program ID {programRequirement.ProgramID},  exception {exp.Message}");
                }
            }
            else
            {
                throw new ApplicationException("No program requirement data to load.");
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Map Program Requirement data.
        /// </summary>
        /// <param name="fileName">The file name.</param>
        private List <ProgramRequirements> ReadProgramRequirementFile(string fileName)
        {
            List <ProgramRequirements> programsReqs = new List <ProgramRequirements>();

            try
            {
                using (TextFieldParser parser = new TextFieldParser(fileName))
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters(",");
                    bool firstfield = true;

                    while (!parser.EndOfData)
                    {
                        //Process field
                        string[] fields = parser.ReadFields();

                        if (firstfield)
                        {
                            firstfield = false;
                            continue;
                        }

                        int topBlockId;
                        int subBlockId;
                        var programReq       = new ProgramRequirements();
                        var topBlockIdResult = Int32.TryParse(fields[5]?.ToString(), out topBlockId);
                        var subBlockIdResult = Int32.TryParse(fields[6]?.ToString(), out subBlockId);

                        programReq.ProgramID              = fields[0]?.ToString() ?? "";
                        programReq.CatalogYear            = fields[1]?.ToString() ?? "";
                        programReq.ProgramTitle           = fields[2]?.ToString() ?? "";
                        programReq.RequirementDescription = fields[3]?.ToString() ?? "";
                        programReq.RequirementID          = fields[4]?.ToString() ?? "";
                        if (topBlockIdResult)
                        {
                            programReq.topBlockId = topBlockId;
                        }
                        if (subBlockIdResult)
                        {
                            programReq.subBlock = subBlockId;
                        }
                        programReq.ACRB_PRINTED_SPEC          = fields[7]?.ToString().Replace('�', ' ') ?? "";
                        programReq.ACRB_COURSES_CRS_NAME      = fields[8]?.ToString() ?? "";
                        programReq.ACRB_COURSES               = fields[9]?.ToString() ?? "";
                        programReq.ACRB_FROM_COURSES_CRS_NAME = fields[10]?.ToString() ?? "";
                        programReq.ACRB_FROM_COURSES          = fields[11]?.ToString() ?? "";
                        programReq.ACRB_FROM_SUBJECTS         = fields[12]?.ToString() ?? "";
                        programReq.ACRB_ACAD_CRED_RULES       = fields[13]?.ToString() ?? "";
                        programReq.ACRB_MIN_CRED              = fields[14]?.ToString() ?? "";
                        programReq.ACRB_MIN_NO_COURSES        = fields[15]?.ToString() ?? "";
                        programsReqs.Add(programReq);
                    }
                }
                return(programsReqs);
            }
            catch (Exception exp)
            {
                this.Log.Error($"Error occurred reading the program requirement csv file. file {fileName}, exception {exp.Message}");
                return(null);
            }
        }