Now even map technic is implemented

This commit is contained in:
2023-04-23 12:52:46 +02:00
parent 0b69e0b13a
commit c9ee3e7f14
8 changed files with 386 additions and 7 deletions

View File

@ -0,0 +1,35 @@
@page "/map"
@inject HttpClient Http
<h3>Map</h3>
<SfMaps>
<MapsLayers>
<MapsLayer UrlTemplate="https://tile.openstreetmap.org/level/tileX/tileY.png" TValue="string">
<MapsMarkerSettings>
<MapsMarker Visible="true"
Shape="Syncfusion.Blazor.Maps.MarkerType.Circle"
DataSource="Contacts" Height="25" Width="15" TValue="Contact">
<MapsMarkerTooltipSettings Visible="true" ValuePath="Place"></MapsMarkerTooltipSettings>
</MapsMarker>
</MapsMarkerSettings>
</MapsLayer>
</MapsLayers>
<MapsZoomSettings Enable="true"
HorizontalAlignment="Syncfusion.Blazor.Maps.Alignment.Near"
ShouldZoomInitially="true"></MapsZoomSettings>
</SfMaps>
@code {
public List<Contact> Contacts { get; set; } = new List<Contact>();
protected override async Task OnInitializedAsync()
{
var result = await Http.GetFromJsonAsync<List<Contact>>("api/contacts/map");
if (result is not null)
{
Contacts = result;
}
}
}

View File

@ -17,4 +17,5 @@
@using Syncfusion.Blazor.Notifications @using Syncfusion.Blazor.Notifications
@using Syncfusion.Blazor.Popups @using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Cards @using Syncfusion.Blazor.Cards
@using Syncfusion.Blazor.Maps

View File

@ -7,6 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GoogleMaps.LocationServices" Version="1.2.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.0.5" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0-preview.3.23174.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0-preview.3.23174.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0-preview.3.23174.2"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0-preview.3.23174.2">

View File

@ -1,5 +1,6 @@
using BlazorSyncfusionCrm.Server.Data; using BlazorSyncfusionCrm.Server.Data;
using BlazorSyncfusionCrm.Shared; using BlazorSyncfusionCrm.Shared;
using GoogleMaps.LocationServices;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@ -39,6 +40,8 @@ namespace BlazorSyncfusionCrm.Server.Controllers
[HttpPost] [HttpPost]
public async Task<ActionResult<Contact>> CreateContact(Contact contact) public async Task<ActionResult<Contact>> CreateContact(Contact contact)
{ {
SetLatLong(contact);
_context.Contacts.Add(contact); _context.Contacts.Add(contact);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return Ok(contact); return Ok(contact);
@ -59,6 +62,7 @@ namespace BlazorSyncfusionCrm.Server.Controllers
dbContact.DateOfBirth = contact.DateOfBirth; dbContact.DateOfBirth = contact.DateOfBirth;
dbContact.Place = contact.Place; dbContact.Place = contact.Place;
dbContact.DateUpdated = DateTime.Now; dbContact.DateUpdated = DateTime.Now;
SetLatLong(dbContact);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
@ -83,5 +87,29 @@ namespace BlazorSyncfusionCrm.Server.Controllers
return await GetAllContacts(); return await GetAllContacts();
} }
[HttpGet("map")]
public async Task<ActionResult<List<Contact>>> GetMapContacts()
{
return await _context.Contacts
.Where(c => !c.IsDeleted && c.Longitude != null && c.Latitude != null)
.ToListAsync();
}
MapPoint GetLatLong(Contact contact)
{
var gls = new GoogleLocationService("AIzaSyAGh2TGRfQu1UURz2PdJd4DWFFcOpT-jYA");
var latLong = gls.GetLatLongFromAddress(contact.Place);
return latLong;
}
void SetLatLong(Contact contact)
{
var latLong = GetLatLong(contact);
if(latLong != null)
{
contact.Latitude = latLong.Latitude;
contact.Longitude = latLong.Longitude;
}
}
} }
} }

View File

