Exemple #1
0
        /// <summary>
        /// Add Learning Story
        /// </summary>
        public int AddItem(LearningStory learningStory, LearningStoryItem item, HeaderInfo _headerInfo)
        {
            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                int nextItemUID = CommonDB.GetLastUID("learningstoryitem") + 1;

                var commandString =
                    (

                        " INSERT INTO learningstoryitem " +
                        " (UID, " +
                        " FKLearningStoryUID, " +
                        " FKCodeType, " +
                        " FKCodeValue " +
                        " )" +
                        " VALUES " +
                        "( " +
                        "  @UID " +
                        " ,@FKLearningStoryUID " +
                        " ,@FKCodeType " +
                        " ,@FKCodeValue " +
                        " )"
                    );

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    command.Parameters.AddWithValue("@UID", nextItemUID);
                    command.Parameters.AddWithValue("@FKLearningStoryUID", learningStory.UID);
                    command.Parameters.AddWithValue("@FKCodeType", item.FKCodeType);
                    command.Parameters.AddWithValue("@FKCodeValue", item.FKCodeValue);

                    try
                    {
                        connection.Open();
                        command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        LogFile.WriteToTodaysLogFile(ex.ToString(), _headerInfo.UserID);

                        var respError = new LearningStory.LearningStoryAddResponse();
                        respError.responseStatus            = new ResponseStatus();
                        respError.responseStatus.ReturnCode = -0025;
                        respError.responseStatus.ReasonCode = 0002;
                        respError.responseStatus.Message    = "Error adding Learning Story Item. " + ex;
                    }
                }
            }

            return(UID);
        }
Exemple #2
0
        /// <summary>
        /// List clients
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="_FKLearningStoryUID"> </param>
        /// <param name="_headerInfo"> </param>
        public static List <LearningStoryItem> ListItem(int _FKLearningStoryUID, string codeType)
        {
            List <LearningStoryItem> ret = new List <LearningStoryItem>();

            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                var commandString = string.Format(
                    " SELECT " +
                    "  UID, " +
                    " FKLearningStoryUID, " +
                    " FKCodeType, " +
                    " FKCodeValue " +
                    "   FROM LearningStoryItem " +
                    "  WHERE FKLearningStoryUID = @FKLearningStoryUID and FKCodeType = @codeType" +
                    "  ORDER BY UID ASC "
                    );

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    command.Parameters.AddWithValue("@FKLearningStoryUID", _FKLearningStoryUID);
                    command.Parameters.AddWithValue("@codeType", codeType);

                    connection.Open();

                    try
                    {
                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var item = new LearningStoryItem();
                                item.UID = Convert.ToInt32(reader["UID"]);
                                item.FKLearningStoryUID = Convert.ToInt32(reader["FKLearningStoryUID"]);
                                item.FKCodeType         = reader["FKCodeType"] as string;
                                item.FKCodeValue        = reader["FKCodeValue"] as string;

                                ret.Add(item);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string error = ex.ToString();
                        LogFile.WriteToTodaysLogFile(ex.ToString(), "", "", "Client.cs");
                    }
                }
            }

            return(ret);
        }
