15
bring IBM i RPG assets forward 1 © 2014 by ASNA. All rights reserved. Using data annotations to form a scaffolding for a solid and dynamic data driven architecture Architect your AVR for .NET apps like a pro Presented by Tim Daniels

Architect your next-generation AVR for .NET apps like a pro

Embed Size (px)

DESCRIPTION

Architect your next-generation AVR for .NET apps like a pro

Citation preview

Page 1: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 1© 2014 by ASNA. All rights reserved.

Using data annotations to form a scaffolding for a solid and dynamic data driven architecture

Architect your AVR for .NET apps like a pro

Presented by Tim Daniels

Page 2: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 2© 2014 by ASNA. All rights reserved.

Using Data Annotations

• Four objectives for a web app1. Standardize data validation2. Standardize data display3. Provide scaffolding for a dynamic data driven website4. Support client side validation

Page 3: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 3© 2014 by ASNA. All rights reserved.

Using Data Annotations

• Use data annotations to customize entity classes• Centralize the validation and display rules of the

entity class• Avoid re-applying the same rules in multiple places

Page 4: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 4© 2014 by ASNA. All rights reserved.

What is an entity class?

• Defines the domain object model• Business Domain Entity is defined with properties• Properties support data annotation attributes• Properties provide strong typing of data values• Properties provide IntelliSense • Achieve Database independence

Page 5: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 5© 2014 by ASNA. All rights reserved.

What is the ValidationAttribute Class

•Member of;•  System.ComponentModel.DataAnnotations

• Serves as the base class for all validation attributes

• The Details• System.ComponentModel.DataAnnotations

Page 6: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 6© 2014 by ASNA. All rights reserved.

Data Annotation Attributes

• Applied to entity class properties• Three Categories

1. Validation Attributes2. Display Attributes3. Data Modeling Attributes

• The Details• Using Data Annotations to Customize Data Classes

Page 7: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 7© 2014 by ASNA. All rights reserved.

First add a reference to this assembly: System.ComponentModel.DataAnnotations

Add this using statement: Using System.ComponentModel.DataAnnotations

Applying data annotation attributes to properties

Page 8: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 8© 2014 by ASNA. All rights reserved.

Using System

Using System.Text

Using System.ComponentModel.DataAnnotations

DclNamespace ASNA.Examples.Models

BegClass Customer Access(*Public)

dclprop CustomerName type(*string) access(*public)

attributes(DisplayAttribute(Name:="Name"), RequiredAttribute(), +

StringLengthAttribute(40, ErrorMessage:="Name cannot be longer than 40 +

characters"))

Display Rule

Validation Rule

Validation Rule

Page 9: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 9© 2014 by ASNA. All rights reserved.

• Scaffolding • By Default scaffolding mechanism in ASP.NET is turned on

• The benefits of scaffolding• Small amount of code is required to create a data-driven web app• Data validation is built in, based on data validation attributes• Customization • Easy to change the way data is displayed and validated

Dynamic Data in ASP.NET

Page 10: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 10© 2014 by ASNA. All rights reserved.

• Dynamic Field attribute

Dynamic Data in ASP.NET

Page 11: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 11© 2014 by ASNA. All rights reserved.

• Provides a better user experience• More responsive web page• Does not require a round trip to the server

• Dynamic Fields automat client side validation• Client side JavaScript is automatically generated • The Validation Summary control provides formatting of error

messages

Client side validation

Page 12: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 12© 2014 by ASNA. All rights reserved.

• Editing a customer object• ASP.NET Details View Control• Item Type Attribute• Dynamic Fields• Select Method• Update Method

• Client side validation• JavaScript• Validation Summary

Web application demonstration

Page 13: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 13© 2014 by ASNA. All rights reserved.

Validation AttributesValidation Attribute Description

CustomValidationAttribute Uses a custom method for validation.

DataTypeAttribute Specifies a particular type of data, such as e-mail address or phone number.

EnumDataTypeAttribute Ensures that the value exists in an enumeration.

RangeAttribute Designates minimum and maximum constraints.

RegularExpressionAttribute Uses a regular expression to determine valid values.

RequiredAttribute Specifies that a value must be provided.

StringLengthAttribute Designates maximum and minimum number of characters.

ValidationAttribute Serves as base class for validation attributes.

Page 14: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 14© 2014 by ASNA. All rights reserved.

Display AttributesDisplay Attribute Description

DataTypeAttribute Specifies a particular type of data, such as e-mail address or phone number.

DisplayAttribute Specifies localizable strings for data types and members that are used in the user interface.

DisplayColumnAttribute Designates display and sorting properties when a table is used as a parent table in a foreign key relationship.

DisplayFormatAttribute Specifies how data fields are displayed and formatted.

FilterUIHintAttribute Designates the filtering behavior for a column.

UIHintAttribute Designates the control and values to use to display the associated entity member.

Page 15: Architect your next-generation AVR for .NET apps like a pro

We bring IBM i RPG assets forward 15© 2014 by ASNA. All rights reserved.

Data Modeling AttributesData Modeling Attribute Description

AssociationAttribute Specifies that an entity member represents a data relationship, such as a foreign key relationship.

ConcurrencyCheckAttribute Designates that a property participates in optimistic concurrency checks.

EditableAttribute Specifies whether users should be able to change the value of the entity property.

KeyAttribute Specifies one or more entity properties to use as the unique identity for the entity.

TimestampAttribute Designates a member as a time stamp value for data versioning.