/// <summary>
        /// retrieve a list of all characters using the repository
        /// </summary>
        /// <returns>all characters</returns>
        private List <FlintstoneCharacter> GetAllCharacters()
        {
            List <FlintstoneCharacter> characters = null;

            FileIoStatus = FileIoMessage.None;

            try
            {
                using (FlintstoneCharacterRepository fsRepository = new FlintstoneCharacterRepository())
                {
                    characters = fsRepository.GetAll() as List <FlintstoneCharacter>;
                };

                if (characters != null)
                {
                    FileIoStatus = FileIoMessage.Complete;
                }
                else
                {
                    FileIoStatus = FileIoMessage.NoRecordsFound;
                }
            }
            catch (Exception)
            {
                FileIoStatus = FileIoMessage.FileAccessError;
            }

            return(characters);
        }
        /// <summary>
        /// retrieve a character using the repository
        /// </summary>
        /// <returns>character</returns>
        private FlintstoneCharacter GetCharacter(int id)
        {
            FlintstoneCharacter character = null;

            FileIoStatus = FileIoMessage.None;

            try
            {
                using (FlintstoneCharacterRepository fsRepository = new FlintstoneCharacterRepository())
                {
                    character = fsRepository.GetById(id);
                };

                if (character != null)
                {
                    FileIoStatus = FileIoMessage.Complete;
                }
                else
                {
                    FileIoStatus = FileIoMessage.RecordNotFound;
                }
            }
            catch (Exception)
            {
                FileIoStatus = FileIoMessage.FileAccessError;
            }

            return(character);
        }
 public void DeleteFlintstoneCharacter(FlintstoneCharacter character)
 {
     FileIoStatus = FileIoMessage.None;
     using (FlintstoneCharacterRepository fsRepository = new FlintstoneCharacterRepository())
         try
         {
             fsRepository.Delete(character.Id);
             FileIoStatus = FileIoMessage.FileAccessError;
         }
         catch (Exception)
         {
             FileIoStatus = FileIoMessage.FileAccessError;
         }
 }
 public void AddFlintstoneCharacter(FlintstoneCharacter character)
 {
     FileIoStatus = FileIoMessage.None;
     using (FlintstoneCharacterRepository fsRepository = new FlintstoneCharacterRepository())
     {
         try
         {
             fsRepository.Add(character);
             FileIoStatus = FileIoMessage.Complete;
         }
         catch (Exception)
         {
             FileIoStatus = FileIoMessage.FileAccessError;
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// retrieve a list of all characters
        /// </summary>
        /// <returns>all characters</returns>
        private List <FlintstoneCharacter> FlintstoneCharactersList()
        {
            List <FlintstoneCharacter> characters = new List <FlintstoneCharacter>();

            FileIoStatus = FileIoMessage.None;

            using (FlintstoneCharacterRepository fsRepository = new FlintstoneCharacterRepository())
            {
                try
                {
                    characters   = fsRepository.GetAll() as List <FlintstoneCharacter>;
                    FileIoStatus = FileIoMessage.Complete;
                }
                catch (Exception)
                {
                    FileIoStatus = FileIoMessage.FileAccessError;
                }
            };

            return(characters);
        }
        public void UpdateFlintstoneCharacter(FlintstoneCharacter updatedCharacter)
        {
            try
            {
                if (GetCharacter(updatedCharacter.Id) != null)
                {
                    using (FlintstoneCharacterRepository repo = new FlintstoneCharacterRepository())
                    {
                        repo.Update(updatedCharacter);
                    }

                    FileIoStatus = FileIoMessage.Complete;
                }
                else
                {
                    FileIoStatus = FileIoMessage.RecordNotFound;
                }
            }
            catch (Exception)
            {
                FileIoStatus = FileIoMessage.FileAccessError;
            }
        }