Esempio n. 1
0
        /// <summary>
        /// Logical Delete client
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public ResponseStatus DeleteItems(int learningStoryUID, HeaderInfo _headerInfo)
        {
            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                var commandString =
                    (
                        "DELETE FROM LearningStoryItem " +
                        "    WHERE FKLearningStoryUID = @FKLearningStoryUID "
                    );

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

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

                        return(new ResponseStatus()
                        {
                            ReturnCode = -0022, ReasonCode = 0001, Message = "Error deleting Learning Story Item. " + ex
                        });
                    }
                }
            }
            return(new ResponseStatus());
        }
Esempio n. 2
0
        // ----------------------------------------------
        // Private methods
        // ----------------------------------------------

        /// <summary>
        /// Get Employee details
        /// </summary>
        public void Read(bool includeOutcome)
        {
            //
            // EA SQL database
            //
            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                var commandString =
                    " SELECT " +
                    FieldString()
                    + "  FROM learningStory" +
                    " WHERE UID = " + this.UID;

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    connection.Open();
                    MySqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        try
                        {
                            LoadObject(reader, this, includeOutcome);
                        }
                        catch (Exception ex)
                        {
                            UID = 0;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// List clients
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="roomUID"> </param>
        public void List(string userID, int roomUID = 0)
        {
            childList = new List <Child>();

            string roomCriteria = "";

            if (roomUID > 0)
            {
                roomCriteria = " and child.CurrentRoom = " + roomUID;

                // Get Room Name
                var room = new Room();
                room.UID = roomUID;
                room.Read();

                this.RoomName = room.Name;
            }

            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                var commandString = string.Format(
                    " SELECT " +
                    FieldString() +
                    " , room.Name " +
                    "   FROM child, room " +
                    "  WHERE child.IsVoid = 'N' " +
                    "  AND   child.CurrentRoom = room.UID " +
                    roomCriteria +
                    "  ORDER BY UID ASC "
                    );

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    connection.Open();

                    try
                    {
                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var client = new Child();
                                LoadObject(reader, client);
                                client.RoomName = reader.GetString(FieldName.RoomName);

                                childList.Add(client);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string error = ex.ToString();
                        LogFile.WriteToTodaysLogFile(ex.ToString(), userID, "", "Client.cs");
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Add Room
        /// </summary>
        public ResponseStatus Add(string userID)
        {
            this.UserIdCreatedBy = userID;
            this.UserIdUpdatedBy = userID;

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

                var commandString =
                    (
                        "INSERT INTO Room (" +
                        FieldString() +
                        ")" +
                        " VALUES " +
                        "( " +
                        "  @" + FieldName.UID +
                        " ,@" + FieldName.Name +
                        " ,@" + FieldName.Description +
                        ", @" + FieldName.UpdateDateTime +
                        ", @" + FieldName.UserIdUpdatedBy +
                        ", @" + FieldName.CreationDateTime +
                        ", @" + FieldName.UserIdCreatedBy +
                        ", @" + FieldName.RecordVersion +
                        ", @" + FieldName.IsVoid +
                        " )"
                    );

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    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);

                        return(new ResponseStatus()
                        {
                            ReturnCode = -0025, ReasonCode = 0001, Message = "Error adding Room. " + ex
                        });
                    }

                    return(new ResponseStatus());
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Check if the record version is the same. If it is not, deny update
        /// </summary>
        /// <param name="tablename"></param>
        /// <param name="inputUID"></param>
        /// <param name="recordVersion"></param>
        /// <returns></returns>
        public static bool IsTheSameRecordVersion(string tablename, int inputUID, int recordVersion, ResponseStatus responseStatus)
        {
            //
            // EA SQL database
            //
            int currentVersion = 0;

            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                var commandString = "SELECT recordversion FROM " + tablename + " WHERE UID = " +
                                    inputUID.ToString(CultureInfo.InvariantCulture);

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    connection.Open();
                    MySqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        try
                        {
                            currentVersion = Convert.ToInt32(reader["recordversion"]);
                        }
                        catch (Exception)
                        {
                            currentVersion = 0;
                        }
                    }
                }
            }


            bool ret = false;

            if (currentVersion == 0 || currentVersion != recordVersion)
            {
                responseStatus.ReturnCode = -0010;
                responseStatus.ReasonCode = 0001;
                responseStatus.Message    = "Record updated previously by another user.";
                ret = false;
            }
            else
            {
                responseStatus.ReturnCode = 0001;
                responseStatus.ReasonCode = 0001;
                responseStatus.Message    = "Record Versions are matching. All good.";
                ret = true;
            }

            return(ret);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        /// <summary>
        /// Update Room details
        /// </summary>
        /// <returns></returns>
        public ResponseStatus Update(string userID)
        {
            // Check record version. Do not allow update if version is different

            string commandString = (
                "UPDATE room " +
                " SET  " +
                FieldName.UID + "= @" + FieldName.UID + ", " +
                FieldName.Name + "= @" + FieldName.Name + ", " +
                FieldName.Description + "= @" + FieldName.Description + ", " +
                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++;
                    AddSqlParameters(command);

                    try
                    {
                        //command.Parameters.Add("@" + FieldName.UpdateDateTime, MySqlDbType.DateTime).Value = DateTime.Now;
                        //command.Parameters.Add("@" + FieldName.UserIdUpdatedBy, MySqlDbType.VarChar).Value = userID;
                        command.Parameters.AddWithValue("@" + FieldName.IsVoid, 'N');

                        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
                        });
                    }
                }
            }

            return(new ResponseStatus());
        }
