Search

MVC Pattern

MVC Pattern stands for Model-View-Controller Pattern. This pattern is used to separate application's concerns.

  • Model - Model represents an object or JAVA POJO carrying data. It can also have logic to update controller if its data changes.

  • View - View represents the visualization of the data that model contains.

  • Controller - Controller acts on both model and view. It controls the data flow into model object and updates the view whenever data changes. It keeps view and model separate.

Implementation

We are going to create a Student object acting as a model.StudentView will be a view class which can print student details on console and StudentController is the controller class responsible to store data in Student object and update view StudentView accordingly.

 

Step 1

Create Model.

Student.cs


public class Student {
private String rollNo;
private String name;

public String getRollNo() {
return rollNo;
}

public void setRollNo(String rollNo) {
this.rollNo = rollNo;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

Step 2


Create View.

StudentView.cs


public class StudentView {
public void printStudentDetails(String studentName, String studentRollNo){
Console.WriteLine("Student: ");
Console.WriteLine("Name: " + studentName);
Console.WriteLine("Roll No: " + studentRollNo);
}
}

Step 3


Create Controller.

StudentController.cs


public class StudentController {
private Student model;
private StudentView view;

public StudentController(Student model, StudentView view){
this.model = model;
this.view = view;
}

public void setStudentName(String name){
model.setName(name);
}

public String getStudentName(){
return model.getName();
}

public void setStudentRollNo(String rollNo){
model.setRollNo(rollNo);
}

public String getStudentRollNo(){
return model.getRollNo();
}

public void updateView(){
view.printStudentDetails(model.getName(), model.getRollNo());
}
}

Step 4


Use the StudentController methods to demonstrate MVC design pattern usage.

MVCPatternDemo.cs




public class MVCPatternDemo {
public static void main(String[] args) {

//fetch student record based on his roll no from the database
Student model = retriveStudentFromDatabase();

//Create a view : to write student details on console
StudentView view = new StudentView();

StudentController controller = new StudentController(model, view);

controller.updateView();

//update model data
controller.setStudentName("John");

controller.updateView();
}

private static Student retriveStudentFromDatabase(){
Student student = new Student();
student.setName("Robert");
student.setRollNo("10");
return student;
}
}



Ping IP Addresses

Small module written to replicate the ping functionality in C# code

Complete Installation guide for CRM 4.0

Complete Installation guide for CRM 4.0 / Step by Step guide to install CRM 4.0

        Last week I installed Microsoft Dynamic 4.0 on my virtual machine and I found that it will be helpful for beginner like me, if there is a step by step installation guide. Lets start with OS selection.

1. You can use Windows Server 2003 or later server version. I had Windows Server 2003 R2.

2. Install latest service pack for OS you installed.

3. Install Internet Information Service.

4. Install Active Directory.

5. Configure DNS Server.

6. Create new user for domain and make him member of Administrators group.

7. Install SQL Server 2005 with Reporting Service and Analysis service.

8. Configure new account as service account for Report Server and Analysis server.

9. Install Visual Studio 2008.

10. Start installation of CRM 4.0

11. Enter display name for your Organization.

clip_image001

12. Next step is to select installation path, you can leave this as it is or select specific folder,

clip_image002

13. Next select website for CRM, I choose new website with different port address in my case it was 5555 as shown in image below,

clip_image003

14. Next you need to enter URL for Reporting server.

15. Next you have to select Organization Unit. Click on Browse button and select the root node of your domain in my case it is chirag.

clip_image004

16. On next step you need to specify security account, choose the one you created in step 6. Enter the password in password textbox and click next.

17. Select your local machine as Email Router setting or select specific machine on domain which you are using at email server. I chose my local machine so localhost.

18. Once you click next you will see System Requirements screen. If Domain user, SQL Server Reporting Service and ASP.NET are installed properly you will receive no error or warning else you will receive error message. I received following errors,

clip_image005

19. If you receive error message for SQL Server or SQL Server Reporting Service don’t be afraid. Open Services from Start – All Programs – Administrative Tools – Services. Check whether SQL Server Agent is running. If not right click on service and select property. Select Startup Type as Automatic and click on start button.

20. Another common error is for Indexing service. Follow the steps mention in point 19 to start Indexing Service.

21. You can see a warning mentioning Verify Domain User account SPN for the Microsoft Dynamics CRM ASP.NET Application Pool account. This will usually shows when you add specific domain account for security account in step 16.

22. If System Requirements screen show no error or warning on next step installation will be started.

23. Finally you will see following screen, this means your CRM is installed.

clip_image006