Exemple #3
0
        /// <summary>
        /// Load object
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="learningStory"></param>
        private static void LoadObject(MySqlDataReader reader, LearningStory learningStory, bool includeOutcome)
        {
            learningStory.UID                 = Convert.ToInt32(reader[FieldName.UID]);
            learningStory.FKChildUID          = Convert.ToInt32(reader[FieldName.FKChildUID]);
            learningStory.FKRoomCode          = reader[FieldName.FKRoomCode] as string;
            learningStory.FKEducatorUID       = Convert.ToInt32(reader[FieldName.FKEducatorUID]);
            learningStory.Date                = Convert.ToDateTime((reader[FieldName.Date]));
            learningStory.Story               = reader[FieldName.Story] as string;
            learningStory.AnalysisOfLearning  = reader[FieldName.AnalysisOfLearning] as string;
            learningStory.ExtensionOfLearning = reader[FieldName.ExtensionOfLearning] as string;
            learningStory.ParentsComments     = reader[FieldName.ParentsComments] as string;
            // -----------------------------------------------------------------------------------------
            learningStory.UpdateDateTime   = Convert.ToDateTime((reader[FieldName.UpdateDateTime]));
            learningStory.UserIdUpdatedBy  = reader[FieldName.UserIdUpdatedBy] as string;
            learningStory.CreationDateTime = Convert.ToDateTime((reader[FieldName.CreationDateTime]));
            learningStory.UserIdCreatedBy  = reader[FieldName.UserIdCreatedBy] as string;
            learningStory.RecordVersion    = Convert.ToInt32(reader[FieldName.RecordVersion]);
            learningStory.IsVoid           = reader[FieldName.IsVoid] as string;

            learningStory.child     = new Child();
            learningStory.child.UID = learningStory.FKChildUID;
            learningStory.child.Read();

            learningStory.educator     = new Educator();
            learningStory.educator.UID = learningStory.FKEducatorUID;
            learningStory.educator.Read();

            // Loading outcomes, practices and principles
            //
            if (includeOutcome)
            {
                learningStory.LearningOutcomes = LearningStoryItem.ListItem(learningStory.UID, "LESI");
                learningStory.Principles       = LearningStoryItem.ListItem(learningStory.UID, "PRIN");
                learningStory.Practices        = LearningStoryItem.ListItem(learningStory.UID, "PRAC");
            }
        }
Exemple #4
0
        /// <summary>
        /// Update Learning Story details
        /// </summary>
        /// <returns></returns>
        public ResponseStatus Update(string userID)
        {
            // Check record version. Do not allow update if version is different

            if (!IsTheSameRecordVersion(this.UID, this.RecordVersion))
            {
                return(new ResponseStatus()
                {
                    ReturnCode = -0010,
                    ReasonCode = 0001,
                    Message = "Record updated previously by another user."
                });
            }

            string commandString = (
                "UPDATE LearningStory " +
                " SET  " +
                FieldName.UID + "= @" + FieldName.UID + ", " +
                FieldName.FKChildUID + "= @" + FieldName.FKChildUID + ", " +
                FieldName.FKEducatorUID + "= @" + FieldName.FKEducatorUID + ", " +
                FieldName.FKRoomCode + "= @" + FieldName.FKRoomCode + ", " +
                FieldName.Date + "= @" + FieldName.Date + ", " +
                FieldName.Story + "= @" + FieldName.Story + ", " +
                FieldName.AnalysisOfLearning + "= @" + FieldName.AnalysisOfLearning + ", " +
                FieldName.ExtensionOfLearning + "= @" + FieldName.ExtensionOfLearning + ", " +
                FieldName.ParentsComments + "= @" + FieldName.ParentsComments + ", " +
                FieldName.UpdateDateTime + "= @" + FieldName.UpdateDateTime + ", " +
                FieldName.UserIdUpdatedBy + "= @" + FieldName.UserIdUpdatedBy + ", " +
                FieldName.RecordVersion + "= @" + FieldName.RecordVersion + ", " +
                FieldName.IsVoid + "= @" + FieldName.IsVoid +

                "    WHERE UID = @UID "
                );



            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                using (var command = new MySqlCommand(cmdText: commandString, connection: connection))
                {
                    RecordVersion++;
                    IsVoid = "N";
                    AddSqlParameters(command);

                    try
                    {
                        connection.Open();
                        command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        LogFile.WriteToTodaysLogFile(ex.ToString(), _headerInfo.UserID);

                        return(new ResponseStatus()
                        {
                            ReturnCode = -0020, ReasonCode = 0001, Message = "Error saving client. " + ex
                        });
                    }
                }
            }

            // Delete Items
            //
            new LearningStoryItem().DeleteItems(this.UID, _headerInfo);

            // Add items
            //

            if (LearningOutcomes != null)
            {
                foreach (var learningOutcome in LearningOutcomes)
                {
                    var lit = new LearningStoryItem().AddItem(this, learningOutcome, _headerInfo);
                }
            }

            if (Practices != null)
            {
                foreach (var practice in Practices)
                {
                    var lit = new LearningStoryItem().AddItem(this, practice, _headerInfo);
                }
            }
            if (Principles != null)
            {
                foreach (var principle in Principles)
                {
                    var lit = new LearningStoryItem().AddItem(this, principle, _headerInfo);
                }
            }

            return(new ResponseStatus());
        }
