Skip to content

Commit a2ace90

Browse files
Update to 25.1.3+
1 parent 74d5cab commit a2ace90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2573
-17
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using ASP.NET_Core.Models;
2+
using ASP_NET_Core.Models;
3+
using DevExtreme.AspNet.Data;
4+
using DevExtreme.AspNet.Mvc;
5+
using Microsoft.AspNetCore.Http;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Caching.Memory;
8+
using Newtonsoft.Json;
9+
using System.Linq;
10+
11+
namespace ASP.NET_Core.Controllers {
12+
[Route("api/[controller]/[action]")]
13+
public class DnDBetweenGridsController : Controller
14+
{
15+
InMemoryRowReorderingTasksDataContext _context;
16+
17+
public DnDBetweenGridsController(IHttpContextAccessor httpContextAccessor, IMemoryCache memoryCache)
18+
{
19+
_context = new InMemoryRowReorderingTasksDataContext(httpContextAccessor, memoryCache);
20+
}
21+
22+
[HttpGet]
23+
public object Tasks(DataSourceLoadOptions loadOptions)
24+
{
25+
return DataSourceLoader.Load(_context.Tasks.Where(task => task.Status < 3).Take(10).ToList<RowReorderingTask>(), loadOptions);
26+
}
27+
28+
[HttpPut]
29+
public IActionResult UpdateTask(int key, string values)
30+
{
31+
var order = _context.Tasks.First(o => o.ID == key);
32+
JsonConvert.PopulateObject(values, order);
33+
34+
if (!TryValidateModel(order))
35+
return BadRequest(ModelState.GetFullErrorMessage());
36+
37+
_context.SaveChanges();
38+
39+
return Ok(order);
40+
}
41+
}
42+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
namespace ASP_NET_Core.Controllers
8+
{
9+
public class HomeController : Controller
10+
{
11+
public IActionResult Index()
12+
{
13+
return View();
14+
}
15+
16+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
17+
public IActionResult Error() {
18+
return View();
19+
}
20+
}
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.AspNetCore.Mvc.ModelBinding;
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace ASP.NET_Core.Models
6+
{
7+
static class Extensions
8+
{
9+
10+
public static string GetFullErrorMessage(this ModelStateDictionary modelState)
11+
{
12+
var messages = new List<string>();
13+
14+
foreach (var entry in modelState)
15+
{
16+
foreach (var error in entry.Value.Errors)
17+
messages.Add(error.ErrorMessage);
18+
}
19+
20+
return String.Join(" ", messages);
21+
}
22+
23+
}
24+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.Extensions.Caching.Memory;
3+
using Newtonsoft.Json;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
8+
namespace ASP.NET_Core.Models
9+
{
10+
public abstract class InMemoryDataContext<T>
11+
{
12+
IHttpContextAccessor _contextAccessor;
13+
IMemoryCache _memoryCache;
14+
15+
public InMemoryDataContext(IHttpContextAccessor contextAccessor, IMemoryCache memoryCache)
16+
{
17+
_contextAccessor = contextAccessor;
18+
_memoryCache = memoryCache;
19+
}
20+
21+
protected ICollection<T> ItemsInternal
22+
{
23+
get
24+
{
25+
var session = _contextAccessor.HttpContext.Session;
26+
if (!session.IsAvailable)
27+
throw new NotSupportedException("Session is required");
28+
29+
var key = session.Id + "_" + GetType().FullName;
30+
return _memoryCache.GetOrCreate(key, entry => {
31+
session.SetInt32("dirty", 1);
32+
entry.SlidingExpiration = TimeSpan.FromMinutes(10);
33+
return DeepClone(Source);
34+
});
35+
}
36+
}
37+
38+
protected abstract IEnumerable<T> Source { get; }
39+
40+
public void SaveChanges()
41+
{
42+
foreach (var item in ItemsInternal.Where(i => GetKey(i) == 0))
43+
SetKey(item, ItemsInternal.Max(GetKey) + 1);
44+
}
45+
46+
protected abstract int GetKey(T item);
47+
48+
protected abstract void SetKey(T item, int key);
49+
50+
static ICollection<T> DeepClone(IEnumerable<T> source)
51+
{
52+
return JsonConvert.DeserializeObject<List<T>>(JsonConvert.SerializeObject(source));
53+
}
54+
}
55+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using ASP_NET_Core.Models;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.Extensions.Caching.Memory;
4+
using System.Collections.Generic;
5+
6+
namespace ASP.NET_Core.Models
7+
{
8+
public class InMemoryRowReorderingTasksDataContext : InMemoryDataContext<RowReorderingTask>
9+
{
10+
11+
public InMemoryRowReorderingTasksDataContext(IHttpContextAccessor contextAccessor, IMemoryCache memoryCache)
12+
: base(contextAccessor, memoryCache) {
13+
}
14+
15+
public ICollection<RowReorderingTask> Tasks => ItemsInternal;
16+
17+
protected override IEnumerable<RowReorderingTask> Source => SampleData.RowReorderingTasks;
18+
19+
protected override int GetKey(RowReorderingTask item) => item.ID;
20+
21+
protected override void SetKey(RowReorderingTask item, int key) => item.ID = key;
22+
}
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace ASP_NET_Core.Models {
4+
public class RowReorderingTask
5+
{
6+
public int ID { set; get; }
7+
[Required]
8+
public string Subject { set; get; }
9+
[Required]
10+
public int Status { set; get; }
11+
[Required]
12+
public int Owner { set; get; }
13+
[Required]
14+
public int AssignedEmployee { get; set; }
15+
public int OrderIndex { get; set; }
16+
public int Priority { get; set; }
17+
}
18+
}

0 commit comments

Comments
 (0)