From b8f18467831e4c7cb5f2aa7dc00e5e8572451ad2 Mon Sep 17 00:00:00 2001 From: Diana Gromova <16adianay@gmail.com> Date: Mon, 25 Dec 2023 17:39:11 +0400 Subject: [PATCH 1/2] ASP.NET example --- ASP.NET Core/ASP.NET Core.csproj | 4 +- .../Controllers/SampleDataController.cs | 22 +- ASP.NET Core/Models/SampleData.cs | 379 ++---------------- ASP.NET Core/Models/SampleOrder.cs | 32 +- ASP.NET Core/Views/Home/Index.cshtml | 87 ++-- 5 files changed, 136 insertions(+), 388 deletions(-) diff --git a/ASP.NET Core/ASP.NET Core.csproj b/ASP.NET Core/ASP.NET Core.csproj index 1b62626..6e9aa5d 100644 --- a/ASP.NET Core/ASP.NET Core.csproj +++ b/ASP.NET Core/ASP.NET Core.csproj @@ -18,8 +18,8 @@ - - + + diff --git a/ASP.NET Core/Controllers/SampleDataController.cs b/ASP.NET Core/Controllers/SampleDataController.cs index 9e55a9a..9da8a8d 100644 --- a/ASP.NET Core/Controllers/SampleDataController.cs +++ b/ASP.NET Core/Controllers/SampleDataController.cs @@ -3,20 +3,36 @@ using System.Linq; using System.Net; using System.Net.Http; +using System.Runtime.CompilerServices; using ASP_NET_Core.Models; using DevExtreme.AspNet.Data; using DevExtreme.AspNet.Mvc; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace ASP_NET_Core.Controllers { - [Route("api/[controller]")] + [Route("api/[controller]/[action]")] public class SampleDataController : Controller { - + [HttpGet] public object Get(DataSourceLoadOptions loadOptions) { - return DataSourceLoader.Load(SampleData.Orders, loadOptions); + return DataSourceLoader.Load(SampleData.Customers, loadOptions); } + [HttpPut] + public IActionResult Put(int key, string values) + { + + var item = SampleData.Customers.First(e => e.ID == key); + + JsonConvert.PopulateObject(values, item); + if (!TryValidateModel(item)) + return BadRequest(ModelState); + + return Ok(item); + } } } \ No newline at end of file diff --git a/ASP.NET Core/Models/SampleData.cs b/ASP.NET Core/Models/SampleData.cs index b49f5b9..21786bd 100644 --- a/ASP.NET Core/Models/SampleData.cs +++ b/ASP.NET Core/Models/SampleData.cs @@ -6,357 +6,32 @@ namespace ASP_NET_Core.Models { static class SampleData { - public static List Orders = new List() { - new SampleOrder { - OrderID = 10248, - OrderDate = new DateTime(1996, 7, 4), - ShipCountry = "France", - ShipCity = "Reims", - CustomerName = "Paul Henriot" - }, - new SampleOrder { - OrderID = 10249, - OrderDate = new DateTime(1996, 7, 5), - ShipCountry = "Germany", - ShipCity = "Münster", - CustomerName = "Karin Josephs" - }, - new SampleOrder { - OrderID = 10250, - OrderDate = new DateTime(1996, 7, 8), - ShipCountry = "Brazil", - ShipCity = "Rio de Janeiro", - CustomerName = "Mario Pontes" - }, - new SampleOrder { - OrderID = 10251, - OrderDate = new DateTime(1996, 7, 8), - ShipCountry = "France", - ShipCity = "Lyon", - CustomerName = "Mary Saveley" - }, - new SampleOrder { - OrderID = 10252, - OrderDate = new DateTime(1996, 7, 9), - ShipCountry = "Belgium", - ShipCity = "Charleroi", - CustomerName = "Pascale Cartrain" - }, - new SampleOrder { - OrderID = 10253, - OrderDate = new DateTime(1996, 7, 10), - ShipCountry = "Brazil", - ShipCity = "Rio de Janeiro", - CustomerName = "Mario Pontes" - }, - new SampleOrder { - OrderID = 10254, - OrderDate = new DateTime(1996, 7, 11), - ShipCountry = "Switzerland", - ShipCity = "Bern", - CustomerName = "Yang Wang" - }, - new SampleOrder { - OrderID = 10255, - OrderDate = new DateTime(1996, 7, 12), - ShipCountry = "Switzerland", - ShipCity = "Genève", - CustomerName = "Michael Holz" - }, - new SampleOrder { - OrderID = 10256, - OrderDate = new DateTime(1996, 7, 15), - ShipCountry = "Brazil", - ShipCity = "Resende", - CustomerName = "Paula Parente" - }, - new SampleOrder { - OrderID = 10257, - OrderDate = new DateTime(1996, 7, 16), - ShipCountry = "Venezuela", - ShipCity = "San Cristóbal", - CustomerName = "Carlos Hernández" - }, - new SampleOrder { - OrderID = 10258, - OrderDate = new DateTime(1996, 7, 17), - ShipCountry = "Austria", - ShipCity = "Graz", - CustomerName = "Roland Mendel" - }, - new SampleOrder { - OrderID = 10259, - OrderDate = new DateTime(1996, 7, 18), - ShipCountry = "Mexico", - ShipCity = "México D.F.", - CustomerName = "Francisco Chang" - }, - new SampleOrder { - OrderID = 10260, - OrderDate = new DateTime(1996, 7, 19), - ShipCountry = "Germany", - ShipCity = "Köln", - CustomerName = "Henriette Pfalzheim" - }, - new SampleOrder { - OrderID = 10261, - OrderDate = new DateTime(1996, 7, 19), - ShipCountry = "Brazil", - ShipCity = "Rio de Janeiro", - CustomerName = "Bernardo Batista" - }, - new SampleOrder { - OrderID = 10262, - OrderDate = new DateTime(1996, 7, 22), - ShipCountry = "USA", - ShipCity = "Albuquerque", - CustomerName = "Paula Wilson" - }, - new SampleOrder { - OrderID = 10263, - OrderDate = new DateTime(1996, 7, 23), - ShipCountry = "Austria", - ShipCity = "Graz", - CustomerName = "Roland Mendel" - }, - new SampleOrder { - OrderID = 10264, - OrderDate = new DateTime(1996, 7, 24), - ShipCountry = "Sweden", - ShipCity = "Bräcke", - CustomerName = "Maria Larsson" - }, - new SampleOrder { - OrderID = 10265, - OrderDate = new DateTime(1996, 7, 25), - ShipCountry = "France", - ShipCity = "Strasbourg", - CustomerName = "Frédérique Citeaux" - }, - new SampleOrder { - OrderID = 10266, - OrderDate = new DateTime(1996, 7, 26), - ShipCountry = "Finland", - ShipCity = "Oulu", - CustomerName = "Pirkko Koskitalo" - }, - new SampleOrder { - OrderID = 10267, - OrderDate = new DateTime(1996, 7, 29), - ShipCountry = "Germany", - ShipCity = "München", - CustomerName = "Peter Franken" - }, - new SampleOrder { - OrderID = 10268, - OrderDate = new DateTime(1996, 7, 30), - ShipCountry = "Venezuela", - ShipCity = "Caracas", - CustomerName = "Manuel Pereira" - }, - new SampleOrder { - OrderID = 10269, - OrderDate = new DateTime(1996, 7, 31), - ShipCountry = "USA", - ShipCity = "Seattle", - CustomerName = "Karl Jablonski" - }, - new SampleOrder { - OrderID = 10270, - OrderDate = new DateTime(1996, 8, 1), - ShipCountry = "Finland", - ShipCity = "Oulu", - CustomerName = "Pirkko Koskitalo" - }, - new SampleOrder { - OrderID = 10271, - OrderDate = new DateTime(1996, 8, 1), - ShipCountry = "USA", - ShipCity = "Lander", - CustomerName = "Art Braunschweiger" - }, - new SampleOrder { - OrderID = 10272, - OrderDate = new DateTime(1996, 8, 2), - ShipCountry = "USA", - ShipCity = "Albuquerque", - CustomerName = "Paula Wilson" - }, - new SampleOrder { - OrderID = 10273, - OrderDate = new DateTime(1996, 8, 5), - ShipCountry = "Germany", - ShipCity = "Cunewalde", - CustomerName = "Horst Kloss" - }, - new SampleOrder { - OrderID = 10274, - OrderDate = new DateTime(1996, 8, 6), - ShipCountry = "France", - ShipCity = "Reims", - CustomerName = "Paul Henriot" - }, - new SampleOrder { - OrderID = 10275, - OrderDate = new DateTime(1996, 8, 7), - ShipCountry = "Italy", - ShipCity = "Bergamo", - CustomerName = "Giovanni Rovelli" - }, - new SampleOrder { - OrderID = 10276, - OrderDate = new DateTime(1996, 8, 8), - ShipCountry = "Mexico", - ShipCity = "México D.F.", - CustomerName = "Miguel Angel Paolino" - }, - new SampleOrder { - OrderID = 10277, - OrderDate = new DateTime(1996, 8, 9), - ShipCountry = "Germany", - ShipCity = "Leipzig", - CustomerName = "Alexander Feuer" - }, - new SampleOrder { - OrderID = 10278, - OrderDate = new DateTime(1996, 8, 12), - ShipCountry = "Sweden", - ShipCity = "Luleå", - CustomerName = "Christina Berglund" - }, - new SampleOrder { - OrderID = 10279, - OrderDate = new DateTime(1996, 8, 13), - ShipCountry = "Germany", - ShipCity = "Frankfurt a.M.", - CustomerName = "Renate Messner" - }, - new SampleOrder { - OrderID = 10280, - OrderDate = new DateTime(1996, 8, 14), - ShipCountry = "Sweden", - ShipCity = "Luleå", - CustomerName = "Christina Berglund" - }, - new SampleOrder { - OrderID = 10281, - OrderDate = new DateTime(1996, 8, 14), - ShipCountry = "Spain", - ShipCity = "Madrid", - CustomerName = "Alejandra Camino" - }, - new SampleOrder { - OrderID = 10282, - OrderDate = new DateTime(1996, 8, 15), - ShipCountry = "Spain", - ShipCity = "Madrid", - CustomerName = "Alejandra Camino" - }, - new SampleOrder { - OrderID = 10283, - OrderDate = new DateTime(1996, 8, 16), - ShipCountry = "Venezuela", - ShipCity = "Barquisimeto", - CustomerName = "Carlos González" - }, - new SampleOrder { - OrderID = 10284, - OrderDate = new DateTime(1996, 8, 19), - ShipCountry = "Germany", - ShipCity = "Frankfurt a.M.", - CustomerName = "Renate Messner" - }, - new SampleOrder { - OrderID = 10285, - OrderDate = new DateTime(1996, 8, 20), - ShipCountry = "Germany", - ShipCity = "Cunewalde", - CustomerName = "Horst Kloss" - }, - new SampleOrder { - OrderID = 10286, - OrderDate = new DateTime(1996, 8, 21), - ShipCountry = "Germany", - ShipCity = "Cunewalde", - CustomerName = "Horst Kloss" - }, - new SampleOrder { - OrderID = 10287, - OrderDate = new DateTime(1996, 8, 22), - ShipCountry = "Brazil", - ShipCity = "Rio de Janeiro", - CustomerName = "Janete Limeira" - }, - new SampleOrder { - OrderID = 10288, - OrderDate = new DateTime(1996, 8, 23), - ShipCountry = "Italy", - ShipCity = "Reggio Emilia", - CustomerName = "Maurizio Moroni" - }, - new SampleOrder { - OrderID = 10289, - OrderDate = new DateTime(1996, 8, 26), - ShipCountry = "UK", - ShipCity = "London", - CustomerName = "Victoria Ashworth" - }, - new SampleOrder { - OrderID = 10290, - OrderDate = new DateTime(1996, 8, 27), - ShipCountry = "Brazil", - ShipCity = "Sao Paulo", - CustomerName = "Pedro Afonso" - }, - new SampleOrder { - OrderID = 10291, - OrderDate = new DateTime(1996, 8, 27), - ShipCountry = "Brazil", - ShipCity = "Rio de Janeiro", - CustomerName = "Bernardo Batista" - }, - new SampleOrder { - OrderID = 10292, - OrderDate = new DateTime(1996, 8, 28), - ShipCountry = "Brazil", - ShipCity = "Sao Paulo", - CustomerName = "Anabela Domingues" - }, - new SampleOrder { - OrderID = 10293, - OrderDate = new DateTime(1996, 8, 29), - ShipCountry = "Mexico", - ShipCity = "México D.F.", - CustomerName = "Miguel Angel Paolino" - }, - new SampleOrder { - OrderID = 10294, - OrderDate = new DateTime(1996, 8, 30), - ShipCountry = "USA", - ShipCity = "Albuquerque", - CustomerName = "Paula Wilson" - }, - new SampleOrder { - OrderID = 10295, - OrderDate = new DateTime(1996, 9, 2), - ShipCountry = "France", - ShipCity = "Reims", - CustomerName = "Paul Henriot" - }, - new SampleOrder { - OrderID = 10296, - OrderDate = new DateTime(1996, 9, 3), - ShipCountry = "Venezuela", - ShipCity = "Barquisimeto", - CustomerName = "Carlos González" - }, - new SampleOrder { - OrderID = 10297, - OrderDate = new DateTime(1996, 9, 4), - ShipCountry = "France", - ShipCity = "Strasbourg", - CustomerName = "Frédérique Citeaux" - } - }; + public static List Customers = new List + { + new Customer + { + ID = 1, + CompanyName = "", + Address = "702 SW 8th Street", + City = "Bentonville", + State = "Arkansas", + Zipcode = 72716, + Phone = "123456", + Fax = "(800) 555-2171", + Website = "http://www.nowebsitesupermart.com" + }, + new Customer + { + ID = 2, + CompanyName = "Electronics Depot", + Address = "2455 Paces Ferry Road NW", + City = "NYC", + State = "Georgia", + Zipcode = 30339, + Phone = "(800) 595-3232", + Fax = "(800) 595-3231", + Website = "http://www.nowebsitedepot.com" + } + }; } } diff --git a/ASP.NET Core/Models/SampleOrder.cs b/ASP.NET Core/Models/SampleOrder.cs index 7f10198..1673dc5 100644 --- a/ASP.NET Core/Models/SampleOrder.cs +++ b/ASP.NET Core/Models/SampleOrder.cs @@ -1,16 +1,34 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ASP_NET_Core.Models { - public class SampleOrder { - public int OrderID { get; set; } - public DateTime OrderDate { get; set; } - public string CustomerID { get; set; } - public string CustomerName { get; set; } - public string ShipCountry { get; set; } - public string ShipCity { get; set; } + public class Customer + { + + public int ID { get; set; } + + [Required] + public string CompanyName { get; set; } + + public string Address { get; set; } + + [StringLength(int.MaxValue, MinimumLength = 4, ErrorMessage = "City must have at least 2 symbols")] + public string City { get; set; } + + public string State { get; set; } + + public int Zipcode { get; set; } + + [Required] + [RegularExpression(@"^\(\d{3}\)\ \d{3}-\d{4}$", ErrorMessage = @"Your phone must have ""(555) 555-5555"" format!")] + public string Phone { get; set; } + + public string Fax { get; set; } + + public string Website { get; set; } } } diff --git a/ASP.NET Core/Views/Home/Index.cshtml b/ASP.NET Core/Views/Home/Index.cshtml index 672571d..94dae9a 100644 --- a/ASP.NET Core/Views/Home/Index.cshtml +++ b/ASP.NET Core/Views/Home/Index.cshtml @@ -2,28 +2,67 @@

Home

-@(Html.DevExtreme().DataGrid() - .ShowBorders(true) - .DataSource(d => d.Mvc().Controller("SampleData").LoadAction("Get").Key("OrderID")) - .Columns(columns => { - columns.AddFor(m => m.OrderID); - columns.AddFor(m => m.OrderDate); - columns.AddFor(m => m.CustomerName); - columns.AddFor(m => m.ShipCountry); - columns.AddFor(m => m.ShipCity); +@(Html.DevExtreme().DataGrid() + .ID("gridContainer") + .DataSource(d => d.Mvc() + .Controller("SampleData") + .LoadAction("Get") + .UpdateAction("Put") + .Key("ID")) + .Editing(e => + { + e.AllowUpdating(true); + e.Mode(GridEditMode.Batch); + }) + .Columns(columns => + { + columns.AddFor(m => m.CompanyName); + columns.AddFor(m => m.City); + columns.AddFor(m => m.Phone); + columns.AddFor(m => m.Fax); + columns.AddFor(m => m.State); }) - .Paging(p => p.PageSize(10)) - .FilterRow(f => f.Visible(true)) - .HeaderFilter(f => f.Visible(true)) - .GroupPanel(p => p.Visible(true)) - .Grouping(g => g.AutoExpandAll(false)) - .RemoteOperations(true) - .Summary(s => s - .TotalItems(totalItems => { - totalItems.AddFor(m => m.ShipCity).SummaryType(SummaryType.Count); - }) - .GroupItems(groupItems => { - groupItems.Add().SummaryType(SummaryType.Count); - }) - ) -) \ No newline at end of file + .Toolbar(toolbar => + { + toolbar.Items(items => + { + items.Add() + .Name("validate") + .Widget(w => + w.Button() + .Text("Validate DataGrid") + .StylingMode(ButtonStylingMode.Outlined) + .OnClick("validateVisibleRows")); + items.Add().Name("saveButton"); + items.Add().Name("revertButton"); + }); + }) + .ShowBorders(true) +) + + From a7348afe17843f2fe0060e678c6ecc535ae6665a Mon Sep 17 00:00:00 2001 From: DevExpressExampleBot Date: Mon, 25 Dec 2023 17:41:00 +0400 Subject: [PATCH 2/2] README auto update [skip ci] --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9687e9f..3e99775 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/723096689/23.1.3%2B) [![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T1202789) [![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)