3

Closed

Use with webforms load/save typical scenarios

description

Hey there,
 
I'll try to simplify the scenario, so, not all the names and practices below are real world or topic for criticism:
 
Let's say I have EmployeeEntity object, and EditEmployee.aspx page, which has private field _employeeEntity.
 
 
In my Page_Load event I might have something like:
Page_Load:
_employeeEntity = new EmployeeEntity( Request.QueryString["id"] );
if(!IsPostPack) LoadUIFromEmployeeModel();
 
Say I also have a Save button, where the button click is something like:
SaveEmployee_Click:
LoadEmployeeModelFromUI();
_employeeEntity.Save(); // or EmployeeRepository.Save(_employeeEntity); .. whatever
 
 
Cam Automapper help me with LoadUIFromEmployeeModel() and LoadEmployeeModelFromUI() ?
I mean, where the two functions look like:
 
LoadUIFromEmployeeModel():
txtName.Text = _employeeEntity.Name; //text box
chkIsActive.Checked = _employeeEntity.IsActive; //check box
ddlDepartmentId.Items.SelectByValue(_employeeEntity.DepartmentId); // drop down list
 
LoadUIFromEmployeeModel():
_employeeEntity.Name = txtName.Text; //text box
_employeeEntity.IsActive = chkIsActive.Checked; //check box
_employeeEntity.DepartmentId = ddlDepartmentId.SelectedValue; // drop down list
 
 
Can I automate this somehow using Automap?
If yes, what is the sample code of doing it?
Also, if yes, what are the limitations (for example, the drop down list line or say if I have the Name as two text boxes: txtName_FirstName mapping to _employeeEntity.Name.FirstName and txtName_LastName mapping to _employeeEntity.Name.LastName)?
Closed Sep 13, 2009 at 7:29 PM by jbogard
Solved with backing interface on ASPX page, I believe

comments

jbogard wrote Aug 16, 2009 at 1:49 AM

I think I would do this with interfaces - make an IView that exposes the controls as simple properties, string Name { get; set; }. This is what I did when I used MVP with WebForms, it worked quite nicely. Then you only need to map IEmployeeView to Employee. Make sense?