Esempio n. 9
0
        /// <summary>
        /// Get Employee details
        /// </summary>
        public void Read()
        {
            //
            // EA SQL database
            //
            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                var commandString =
                    " SELECT " +
                    FieldString() +
                    " , room.Name " +
                    "   FROM child, room " +
                    "  WHERE child.IsVoid = 'N' " +
                    "  AND   child.CurrentRoom = room.UID " +
                    "  AND child.UID = @UID";

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    try
                    {
                        command.Parameters.AddWithValue("@UID", this.UID);

                        connection.Open();
                        MySqlDataReader reader = command.ExecuteReader();

                        if (reader.Read())
                        {
                            try
                            {
                                LoadObject(reader, this);
                                this.RoomName = reader.GetString(FieldName.RoomName);
                            }
                            catch (Exception exx)
                            {
                                LogFile.WriteToTodaysLogFile(exx.ToString(), _headerInfo.UserID);
                                UID = 0;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogFile.WriteToTodaysLogFile(ex.ToString(), _headerInfo.UserID);
                    }
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Retrieve last UID
        /// </summary>
        /// <returns></returns>
        private static int GetLastUID()
        {
            int lastUID = 0;

            //
            // EA SQL database
            //

            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                var commandString = "SELECT MAX(UID) LASTUID FROM Worker";

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    try
                    {
                        connection.Open();

                        MySqlDataReader reader = command.ExecuteReader();

                        if (reader.Read())
                        {
                            try
                            {
                                lastUID = Convert.ToInt32(reader["LASTUID"]);
                            }
                            catch (Exception ex)
                            {
                                string error = ex.ToString();
                                LogFile.WriteToTodaysLogFile("Last UID set to ZERO. " +
                                                             ex.ToString(), HeaderInfo.Instance.UserID, "", "Child.cs");

                                lastUID = 0;
                            }
                        }
                    }
                    catch (Exception ex2)
                    {
                        LogFile.WriteToTodaysLogFile(ex2.ToString());
                    }
                }
            }

            return(lastUID);
        }
Esempio n. 11
0
        // ----------------------------------------------
        // Private methods
        // ----------------------------------------------

        /// <summary>
        /// Check if the record version is the same. If it is not, deny update
        /// </summary>
        /// <param name="inputUID"></param>
        /// <param name="recordVersion"></param>
        /// <returns></returns>
        private static bool IsTheSameRecordVersion(int inputUID, int recordVersion)
        {
            //
            // EA SQL database
            //
            int currentVersion = 0;

            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                var commandString = "SELECT recordversion FROM Room WHERE UID = " + inputUID.ToString(CultureInfo.InvariantCulture);

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    connection.Open();
                    MySqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        try
                        {
                            currentVersion = Convert.ToInt32(reader["recordversion"]);
                        }
                        catch (Exception)
                        {
                            currentVersion = 0;
                        }
                    }
                }
            }

            bool ret = false;

            if (currentVersion == 0 || currentVersion != recordVersion)
            {
                ret = false;
            }
            else
            {
                ret = true;
            }

            return(ret);
        }