@ -0,0 +1,183 @@
// <auto-generated />
using System;
using BlazorSyncfusionCrm.Server.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace BlazorSyncfusionCrm.Server.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20230420200923_LatLong")]
partial class LatLong
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.0-preview.3.23174.2")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("BlazorSyncfusionCrm.Shared.Contact", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateCreated")
.HasColumnType("datetime2");
b.Property<DateTime>("DateDeleted")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateOfBirth")
.HasColumnType("datetime2");
b.Property<DateTime>("DateUpdated")
.HasColumnType("datetime2");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double?>("Latitude")
.HasColumnType("float");
b.Property<double?>("Longitude")
.HasColumnType("float");
b.Property<string>("NickName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Place")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Contacts");
b.HasData(
new
{
Id = 1,
DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(6899),
DateDeleted = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateOfBirth = new DateTime(2001, 8, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateUpdated = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
FirstName = "Peter",
IsDeleted = false,
LastName = "Parker",
NickName = "Spider-Man",
Place = "New York City"
},
new
{
Id = 2,
DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(6903),
DateDeleted = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateOfBirth = new DateTime(1970, 5, 29, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateUpdated = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
FirstName = "Tony",
IsDeleted = false,
LastName = "Stark",
NickName = "Iron Man",
Place = "Malibu"
},
new
{
Id = 3,
DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(6906),
DateDeleted = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateOfBirth = new DateTime(1915, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateUpdated = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
FirstName = "Bruce",
IsDeleted = false,
LastName = "Wayne",
NickName = "Batman",
Place = "Gotham City"
});
});
modelBuilder.Entity("BlazorSyncfusionCrm.Shared.Note", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ContactId")
.HasColumnType("int");
b.Property<DateTime>("DateCreated")
.HasColumnType("datetime2");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("ContactId");
b.ToTable("Notes");
b.HasData(
new
{
Id = 1,
ContactId = 1,
DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(7002),
Text = "With great power comes great responsibility."
},
new
{
Id = 2,
ContactId = 2,
DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(7006),
Text = "I'm Iron Man."
},
new
{
Id = 3,
ContactId = 3,
DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(7007),
Text = "I'm Batman!."
});
});
modelBuilder.Entity("BlazorSyncfusionCrm.Shared.Note", b =>
{
b.HasOne("BlazorSyncfusionCrm.Shared.Contact", "Contact")
.WithMany("Notes")
.HasForeignKey("ContactId");
b.Navigation("Contact");
});
modelBuilder.Entity("BlazorSyncfusionCrm.Shared.Contact", b =>
{
b.Navigation("Notes");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,123 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BlazorSyncfusionCrm.Server.Migrations
{
/// <inheritdoc />
public partial class LatLong : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<double>(
name: "Latitude",
table: "Contacts",
type: "float",
nullable: true);
migrationBuilder.AddColumn<double>(
name: "Longitude",
table: "Contacts",
type: "float",
nullable: true);
migrationBuilder.UpdateData(
table: "Contacts",
keyColumn: "Id",
keyValue: 1,
columns: new[] { "DateCreated", "Latitude", "Longitude" },
values: new object[] { new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(6899), null, null });
migrationBuilder.UpdateData(
table: "Contacts",
keyColumn: "Id",
keyValue: 2,
columns: new[] { "DateCreated", "Latitude", "Longitude" },
values: new object[] { new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(6903), null, null });
migrationBuilder.UpdateData(
table: "Contacts",
keyColumn: "Id",
keyValue: 3,
columns: new[] { "DateCreated", "Latitude", "Longitude" },
values: new object[] { new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(6906), null, null });
migrationBuilder.UpdateData(
table: "Notes",
keyColumn: "Id",
keyValue: 1,
column: "DateCreated",
value: new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(7002));
migrationBuilder.UpdateData(
table: "Notes",
keyColumn: "Id",
keyValue: 2,
column: "DateCreated",
value: new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(7006));
migrationBuilder.UpdateData(
table: "Notes",
keyColumn: "Id",
keyValue: 3,
column: "DateCreated",
value: new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(7007));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Latitude",
table: "Contacts");
migrationBuilder.DropColumn(
name: "Longitude",
table: "Contacts");
migrationBuilder.UpdateData(
table: "Contacts",
keyColumn: "Id",
keyValue: 1,
column: "DateCreated",
value: new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6043));
migrationBuilder.UpdateData(
table: "Contacts",
keyColumn: "Id",
keyValue: 2,
column: "DateCreated",
value: new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6047));
migrationBuilder.UpdateData(
table: "Contacts",
keyColumn: "Id",
keyValue: 3,
column: "DateCreated",
value: new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6050));
migrationBuilder.UpdateData(
table: "Notes",
keyColumn: "Id",
keyValue: 1,
column: "DateCreated",
value: new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6341));
migrationBuilder.UpdateData(
table: "Notes",
keyColumn: "Id",
keyValue: 2,
column: "DateCreated",
value: new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6345));
migrationBuilder.UpdateData(
table: "Notes",
keyColumn: "Id",
keyValue: 3,
column: "DateCreated",
value: new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6346));
}
}
}

