Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

I'm trying to data onto a Repositry and it giving me a problem.
Please can you assist me, as i want to save and edit from textboxes into the repository.

C#
public static class PersonRespository
    {
        private static List<Person> _InternalStorage { get; set; }

        static PersonRespository ()
        {
            _InternalStorage = new List<Person>();
            Save(new Person(){FirstName = "Sherlock", LastName = "Holmes", Gender = Gender.Male, Title = Title.Mr});
            Save(new Person() { FirstName = "John", LastName = "Watson", Gender = Gender.Male, Title = Title.Dr });
            Save(new Person() { FirstName = "James", LastName = "Moriati", Gender = Gender.Male, Title = Title.Professor });
            Save(new Person() { FirstName = "Irene", LastName = "Adler", Gender = Gender.Female, Title = Title.Miss });
        }

        public static Person[] FindAll()
        {
            return _InternalStorage.ToArray();
        }

        public static int Save (Person person)
        {
            if (person.Id == 0)
            {
                if (_InternalStorage.Count > 0)
                    person.Id = _InternalStorage.Max(p => p.Id) + 1;
                else
                    person.Id = 1;
            }
            else
            {
                _InternalStorage.RemoveAll(p => p.Id == person.Id);
            }
            _InternalStorage.Add(person);
            return person.Id;
        }

        public static Person Find (int personId)
        {
            return _InternalStorage.FirstOrDefault(p => p.Id == personId);
        }
    }

Please assist where possible?

Kind Regards,
Ndeza
Posted
Updated 14-Feb-12 16:45pm
v2
Comments
Sergey Alexandrovich Kryukov 14-Feb-12 17:55pm    
This is not a question. What is the problem?
--SA
ndeza 14-Feb-12 18:03pm    
I'm trying to add and edit data
krumia 15-Feb-12 3:33am    
I'm surprised you got a solution from someone.

Please try to post your question with a concise subject next time. And please pinpoint your problem. Don't say "I have a problem please help me". Say "When the user does 'x' the system gives error 'y'" or something like that.

1 solution

You will have populated your text box from a Person object, one imagines?

so when you want to save, move the changed data from the text box back into the appropriate property in the person object,

theperson.Firstname = txtFirstname.Text;


then
PersonRepository.Save(thePerson);


if you are not populating your textboxes from a person object then you need to...
Person thePerson = Repository.Find(1);

txtFirstname.Text = thePerson.Firstname;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900