Skip to content

Commit fba521a

Browse files
authored
Merge pull request #1 from VenkateshwaranSaravanakumar/SE-104579-DataBindingURL
Documentation(SE-104579):Created Individual Sample for URL Adaptor in the Blazor Scheduler.
2 parents 6f7b085 + 7bcfbec commit fba521a

38 files changed

+1719
-0
lines changed

App.razor

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>

Controller/DefaultController.cs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Http;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Primitives;
8+
using Syncfusion.Blazor;
9+
using Syncfusion.Blazor.Data;
10+
using System.Collections;
11+
using System.Text.Json;
12+
using Url_Adaptor.Data;
13+
using Url_Adaptor.Models;
14+
using Microsoft.Extensions.Logging;
15+
using Microsoft.EntityFrameworkCore.Metadata.Internal;
16+
17+
18+
namespace Url_Adaptor.Controller
19+
{
20+
[ApiController]
21+
public class DefaultController : ControllerBase
22+
{
23+
private readonly EventsContext dbContext;
24+
25+
public DefaultController(EventsContext dbContext)
26+
{
27+
this.dbContext = dbContext;
28+
29+
if (this.dbContext.Events.Count() == 0)
30+
{
31+
foreach (var b in DataSource.GetEvents())
32+
{
33+
dbContext.Events.Add(b);
34+
}
35+
36+
dbContext.SaveChanges();
37+
}
38+
}
39+
40+
[HttpPost]
41+
[Route("api/[controller]")]
42+
public IActionResult Get()
43+
{
44+
var events = dbContext.Events.ToList();
45+
return Ok(events);
46+
}
47+
48+
49+
[HttpPost]
50+
[Route("api/Default/Add")]
51+
public void Add([FromBody] CRUDModel<Event> args)
52+
{
53+
dbContext.Events.Add(args.Value);
54+
dbContext.SaveChangesAsync();
55+
}
56+
57+
[HttpPost]
58+
[Route("api/Default/Update")]
59+
public async Task Update(CRUDModel<Event> args)
60+
{
61+
var entity = await dbContext.Events.FindAsync(args.Value.Id);
62+
if (entity != null)
63+
{
64+
dbContext.Entry(entity).CurrentValues.SetValues(args.Value);
65+
await dbContext.SaveChangesAsync();
66+
}
67+
}
68+
69+
[HttpPost]
70+
[Route("api/Default/Delete")]
71+
public async Task Delete(CRUDModel<Event> args)
72+
{
73+
var key = Convert.ToInt32(Convert.ToString(args.Key));
74+
var app = dbContext.Events.Find(key);
75+
if (app != null)
76+
{
77+
dbContext.Events.Remove(app);
78+
await dbContext.SaveChangesAsync();
79+
}
80+
}
81+
82+
[HttpPost]
83+
[Route("api/Default/Batch")]
84+
public async Task Batch([FromBody] CRUDModel<Event> args)
85+
{
86+
if (args.Changed.Count > 0)
87+
{
88+
foreach (Event appointment in args.Changed)
89+
{
90+
var entity = await dbContext.Events.FindAsync(appointment.Id);
91+
if (entity != null)
92+
{
93+
dbContext.Entry(entity).CurrentValues.SetValues(appointment);
94+
}
95+
}
96+
}
97+
if (args.Added.Count > 0)
98+
{
99+
foreach (Event appointment in args.Added)
100+
{
101+
dbContext.Events.Add(appointment);
102+
103+
}
104+
}
105+
106+
if (args.Deleted.Count > 0)
107+
{
108+
foreach (Event appointment in args.Deleted)
109+
{
110+
var app = dbContext.Events.Find(appointment.Id);
111+
if (app != null)
112+
{
113+
dbContext.Events.Remove(app);
114+
}
115+
}
116+
}
117+
await dbContext.SaveChangesAsync();
118+
}
119+
}
120+
}

Data/EventsContext.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Url_Adaptor.Models;
2+
using Microsoft.EntityFrameworkCore;
3+
4+
namespace Url_Adaptor.Data
5+
{
6+
public class EventsContext: DbContext
7+
{
8+
public EventsContext()
9+
{
10+
}
11+
12+
public EventsContext(DbContextOptions<EventsContext> options) : base(options)
13+
{
14+
}
15+
16+
public DbSet<Event> Events { get; set; }
17+
}
18+
}

Data/WeatherForecast.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Url_Adaptor.Data
2+
{
3+
public class WeatherForecast
4+
{
5+
public DateOnly Date { get; set; }
6+
7+
public int TemperatureC { get; set; }
8+
9+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
10+
11+
public string? Summary { get; set; }
12+
}
13+
}

Data/WeatherForecastService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Url_Adaptor.Data
2+
{
3+
public class WeatherForecastService
4+
{
5+
private static readonly string[] Summaries = new[]
6+
{
7+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
8+
};
9+
10+
public Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate)
11+
{
12+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
13+
{
14+
Date = startDate.AddDays(index),
15+
TemperatureC = Random.Shared.Next(-20, 55),
16+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
17+
}).ToArray());
18+
}
19+
}
20+
}

