Social Media And Global Computing Managing MVC with Custom Models

Slides:



Advertisements
Similar presentations
Apache Struts Technology
Advertisements

Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Introduction to MVC Action Methods, Edit View, and a Search Feature NTPCUG Dr. Tom Perkins.
Ruby on Rails Model of MVC. Model-View-Controller Paradigm A way of organizing a software system Benefits: Isolation of business logic from the user interface.
University of Nevada, Reno College of Business Administration What are we going to learn 9/27 – 9/29? 1. Answer questions about MS Access queries. 2. Understand.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 5: Restaurant.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Apache Struts Technology A MVC Framework for Java Web Applications.
UNIT-V The MVC architecture and Struts Framework.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall 9.1.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC - Models.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
ASP.NET and Model View Control Jesper Tørresø ITNET2 F08.
CSCI 6962: Server-side Design and Programming Support Classes and Shopping Carts.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
Chapter 9 Designing Databases Modern Systems Analysis and Design Sixth Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.
Introduction to Entity Framework Part 2 CRUD Scaffolding Tom Perkins NTPCUG.
Chapter 6 Server-side Programming: Java Servlets
JSP Tag Libraries Lec Last Lecture Example We incorporated JavaBeans in “Course Outline” Example But still have to write java code inside java.jsp.
Copyright 2006 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Third Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Chapter.
Building Secure Web Applications With ASP.Net MVC.
Introduction to MVC Controllers NTPCUG Tom Perkins, Ph.D.
Getting started with ASP.NET MVC Dhananjay
ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Class Diagrams. Terms and Concepts A class diagram is a diagram that shows a set of classes, interfaces, and collaborations and their relationships.
Model View ViewModel Architecture. MVVM Architecture components.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
Apache Struts Technology A MVC Framework for Java Web Applications.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
BIT 286: Web Applications ASP.Net MVC. Objectives Applied MVC overview Controllers Intro to Routing Views ‘Convention over configuration’ Layout files.
Introduction to MVC Slavomír Moroz. Revision from Previous Lesson o ASP.NET WebForms applications Abstract away HTTP (similar to desktop app development)
Build Data Driven Apps with ASP.NET Core Rachel Appel.
Jim Fawcett CSE686 – Internet Programming Summer 2010
Jim Fawcett CSE686 – Internet Programming Spring 2014
JavaScript, Sixth Edition
Chapter 5 Validating Form Data with JavaScript
Asp.Net MVC Conventions
An introduction to ASP.Net with MVC Nischal S
Building Web Applications with Microsoft ASP
Metropolia 2013 C# programming and .NET framework
Jim Fawcett CSE686 – Internet Programming Spring 2012
Social Media And Global Computing Introduction to The MVC Pattern
MVC Architecture, Symfony Framework for PHP Web Apps
Social Media And Global Computing Managing Databases with MVC
C#: ASP.NET MVC Overview
Play Framework: Introduction
Design Patterns: Model View Controller
CMPE 280 Web UI Design and Development October 24 Class Meeting
CO6025 Advanced Programming
Data Structures and Database Applications Managing Databases with MVC
04 | Customizing Controllers
02 | Developing ASP.NET MVC 4 Models
Chapter 9 Designing Databases
Operation System Program 4
Data Structures and Database Applications Custom Models with MVC
Controllers.
MIS Professor Sandvig MIS 324 Professor Sandvig
Developing a Model-View-Controller Component for Joomla
Service Context Management for Exertion-oriented Programming
Service Context Management for Exertion-oriented Programming
ASP.NET MVC Web Development
ASP.NET and Model View Control
Asp.Net MVC Conventions
Presentation transcript:

Social Media And Global Computing Managing MVC with Custom Models

The Role of Models in MVC Models manage your application’s persistent data storage, which is essential to the logic of both the views and the controllers. The MVC Pattern’s Separation of Concerns specifies where each kind of logic should be located in the application: The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model.

