Exemplo n.º 1
0
        /// <summary>
        /// Convert Person Object into Person Entity
        /// </summary>
        ///<param name="model">Person</param>
        ///<param name="PersonEntity">DataAccess.Person</param>
        ///<returns>DataAccess.Person</returns>
        public static DataAccess.Person ToEntity(this PersonViewModel model,
                                                 DataAccess.Person entity)
        {
            if (entity.Id == 0)
            {
                entity.CreatedUserId = model.SessionUserId;
            }
            else
            {
                entity.UpdatedUserId    = model.SessionUserId;
                entity.UpdatedTimestamp = DateTime.Now;
            }

            entity.IDNumber  = model.IDNumber;
            entity.CountryId = model.CountryId;
            entity.Initials  = model.Initials;
            entity.OtherName = model.OtherName;
            entity.IDTypeId  = model.IDTypeId;
            entity.ContactNo = model.ContactNo;
            entity.Email     = model.Email;
            entity.Surname   = model.Surname;
            entity.FirstName = model.FirstName;
            entity.Surname   = model.Surname;
            entity.TitleId   = model.TitleId;
            entity.GenderId  = model.GenderId;

            return(entity);
        }
        public void BuiderSetsNameOfDtoToEntitys()
        {
            var person = new Person();
            person.Name = "Person with unique name";

            var builder = new PersonDtoBuilder();
            PersonDto dto = builder.BuildDto(person);
            Assert.AreEqual(person.Name, dto.Name);
        }
Exemplo n.º 3
0
		public Person UpdatePerson(DbManager db, Person person)
		{
			db
				./*[a]*/SetCommand/*[/a]*/(@"
					UPDATE
						Person
					SET
						LastName   = @LastName,
						FirstName  = @FirstName,
						Gender     = @Gender
					WHERE
						PersonID = @PersonID",
					db./*[a]*/CreateParameters/*[/a]*/(person))
				.ExecuteNonQuery();

			return GetPersonByID(db, person.ID);
		}
Exemplo n.º 4
0
 /// <summary>
 /// Convert Person Entity  into Person Object
 /// </summary>
 ///<param name="model">PersonViewModel</param>
 ///<param name="PersonEntity">DataAccess.Person</param>
 ///<returns>PersonViewModel</returns>
 public static PersonViewModel ToViewModel(
     this DataAccess.Person entity,
     PersonViewModel model)
 {
     model.Id            = entity.Id;
     model.SessionUserId = entity.CreatedUserId;
     model.Title         = entity.Title.Name;
     model.Gender        = entity.Gender.Name;
     model.FirstName     = entity.FirstName;
     model.Surname       = entity.Surname;
     model.ContactNo     = entity.ContactNo;
     model.Email         = entity.Email;
     model.TitleId       = entity.TitleId ?? 0;
     model.GenderId      = entity.GenderId;
     model.Initials      = entity.Initials;
     model.OtherName     = entity.OtherName;
     model.IDTypeId      = entity.IDTypeId;
     model.IDNumber      = entity.IDNumber;
     model.CountryId     = entity.CountryId;
     model.PersonGuid    = entity.PersonGuid;
     return(model);
 }
Exemplo n.º 5
0
		public void Test()
		{
			Person person = new Person();

			person.FirstName = "John";
			person.LastName  = "Smith";
			person.Gender    = Gender.Male;

			using (DbManager db = new DbManager())
			{
				db.BeginTransaction();

				// Execute.
				//
				db
					.SetSpCommand("Person_Insert", db.CreateParameters(person))
					./*[a]*/ExecuteNonQuery/*[/a]*/();

				// Check the result.
				//
				person = db
					.SetCommand(
						"SELECT * FROM Person WHERE LastName = @lastName",
						db.Parameter("@lastName", "Smith"))
					.ExecuteObject<Person>();

				Assert.IsNotNull(person);

				// Cleanup.
				//
				db
					.SetCommand(
						"DELETE FROM Person WHERE LastName = @lastName",
						db.Parameter("@lastName", "Smith"))
					./*[a]*/ExecuteNonQuery/*[/a]*/();

				db.CommitTransaction();
			}
		}
Exemplo n.º 6
0
		public Person DeletePerson(DbManager db, Person person)
		{
			db
				./*[a]*/SetCommand/*[/a]*/("DELETE FROM Person WHERE PersonID = @id",
					db./*[a]*/Parameter/*[/a]*/("@id", person.ID))
				.ExecuteNonQuery();

			return GetPersonByID(db, person.ID);
		}
Exemplo n.º 7
0
		public void CreateParametersTest()
		{
			Person person = new Person();

			person.FirstName = "John";
			person.LastName  = "Smith";
			person.Gender    = Gender.Male;

			using (DbManager db = new DbManager())
			{
				db.BeginTransaction();

				// Prepare command.
				//
				int id = db
					.SetSpCommand("Person_Insert",
						db./*[a]*/CreateParameters/*[/a]*/(person))
					.ExecuteScalar<int>();

				// Check the result.
				//
				person = db
					.SetCommand(
						"SELECT * FROM Person WHERE PersonID = @id",
						db.Parameter("@id", id))
					.ExecuteObject<Person>();

				Assert.IsNotNull(person);

				// Cleanup.
				//
				db
					.SetCommand(
						"DELETE FROM Person WHERE PersonID = @id",
						db.Parameter("@id", id))
					.ExecuteNonQuery();

				db.CommitTransaction();
			}
		}
Exemplo n.º 8
0
		public Person UpdatePerson(DbManager db, Person person)
		{
			db
				./*[a]*/SetSpCommand/*[/a]*/("Person_Update", db./*[a]*/CreateParameters/*[/a]*/(person))
				.ExecuteNonQuery();

			return GetPersonByID(db, person.ID);
		}
Exemplo n.º 9
0
		public Person DeletePerson(DbManager db, Person person)
		{
			db
				./*[a]*/SetSpCommand/*[/a]*/("Person_Delete", /*[a]*/person.ID/*[/a]*/)
				.ExecuteNonQuery();

			return GetPersonByID(db, person.ID);
		}
Exemplo n.º 10
0
 public PersonDto BuildDto(Person fromPerson)
 {
     return new PersonDto() { Name = fromPerson.Name };
 }