Exemple #5
0
        /// <summary>
        /// Add Learning Story
        /// </summary>
        public LearningStoryAddResponse Add(LearningStoryAddRequest learningStoryAddRequest)
        {
            var response = new LearningStoryAddResponse();

            response.responseStatus = new ResponseStatus();

            this.UserIdCreatedBy = learningStoryAddRequest.headerInfo.UserID;
            this.UserIdUpdatedBy = learningStoryAddRequest.headerInfo.UserID;

            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                UID           = CommonDB.GetLastUID("LearningStory") + 1;
                RecordVersion = 1;

                var commandString =
                    (
                        "INSERT INTO LearningStory (" +
                        FieldString() +
                        ")" +
                        " VALUES " +
                        "( " +
                        "  @" + FieldName.UID +
                        " ,@" + FieldName.FKChildUID +
                        " ,@" + FieldName.FKEducatorUID +
                        " ,@" + FieldName.FKRoomCode +
                        " ,@" + FieldName.Date +
                        " ,@" + FieldName.Story +
                        " ,@" + FieldName.AnalysisOfLearning +
                        " ,@" + FieldName.ExtensionOfLearning +
                        " ,@" + FieldName.ParentsComments +

                        ", @" + FieldName.UpdateDateTime +
                        ", @" + FieldName.UserIdUpdatedBy +
                        ", @" + FieldName.CreationDateTime +
                        ", @" + FieldName.UserIdCreatedBy +
                        ", @" + FieldName.RecordVersion +
                        ", @" + FieldName.IsVoid +
                        " )"
                    );

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    IsVoid = "N";
                    AddSqlParameters(command);

                    command.Parameters.Add("@" + FieldName.CreationDateTime, MySqlDbType.DateTime).Value = DateTime.Now;
                    command.Parameters.Add("@" + FieldName.UserIdCreatedBy, MySqlDbType.VarChar).Value   = this.UserIdCreatedBy;
                    //command.Parameters.Add("@" + FieldName.IsVoid, MySqlDbType.VarChar).Value = "N";

                    try
                    {
                        connection.Open();
                        command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        LogFile.WriteToTodaysLogFile(ex.ToString(), _headerInfo.UserID);

                        var respError = new LearningStoryAddResponse();
                        respError.responseStatus            = new ResponseStatus();
                        respError.responseStatus.ReturnCode = -0025;
                        respError.responseStatus.ReasonCode = 0001;
                        respError.responseStatus.Message    = "Error adding Learning Story. " + ex;
                    }
                }
            }

            // Add items


            if (LearningOutcomes != null)
            {
                foreach (var learningOutcome in LearningOutcomes)
                {
                    if (learningOutcome.Action == "TBD")
                    {
                        continue;
                    }
                    var lit = new LearningStoryItem().AddItem(this, learningOutcome, _headerInfo);
                }
            }

            if (Practices != null)
            {
                foreach (var practice in Practices)
                {
                    if (practice.Action == "TBD")
                    {
                        continue;
                    }
                    var lit = new LearningStoryItem().AddItem(this, practice, _headerInfo);
                }
            }
            if (Principles != null)
            {
                foreach (var principle in Principles)
                {
                    if (principle.Action == "TBD")
                    {
                        continue;
                    }
                    var lit = new LearningStoryItem().AddItem(this, principle, _headerInfo);
                }
            }
            return(response);
        }