View File

@ -53,6 +53,12 @@ namespace BlazorSyncfusionCrm.Server.Migrations
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<double?>("Latitude")
.HasColumnType("float");
b.Property<double?>("Longitude")
.HasColumnType("float");
b.Property<string>("NickName") b.Property<string>("NickName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
@ -69,7 +75,7 @@ namespace BlazorSyncfusionCrm.Server.Migrations
new new
{ {
Id = 1, Id = 1,
DateCreated = new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6043), DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(6899),
DateDeleted = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), DateDeleted = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateOfBirth = new DateTime(2001, 8, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), DateOfBirth = new DateTime(2001, 8, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateUpdated = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), DateUpdated = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
@ -82,7 +88,7 @@ namespace BlazorSyncfusionCrm.Server.Migrations
new new
{ {
Id = 2, Id = 2,
DateCreated = new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6047), DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(6903),
DateDeleted = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), DateDeleted = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateOfBirth = new DateTime(1970, 5, 29, 0, 0, 0, 0, DateTimeKind.Unspecified), DateOfBirth = new DateTime(1970, 5, 29, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateUpdated = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), DateUpdated = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
@ -95,7 +101,7 @@ namespace BlazorSyncfusionCrm.Server.Migrations
new new
{ {
Id = 3, Id = 3,
DateCreated = new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6050), DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(6906),
DateDeleted = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), DateDeleted = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateOfBirth = new DateTime(1915, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), DateOfBirth = new DateTime(1915, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified),
DateUpdated = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), DateUpdated = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
@ -136,21 +142,21 @@ namespace BlazorSyncfusionCrm.Server.Migrations
{ {
Id = 1, Id = 1,
ContactId = 1, ContactId = 1,
DateCreated = new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6341), DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(7002),
Text = "With great power comes great responsibility." Text = "With great power comes great responsibility."
}, },
new new
{ {
Id = 2, Id = 2,
ContactId = 2, ContactId = 2,
DateCreated = new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6345), DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(7006),
Text = "I'm Iron Man." Text = "I'm Iron Man."
}, },
new new
{ {
Id = 3, Id = 3,
ContactId = 3, ContactId = 3,
DateCreated = new DateTime(2023, 4, 17, 10, 8, 30, 665, DateTimeKind.Local).AddTicks(6346), DateCreated = new DateTime(2023, 4, 20, 22, 9, 23, 469, DateTimeKind.Local).AddTicks(7007),
Text = "I'm Batman!." Text = "I'm Batman!."
}); });
}); });

View File

@ -18,6 +18,8 @@ namespace BlazorSyncfusionCrm.Shared
public string Place { get; set; } = string.Empty; public string Place { get; set; } = string.Empty;
public bool IsDeleted { get; set; } public bool IsDeleted { get; set; }
public DateTime? DateOfBirth { get; set; } public DateTime? DateOfBirth { get; set; }
public double? Latitude { get; set; }
public double? Longitude { get; set; }
public DateTime DateCreated { get; set; } = DateTime.Now; public DateTime DateCreated { get; set; } = DateTime.Now;
public DateTime DateUpdated { get; set; } public DateTime DateUpdated { get; set; }
public DateTime DateDeleted { get; set; } public DateTime DateDeleted { get; set; }