Models/DataSource.cs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
namespace Url_Adaptor.Models
2+
{
3+
public static class DataSource
4+
{
5+
private static IList<Event>? _eventsData { get; set; }
6+
7+
public static IList<Event> GetEvents()
8+
{
9+
if (_eventsData != null)
10+
{
11+
return _eventsData;
12+
}
13+
14+
_eventsData = new List<Event>();
15+
16+
Event related = new Event
17+
{
18+
Id = 1,
19+
Subject = "Explosion of Betelgeuse Star",
20+
Location = "Space Centre USA",
21+
StartTime = new DateTime(2022, 12, 5, 9, 30, 0),
22+
EndTime = new DateTime(2022, 12, 5, 11, 0, 0),
23+
OwnerId = 1
24+
};
25+
_eventsData.Add(related);
26+
27+
Event events = new Event
28+
{
29+
Id = 2,
30+
Subject = "Thule Air Crash Report",
31+
Location = "Newyork City",
32+
StartTime = new DateTime(2022, 12, 6, 12, 0, 0),
33+
EndTime = new DateTime(2022, 12, 6, 14, 0, 0),
34+
OwnerId = 2
35+
};
36+
_eventsData.Add(events);
37+
38+
events = new Event
39+
{
40+
Id = 3,
41+
Subject = "Blue Moon Eclipse",
42+
Location = "Space Centre USA",
43+
StartTime = new DateTime(2022, 12, 7, 9, 30, 0),
44+
EndTime = new DateTime(2022, 12, 7, 11, 0, 0),
45+
OwnerId = 3
46+
};
47+
_eventsData.Add(events);
48+
49+
events = new Event
50+
{
51+
Id = 4,
52+
Subject = "Meteor Showers in 2018",
53+
Location = "Space Centre USA",
54+
StartTime = new DateTime(2022, 12, 8, 13, 0, 0),
55+
EndTime = new DateTime(2022, 12, 8, 14, 30, 0),
56+
OwnerId = 1
57+
};
58+
_eventsData.Add(events);
59+
60+
events = new Event
61+
{
62+
Id = 5,
63+
Subject = "Milky Way as Melting pot",
64+
Location = "Space Centre USA",
65+
StartTime = new DateTime(2022, 12, 9, 12, 0, 0),
66+
EndTime = new DateTime(2022, 12, 9, 14, 0, 0),
67+
OwnerId = 2
68+
};
69+
_eventsData.Add(events);
70+
71+
events = new Event
72+
{
73+
Id = 6,
74+
Subject = "Mysteries of Bermuda Triangle",
75+
Location = "Bermuda",
76+
StartTime = new DateTime(2022, 12, 9, 9, 30, 0),
77+
EndTime = new DateTime(2022, 12, 9, 11, 0, 0),
78+
OwnerId = 3
79+
};
80+
_eventsData.Add(events);
81+
82+
events = new Event
83+
{
84+
Id = 7,
85+
Subject = "Glaciers and Snowflakes",
86+
Location = "Himalayas",
87+
StartTime = new DateTime(2022, 12, 10, 11, 0, 0),
88+
EndTime = new DateTime(2022, 12, 10, 12, 30, 0),
89+
OwnerId = 1
90+
};
91+
_eventsData.Add(events);
92+
93+
events = new Event
94+
{
95+
Id = 8,
96+
Subject = "Life on Mars",
97+
Location = "Space Centre USA",
98+
StartTime = new DateTime(2022, 12, 11, 9, 0, 0),
99+
EndTime = new DateTime(2022, 12, 11, 10, 0, 0),
100+
OwnerId = 2
101+
};
102+
_eventsData.Add(events);
103+
104+
events = new Event
105+
{
106+
Id = 9,
107+
Subject = "Alien Civilization",
108+
Location = "Space Centre USA",
109+
StartTime = new DateTime(2022, 12, 13, 11, 0, 0),
110+
EndTime = new DateTime(2022, 12, 13, 13, 0, 0),
111+
OwnerId = 3
112+
};
113+
_eventsData.Add(events);
114+
115+
return _eventsData;
116+
}
117+
}
118+
}

Models/Event.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Url_Adaptor.Models
2+
{
3+
public class Event
4+
{
5+
public int Id { get; set; }
6+
public string? Subject { get; set; }
7+
public DateTime StartTime { get; set; }
8+
public DateTime EndTime { get; set; }
9+
public string? StartTimezone { get; set; }
10+
public string? EndTimezone { get; set; }
11+
public string? Location { get; set; }
12+
public string? Description { get; set; }
13+
public bool? IsAllDay { get; set; }
14+
public bool? IsBlock { get; set; }
15+
public bool? IsReadOnly { get; set; }
16+
public int? FollowingID { get; set; }
17+
public int? RecurrenceID { get; set; }
18+
public string? RecurrenceRule { get; set; }
19+
public string? RecurrenceException { get; set; }
20+
public int? OwnerId { get; set; }
21+
public Guid? Guid { get; set; }
22+
}
23+
}

Models/Params.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Url_Adaptor.Models
2+
{
3+
public class Params
4+
{
5+
public DateTime StartDate { get; set; }
6+
public DateTime EndDate { get; set; }
7+
}
8+
}

Pages/Counter.razor

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page "/counter"
2+
3+
<PageTitle>Counter</PageTitle>
4+
5+
<h1>Counter</h1>
6+
7+
<p role="status">Current count: @currentCount</p>
8+
9+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
10+
11+
@code {
12+
private int currentCount = 0;
13+
14+
private void IncrementCount()
15+
{
16+
currentCount++;
17+
}
18+
}

0 commit comments

Comments
 (0)