Data Structures and Database Applications Custom Models with MVC

Slides:



Advertisements
Similar presentations
And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering.
Advertisements

Apache Struts Technology
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.
J4www/jea Week 3 Version Slide edits: nas1 Format of lecture: Assignment context: CRUD - “update details” JSP models.
Robustness Analysis Dr. Neal CIS 480. Outline What is robustness analysis? Key roles in robustness analysis Object types found in discovery Diagramming.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Object-Oriented Analysis and Design
Microsoft Office Word 2013 Expert Microsoft Office Word 2013 Expert Courseware # 3251 Lesson 4: Working with Forms.
Systems Analysis and Design in a Changing World, Fifth Edition
Unit J: Creating a Database Microsoft Office Illustrated Fundamentals.
1 C omputer information systems Design Instructor: Mr. Ahmed Al Astal IGGC1202 College Requirement University Of Palestine.
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.
ASP.NET and Model View Control Jesper Tørresø ITNET2 F08.
RECALL THE MAIN COMPONENTS OF KIM Functional User Interfaces We just looked at these Reference Implementation We will talk about these later Service Interface.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
12 Systems Analysis and Design in a Changing World, Fifth Edition.
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.
CRUD Matrix Presented by Trisha Cummings. Background to a CRUD Matrix CRUD stands for :- Create, Read, Update and Delete. A CRUD Matrix is very useful.
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.
Google App Engine Data Store ae-10-datastore
.  A multi layer architecture powered by Spring Framework, ExtJS, Spring Security and Hibernate.  Taken advantage of Spring’s multi layer injection.
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.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Class Diagrams. Terms and Concepts A class diagram is a diagram that shows a set of classes, interfaces, and collaborations and their relationships.
App Package Folder App data Folders Local Roaming Temp Removable Storage (SD Card) Cloud Credential Locker B/ground Transfer Publishers Shared Folder.
Model View ViewModel Architecture. MVVM Architecture components.
Apache Struts Technology A MVC Framework for Java Web Applications.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
High degree of user interaction Interactive Systems: Model View Controller Presentation-abstraction-control.
Build Data Driven Apps with ASP.NET Core Rachel Appel.
Jim Fawcett CSE686 – Internet Programming Summer 2010
Jim Fawcett CSE686 – Internet Programming Spring 2014
DBMS and SQL.
An introduction to ASP.Net with MVC Nischal S
Building Web Applications with Microsoft ASP
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
University of Central Florida COP 3330 Object Oriented Programming
Design Patterns: Model View Controller
CMPE 280 Web UI Design and Development October 24 Class Meeting
Data Structures and Database Applications Managing Databases with MVC
04 | Customizing Controllers
Data Structures and Database Applications Hashing and Hashtables in C#
Testing REST IPA using POSTMAN
Chapter 9 Designing Databases
Data Structures and Database Applications Hashing and Hashtables in C#
Controllers.
Introduction to Oracle Application Express
Social Media And Global Computing Managing MVC with Custom Models
Data Structures and Database Applications View and Session Data
Developing a Model-View-Controller Component for Joomla
Use Case Analysis – continued
ASP.NET MVC Imran Rashid CTO at ManiWeber Technologies.
ASP.NET and Model View Control
eSeries Entities By Julie Ladner
Model View Controller (MVC)
Presentation transcript:

Data Structures and Database Applications Custom Models with MVC

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

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 An Entry data structure (Model) that consist of four attributes – ID, Name, Phone, Email: public class Entry { public int ID { get; set; } public string Name { get; set; } public string Phone { get; set; } public string Email { 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 Entry Model’s data object and its List and Details methods: public static List<Entry> entries = new List<Entry>(); public ActionResult List() { return View(entries); } public ActionResult Details(Entry entry) return View(entry);

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

Building Views for the Custom Models To create your views for the Controller functions of your Custom Model, you need to identify the appropriate CRUD template in the “Add view” dialog and then choose the appropriate “Model Class” on the line under the template.

Building Views for the Custom Models When you have a view that is associated with a model, then the CRUD templates logic is added to that view 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 associated with a model, you can pass an object from that model directly back and forth between the view and controller.

Example: Creating Entries An Example of CRUD Functions for views that are for creating a list of entries: public static List<Entry> entries = new List<Entry>(); public static int uniqueID = 1; Function public ActionResult List() { ViewBag.Message = "Here's the list of the Entries:"; return View(entries); } public ActionResult Details(Entry entry) ViewBag.Message = "Details of this entry:"; return View(entry);

The CRUD Functions (cont.) public ActionResult Create() { ViewBag.Message = "Fill in the details for this entry:"; return View(); } [HttpPost] public ActionResult Create(Entry entry) if (!ModelState.IsValid) ViewBag.Message = "There was a creation error:"; return View("Create", entry); entry.ID = uniqueID++; entries.Add(entry); return RedirectToAction("List");

The CRUD Functions (cont.) 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);

The CRUD Functions (cont.) [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");

The CRUD Functions (cont.) 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);

The CRUD Functions (cont.) [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");