Esempio n. 12
0
        /// <summary>
        /// List clients
        /// </summary>
        /// <param name="userID"></param>
        public void List(string userID, int childUID)
        {
            LearningStoryList = new List <LearningStory>();

            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                var commandString = string.Format(
                    " SELECT " +
                    FieldString() +
                    "   FROM LearningStory " +
                    "  WHERE IsVoid = 'N' " +
                    " AND FKChildUID = @FKChildUID " +
                    "  ORDER BY UID ASC "
                    );

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    command.Parameters.AddWithValue("@FkChildUID", childUID);

                    connection.Open();

                    try
                    {
                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var client = new LearningStory();
                                LoadObject(reader, client, false);

                                LearningStoryList.Add(client);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string error = ex.ToString();
                        LogFile.WriteToTodaysLogFile(ex.ToString(), userID, "", "Client.cs");
                    }
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// List clients
        /// </summary>
        /// <param name="userID"></param>
        public static List <Educator> ListS()
        {
            var workerListX = new List <Educator>();

            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                var commandString = string.Format(
                    " SELECT " +
                    FieldString() +
                    "   FROM Worker " +
                    "  WHERE IsVoid = 'N' " +
                    "  ORDER BY UID ASC "
                    );

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    connection.Open();

                    try
                    {
                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var worker = new Educator();
                                LoadObject(reader, worker);

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

            return(workerListX);
        }
Esempio n. 14
0
        /// <summary>
        /// List clients
        /// </summary>
        /// <param name="userID"></param>
        public void List(string userID)
        {
            roomList = new List <Room>();

            using (var connection = new MySqlConnection(ConnectionString.GetConnectionString()))
            {
                var commandString = string.Format(
                    " SELECT " +
                    FieldString() +
                    "   FROM Room " +
                    "  WHERE IsVoid = 'N' " +
                    "  ORDER BY UID ASC "
                    );

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    connection.Open();

                    try
                    {
                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var client = new Room();
                                LoadObject(reader, client);

                                roomList.Add(client);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string error = ex.ToString();
                        LogFile.WriteToTodaysLogFile(ex.ToString(), userID, "", "Client.cs");
                    }
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Update child details
        /// </summary>
        /// <returns></returns>
        public WorkerUpdateResponse Update(WorkerUpdateRequest workerAddRequest)
        {
            WorkerUpdateResponse workerUpdateResponse = new WorkerUpdateResponse();

            workerUpdateResponse.XResponseStatus = new ResponseStatus();

            // Check record version. Do not allow update if version is different

            if (!CommonDB.IsTheSameRecordVersion(tablename: "Worker",
                                                 inputUID: UID,
                                                 recordVersion: RecordVersion,
                                                 responseStatus: workerUpdateResponse.XResponseStatus))
            {
                return(workerUpdateResponse);
            }

            string commandString = (
                "UPDATE Worker " +
                " SET  " +
                FieldName.UID + "= @" + FieldName.UID + ", " +
                FieldName.FirstName + "= @" + FieldName.FirstName + ", " +
                FieldName.Surname + "= @" + FieldName.Surname + ", " +
                FieldName.WLVL_Level + "= @" + FieldName.WLVL_Level + ", " +
                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++;
                    AddSqlParameters(command);

                    try
                    {
                        command.Parameters.AddWithValue("@" + FieldName.IsVoid, "N");

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

                        workerUpdateResponse.XResponseStatus.ReturnCode = -0020;
                        workerUpdateResponse.XResponseStatus.ReasonCode = 0001;
                        workerUpdateResponse.XResponseStatus.Message    = "Error saving client. " + ex;
                        return(workerUpdateResponse);
                    }
                }
            }

            return(workerUpdateResponse);
        }
Esempio n. 16
0
        /// <summary>
        /// Add Worker
        /// </summary>
        public WorkerAddResponse Add(WorkerAddRequest workerAddRequest)
        {
            var workerAddResponse = new WorkerAddResponse();

            workerAddResponse.XResponseStatus = new ResponseStatus();

            this.UserIdCreatedBy = workerAddRequest.XHeaderInfo.UserID;
            this.UserIdUpdatedBy = workerAddRequest.XHeaderInfo.UserID;

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

                var commandString =
                    (
                        "INSERT INTO Worker (" +
                        FieldString() +
                        ")" +
                        " VALUES " +
                        "( " +
                        "  @" + FieldName.UID +
                        " ,@" + FieldName.FirstName +
                        " ,@" + FieldName.Surname +
                        " ,@" + FieldName.WLVL_Level +
                        ", @" + FieldName.UpdateDateTime +
                        ", @" + FieldName.UserIdUpdatedBy +
                        ", @" + FieldName.CreationDateTime +
                        ", @" + FieldName.UserIdCreatedBy +
                        ", @" + FieldName.RecordVersion +
                        ", @" + FieldName.IsVoid +
                        " )"
                    );

                using (var command = new MySqlCommand(
                           commandString, connection))
                {
                    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(), workerAddRequest.XHeaderInfo.UserID);

                        workerAddResponse.XResponseStatus.ReturnCode = -0025;
                        workerAddResponse.XResponseStatus.ReasonCode = 0001;
                        workerAddResponse.XResponseStatus.Message    = "Error adding child. " + ex;
                        return(workerAddResponse);
                    }

                    return(workerAddResponse);
                }
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Add Learning Story
        /// </summary>
        public ChildRoomAddResponse Add(ChildRoomAddRequest childRoomAddRequest)
        {
            this.UserIdCreatedBy = childRoomAddRequest.headerInfo.UserID;
            this.UserIdUpdatedBy = childRoomAddRequest.headerInfo.UserID;

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

                var commandString =
                    (
                        "INSERT INTO LearningStory (" +
                        FieldString() +
                        ")" +
                        " VALUES " +
                        "( " +
                        "  @" + FieldName.UID +
                        " ,@" + FieldName.FKChildUID +
                        " ,@" + FieldName.FKRoomUID +
                        " ,@" + FieldName.StartDate +
                        " ,@" + FieldName.EndDate +

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

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

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

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

                        return(new ChildRoomAddResponse
                        {
                            responseStatus =
                            {
                                ReturnCode = -0025,
                                ReasonCode =  0001,
                                Message    = "Error adding Learning Story. " + ex
                            }
                        });
                    }

                    return(new ChildRoomAddResponse
                    {
                        responseStatus = { ReturnCode = 0001, ReasonCode = 0001 }
                    });
                }
            }
        }
