diff --git a/BlazorSyncfusionCrm/Client/Pages/Map.razor b/BlazorSyncfusionCrm/Client/Pages/Map.razor
new file mode 100644
index 0000000..c3bc020
--- /dev/null
+++ b/BlazorSyncfusionCrm/Client/Pages/Map.razor
@@ -0,0 +1,35 @@
+@page "/map"
+@inject HttpClient Http
+
+
Map
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+@code {
+ public List Contacts { get; set; } = new List();
+
+ protected override async Task OnInitializedAsync()
+ {
+ var result = await Http.GetFromJsonAsync>("api/contacts/map");
+ if (result is not null)
+ {
+ Contacts = result;
+ }
+ }
+}
diff --git a/BlazorSyncfusionCrm/Client/_Imports.razor b/BlazorSyncfusionCrm/Client/_Imports.razor
index 50ab631..ab164e1 100644
--- a/BlazorSyncfusionCrm/Client/_Imports.razor
+++ b/BlazorSyncfusionCrm/Client/_Imports.razor
@@ -17,4 +17,5 @@
@using Syncfusion.Blazor.Notifications
@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Cards
+@using Syncfusion.Blazor.Maps
diff --git a/BlazorSyncfusionCrm/Server/BlazorSyncfusionCrm.Server.csproj b/BlazorSyncfusionCrm/Server/BlazorSyncfusionCrm.Server.csproj
index 465653e..ab0a90f 100644
--- a/BlazorSyncfusionCrm/Server/BlazorSyncfusionCrm.Server.csproj
+++ b/BlazorSyncfusionCrm/Server/BlazorSyncfusionCrm.Server.csproj
@@ -7,6 +7,7 @@
+
diff --git a/BlazorSyncfusionCrm/Server/Controllers/ContactsController.cs b/BlazorSyncfusionCrm/Server/Controllers/ContactsController.cs
index c182b5e..69d5a70 100644
--- a/BlazorSyncfusionCrm/Server/Controllers/ContactsController.cs
+++ b/BlazorSyncfusionCrm/Server/Controllers/ContactsController.cs
@@ -1,5 +1,6 @@
using BlazorSyncfusionCrm.Server.Data;
using BlazorSyncfusionCrm.Shared;
+using GoogleMaps.LocationServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@@ -39,6 +40,8 @@ namespace BlazorSyncfusionCrm.Server.Controllers
[HttpPost]
public async Task> CreateContact(Contact contact)
{
+ SetLatLong(contact);
+
_context.Contacts.Add(contact);
await _context.SaveChangesAsync();
return Ok(contact);
@@ -59,7 +62,8 @@ namespace BlazorSyncfusionCrm.Server.Controllers
dbContact.DateOfBirth = contact.DateOfBirth;
dbContact.Place = contact.Place;
dbContact.DateUpdated = DateTime.Now;
-
+ SetLatLong(dbContact);
+
await _context.SaveChangesAsync();
return Ok(contact);
@@ -83,5 +87,29 @@ namespace BlazorSyncfusionCrm.Server.Controllers
return await GetAllContacts();
}
+
+ [HttpGet("map")]
+ public async Task>> 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;
+ }
+ }
}
}
diff --git a/BlazorSyncfusionCrm/Server/Migrations/20230420200923_LatLong.Designer.cs b/BlazorSyncfusionCrm/Server/Migrations/20230420200923_LatLong.Designer.cs
new file mode 100644
index 0000000..8460d7b
--- /dev/null
+++ b/BlazorSyncfusionCrm/Server/Migrations/20230420200923_LatLong.Designer.cs
@@ -0,0 +1,183 @@
+//
+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
+ {
+ ///
+ 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("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("DateCreated")
+ .HasColumnType("datetime2");
+
+ b.Property("DateDeleted")
+ .HasColumnType("datetime2");
+
+ b.Property("DateOfBirth")
+ .HasColumnType("datetime2");
+
+ b.Property("DateUpdated")
+ .HasColumnType("datetime2");
+
+ b.Property("FirstName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
+
+ b.Property("LastName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Latitude")
+ .HasColumnType("float");
+
+ b.Property("Longitude")
+ .HasColumnType("float");
+
+ b.Property("NickName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("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("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ContactId")
+ .HasColumnType("int");
+
+ b.Property("DateCreated")
+ .HasColumnType("datetime2");
+
+ b.Property("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
+ }
+ }
+}
diff --git a/BlazorSyncfusionCrm/Server/Migrations/20230420200923_LatLong.cs b/BlazorSyncfusionCrm/Server/Migrations/20230420200923_LatLong.cs
new file mode 100644
index 0000000..06ac564
--- /dev/null
+++ b/BlazorSyncfusionCrm/Server/Migrations/20230420200923_LatLong.cs
@@ -0,0 +1,123 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace BlazorSyncfusionCrm.Server.Migrations
+{
+ ///
+ public partial class LatLong : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn(
+ name: "Latitude",
+ table: "Contacts",
+ type: "float",
+ nullable: true);
+
+ migrationBuilder.AddColumn(
+ 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));
+ }
+
+ ///
+ 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));
+ }
+ }
+}
diff --git a/BlazorSyncfusionCrm/Server/Migrations/DataContextModelSnapshot.cs b/BlazorSyncfusionCrm/Server/Migrations/DataContextModelSnapshot.cs
index 2ead768..ee2fe7f 100644
--- a/BlazorSyncfusionCrm/Server/Migrations/DataContextModelSnapshot.cs
+++ b/BlazorSyncfusionCrm/Server/Migrations/DataContextModelSnapshot.cs
@@ -53,6 +53,12 @@ namespace BlazorSyncfusionCrm.Server.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
+ b.Property("Latitude")
+ .HasColumnType("float");
+
+ b.Property("Longitude")
+ .HasColumnType("float");
+
b.Property("NickName")
.IsRequired()
.HasColumnType("nvarchar(max)");
@@ -69,7 +75,7 @@ namespace BlazorSyncfusionCrm.Server.Migrations
new
{
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),
DateOfBirth = new DateTime(2001, 8, 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
{
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),
DateOfBirth = new DateTime(1970, 5, 29, 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
{
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),
DateOfBirth = new DateTime(1915, 4, 7, 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,
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."
},
new
{
Id = 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."
},
new
{
Id = 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!."
});
});
diff --git a/BlazorSyncfusionCrm/Shared/Contact.cs b/BlazorSyncfusionCrm/Shared/Contact.cs
index 3012dcd..8ed50d5 100644
--- a/BlazorSyncfusionCrm/Shared/Contact.cs
+++ b/BlazorSyncfusionCrm/Shared/Contact.cs
@@ -18,6 +18,8 @@ namespace BlazorSyncfusionCrm.Shared
public string Place { get; set; } = string.Empty;
public bool IsDeleted { 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 DateUpdated { get; set; }
public DateTime DateDeleted { get; set; }