The Role of Models in MVC Models manage the persistent data storage, which is essential to both views and controllers

The Role of Models in MVC Typical user interaction with MVC app: User makes a request on a view / form Controller handles request with view function Controller interacts with model Controller selects new view as response The new view awaits another user action

The Role of Models in MVC View doesn’t directly interact with model Controller provides form of model to view View displays data in user interface View transmits data to controller for update

Building Models Views should be simple as possible There to display what the user needs now Design models for the needs of the views Put complicated logic into model, not the view Controller functions should be simple Put complicated logic into model, not function Controller function translates user actions to the model then provides a response

Building Models Two basic approaches: Custom Model Class Entity Framework Model Class

The CRUD Functions When you are building a Model for storage of user data, you should usually implement the CRUD functions: Create – for creating data elements Ex: The Create() View Function Retrieve – for giving details of or listing elements Ex: The Details() and List() View Functions Update – for editing data elements Ex: The Edit() View Function Delete – for removing data elements Ex: The Delete() View Function

Building Custom Models We will create a Dog data structure (Model) that will consist of three attributes – ID, Name, Age: public class Dog { public int ID { get; set; } public string Name { get; set; } public int Age { get; set; } }

Building Custom Models When you have placed your class in your Models folder, you add the following “using” directive to access it from your Controller : using [ProjectName].Models;

Building Controller Functions for Custom Models The Dog Model’s data object and its List and Details methods: public static List<Dog> dogs = new List<Dog>(); public ActionResult List() { return View(dogs); } public ActionResult Details(Dog dog) return View(dog);

Building Controller Functions for Custom Models The Dog Model’s Create methods: public ActionResult Create() { return View(); } [HttpPost] public ActionResult Create(Dog dog) if (!ModelState.IsValid) return View("Create", dog); dogs.Add(dog); return RedirectToAction("List");

Building Controller Functions for Custom Models public ActionResult Edit(int ID) { Entry theEntry = null; ViewBag.Message = "Edit the following Entry’s Information:"; foreach (Entry e in entries) if (d.ID == ID) theEntry = e; break; } if (theEntry == null) return RedirectToAction("Error"); else return View(theEntry);

Building Controller Functions for Custom Models [HttpPost] public ActionResult Edit(Entry entry) { if (!ModelState.IsValid) ViewBag.Message = "There was an editing error:"; return View("Edit", entry); } foreach (Entry e in entries) if (e.ID == entry.ID) e.Name = entry.Name; e.Phone = entry.Phone; e.Email= entry.Email break; return RedirectToAction("List");

Building Controller Functions for Custom Models public ActionResult Delete(int ID) { Entry theEntry = null; ViewBag.Message = "Delete the following Entry's Information:"; foreach (Entry e in entries) if (e.ID == ID) theEntry = e; break; } if (theEntry == null) return RedirectToAction("Error"); else return View(theEntry);

Building Controller Functions for Custom Models [HttpPost] public ActionResult Delete(Entry entry) { if (entry == null) return RedirectToAction("Error"); foreach (Entry e in entries) if (e.ID == entry.ID) entries.Remove(e); break; } return RedirectToAction("List");

Using the Default Error Page In the Controller, you can use the Default Error page that is inside the Shared folder if you include the following Action method: public ActionResult Error() { return View(); }

Building Views for the Custom Models To create your views for the Controller functions of your Custom Model, you need to choose “Create a strongly-typed view” in the “Add view” dialog, and then select whatever appropriate Model “View Content” applies.

Building Views for the Custom Models When you have a view that is a strongly-typed you have the option of having views created for you that have logic in them to handle Creating, Listing, Deleting, or managing other manipulations of that data in the view.

Building Views for the Custom Models When you have a view that is a strongly-typed to a model view, you can pass the model directly back and forth between the view and controller. You can also use the ModelState data to determine if a valid Model is being received.