Esempio n. 18
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);
        }
Esempio n. 19
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());
        }
Esempio n. 20
0
        /// <summary>
        /// Update child 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 Child " +
                " SET  " +
                FieldName.UID + "= @" + FieldName.UID + ", " +
                FieldName.CurrentRoom + "= @" + FieldName.CurrentRoom + ", " +
                FieldName.FirstName + "= @" + FieldName.FirstName + ", " +
                FieldName.Surname + "= @" + FieldName.Surname + ", " +
                FieldName.DateOfBirth + "= @" + FieldName.DateOfBirth + ", " +
                FieldName.AddressStreetName + "= @" + FieldName.AddressStreetName + ", " +
                FieldName.AddressStreetNumber + "= @" + FieldName.AddressStreetNumber + ", " +
                FieldName.AddressSuburb + "= @" + FieldName.AddressSuburb + ", " +
                FieldName.AddressCity + "= @" + FieldName.AddressCity + ", " +
                FieldName.AddressPostCode + "= @" + FieldName.AddressPostCode + ", " +
                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++;
                    AddSqlParameters(command);

                    try
                    {
                        //command.Parameters.Add("@" + FieldName.UpdateDateTime, MySqlDbType.DateTime).Value = DateTime.Now;
                        //command.Parameters.Add("@" + FieldName.UserIdUpdatedBy, MySqlDbType.VarChar).Value = userID;

                        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
                        });
                    }
                }
            }

            return(new ResponseStatus());
        }