Server side Validation made easy

We want to validate the data on the server in ViewModels\OrdersViewModel.cs

Basic Required Validation

protected override void OnSavingRow()
{
    if (Activity == Activities.Insert)
        Orders.OrderID.Value = Orders.Max(Orders.OrderID) + 1;
    ModelState.Required(Orders.CustomerID);
} 

Custom Validation

protected override void OnSavingRow()
{
    if (Activity == Activities.Insert)
        Orders.OrderID.Value = Orders.Max(Orders.OrderID) + 1;
    ModelState.Required(Orders.CustomerID);
    if (Orders.OrderDate.Year < 1990)
        ModelState.AddError(Orders.OrderDate, "Invalid Date");
} 

Basic exist in table validation

protected override void OnSavingRow()
{
    if (Activity == Activities.Insert)
        Orders.OrderID.Value = Orders.Max(Orders.OrderID) + 1;
    ModelState.Required(Orders.CustomerID);
    if (Orders.OrderDate.Year < 1990)
        ModelState.AddError(Orders.OrderDate, "Invalid Date");
    ModelState.Exists(Orders.CustomerID, new Northwind.Models.Customers().CustomerID);
} 

one more for ShipVia

protected override void OnSavingRow()
{
    if (Activity == Activities.Insert)
        Orders.OrderID.Value = Orders.Max(Orders.OrderID) + 1;
    ModelState.Required(Orders.CustomerID);
    if (Orders.OrderDate.Year < 1990)
        ModelState.AddError(Orders.OrderDate, "Invalid Date");
    ModelState.Exists(Orders.CustomerID, new Northwind.Models.Customers().CustomerID);
    ModelState.Exists(Orders.ShipVia, new Northwind.Models.Shippers().ShipperID);
} 

the User Experience

2017 10 15 08H43 25


Help us improve, Edit this page on GitHub
or email us at info@fireflymigration.com