namespace BLL
{
public class Person
{
int _personId;
public int PersonId
{
get { return _personId; }
set { _personId = value; }
}
public static Person GetPerson(int personId)
{
Person person = new Person();
person.PersonId = personId;
person.Fetch(personId);
return person;
}
public static Person GetPerson(PersonManager.Person personData)
{
Person person = new Person();
person.PersonId = personData.PersonId;
person.FirstName = personData.FirstName;
return person;
}
private void Fetch(int personId)
{
PersonManager.Person fetchedPerson = PersonManager.GetPerson(personId);
this.PersonId = fetchedPerson.PersonId;
this.FirstName = fetchedPerson.FirstName;
}
public void Save()
{
if (this._personId == 0)
{
// Means this is a new Person record and needs
// to be inserted into the database
PersonManager.Person newPerson = new PersonManager.Person();
newPerson.PersonCode = this.PersonCode;
this.PersonId = PersonManager.InsertPerson(newPerson).PersonId;
}
else
{
// Means this Person record is already present
// in the database and needs to be updated
PersonManager.Person empToUpdate = new PersonManager.Person();
empToUpdate.PersonId = this.PersonId;
PersonManager.UpdatePerson(empToUpdate);
}
}
}
}
{
public class Person
{
int _personId;
public int PersonId
{
get { return _personId; }
set { _personId = value; }
}
public static Person GetPerson(int personId)
{
Person person = new Person();
person.PersonId = personId;
person.Fetch(personId);
return person;
}
public static Person GetPerson(PersonManager.Person personData)
{
Person person = new Person();
person.PersonId = personData.PersonId;
person.FirstName = personData.FirstName;
return person;
}
private void Fetch(int personId)
{
PersonManager.Person fetchedPerson = PersonManager.GetPerson(personId);
this.PersonId = fetchedPerson.PersonId;
this.FirstName = fetchedPerson.FirstName;
}
public void Save()
{
if (this._personId == 0)
{
// Means this is a new Person record and needs
// to be inserted into the database
PersonManager.Person newPerson = new PersonManager.Person();
newPerson.PersonCode = this.PersonCode;
this.PersonId = PersonManager.InsertPerson(newPerson).PersonId;
}
else
{
// Means this Person record is already present
// in the database and needs to be updated
PersonManager.Person empToUpdate = new PersonManager.Person();
empToUpdate.PersonId = this.PersonId;
PersonManager.UpdatePerson(empToUpdate);
}
}
}
}
namespace BLL
{
public class PersonList : List<Person>
{
private PersonList()
{
}
public static PersonList GetAllPersons()
{
PersonList list = new PersonList();
list.FetchAll();
return list;
}
private void FetchAll()
{
List<PersonManager.Person> allPersons = PersonManager.GetAllPersons();
foreach (var item in allPersons)
{
Person person = Person.GetPerson(item);
this.Add(person);
}
}
public static PersonList GetSearchedPersons(Person personSearched)
{
PersonManager.Person person = new PersonManager.Person();
person.FirstName = personSearched.FirstName;
person.LastName = personSearched.LastName;
person.DateOfJoining = personSearched.DateOfJoining;
person.DepartmentId = personSearched.DepartmentId;
person.PersonCode = personSearched.PersonCode;
person.DepartmentName = personSearched.DepartmentName;
PersonList list = new PersonList();
list.FetchSearchedPersons(person);
return list;
}
private void FetchSearchedPersons(PersonManager.Person personSearched)
{
List<PersonManager.Person> allPersons = PersonManager.SearchPersons(personSearched);
foreach (var item in allPersons)
{
Person person = Person.GetPerson(item);
this.Add(person);
}
}
}
}