예제 #1
0
        /// <summary>
        /// Method to return individual Guardian details that match the guardianId
        /// </summary>
        /// <param name="guardianId">
        /// int GuardianId
        /// </param>
        /// <returns>
        /// Guardian object
        /// </returns>
        public Guardian GetGuardianDetails(int guardianId)
        {
            // Return the selectd guardian record
            Guardian guardian = new Guardian();

            guardian = smaDB.Guardians.Where(g => g.GuardianId == guardianId).FirstOrDefault();

            return(guardian);
        }
예제 #2
0
        /// <summary>
        /// Method to delete selected guardian details from the system database
        /// </summary>
        /// <param name="guardianId">
        /// int guardianId
        /// </param>
        /// <returns>
        /// int signifying success (1) or failure (0) of operation
        /// </returns>
        public int DeleteGuardian(int guardianId)
        {
            // Delete the selected guardian record on the system database
            Guardian guardian = new Guardian();

            guardian = smaDB.Guardians.Where(g => g.GuardianId == guardianId).FirstOrDefault();

            smaDB.Entry(guardian).State = System.Data.Entity.EntityState.Deleted;

            return(smaDB.SaveChanges());
        }
예제 #3
0
        /// <summary>
        /// Method adds new Guardian details to the system database
        /// </summary>
        /// <param name="addedGuardian">
        /// Guardian addedGuardian
        /// </param>
        /// <returns>
        /// int signifying success (1) or failure (0) of operation
        /// </returns>
        public int AddGuardian(Guardian addedGuardian)
        {
            // Add the guardian record to the system database
            var guardian = smaDB.Guardians.Where(g => g.GivenName == addedGuardian.GivenName && g.Surname == addedGuardian.Surname && g.MobileNo == addedGuardian.MobileNo).FirstOrDefault();

            if (guardian != null)
            {
                return(0);
            }
            else
            {
                smaDB.Entry(addedGuardian).State = System.Data.Entity.EntityState.Added;
                return(smaDB.SaveChanges());
            }
        }
예제 #4
0
        /// <summary>
        /// Method updates existing Guardian details on the system database
        /// </summary>
        /// <param name="guardian">
        /// Guardian guardian
        /// </param>
        /// <returns>
        /// int signifying success (1) or failure (0) of operation
        /// </returns>
        public int UpdateGuardian(Guardian guardian)
        {
            // Update the selected guardian record on the system database
            Guardian existingGuardian = new Guardian();

            existingGuardian = smaDB.Guardians.Where(g => g.GuardianId == guardian.GuardianId).FirstOrDefault();

            if (existingGuardian != null)
            {
                existingGuardian.GivenName   = guardian.GivenName;
                existingGuardian.Surname     = guardian.Surname;
                existingGuardian.MobileNo    = guardian.MobileNo;
                existingGuardian.EmergencyNo = guardian.EmergencyNo;
                existingGuardian.Address     = guardian.Address;

                smaDB.Entry(existingGuardian).State = System.Data.Entity.EntityState.Modified;

                return(smaDB.SaveChanges());
            }
            else
            {
                return(0);
            }
        }