IGeoLocationService interface and implementation
This commit is contained in:
parent
445b7b1b8f
commit
474758bc5b
@ -0,0 +1,28 @@
|
||||
namespace RMuseum.Models.Ganjoor.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// geo location view model
|
||||
/// </summary>
|
||||
public class GanjoorGeoLocationViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// id
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// geo location x
|
||||
/// </summary>
|
||||
public double X { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// geo location y
|
||||
/// </summary>
|
||||
public double Y { get; set; }
|
||||
}
|
||||
}
|
||||
@ -6364,6 +6364,31 @@
|
||||
total paragraphs
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjoorGeoLocationViewModel">
|
||||
<summary>
|
||||
geo location view model
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorGeoLocationViewModel.Id">
|
||||
<summary>
|
||||
id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorGeoLocationViewModel.Name">
|
||||
<summary>
|
||||
name
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorGeoLocationViewModel.X">
|
||||
<summary>
|
||||
geo location x
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorGeoLocationViewModel.Y">
|
||||
<summary>
|
||||
geo location y
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjooRhymeAnalysisResult">
|
||||
<summary>
|
||||
Rhyme Analysis Result
|
||||
@ -9368,6 +9393,47 @@
|
||||
<param name="userId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.IGeoLocationService">
|
||||
<summary>
|
||||
geo location service
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGeoLocationService.AddLocationAsync(System.String,System.Double,System.Double)">
|
||||
<summary>
|
||||
add new location
|
||||
</summary>
|
||||
<param name="name"></param>
|
||||
<param name="x"></param>
|
||||
<param name="y"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGeoLocationService.UpdateLocationAsync(RMuseum.Models.Ganjoor.ViewModels.GanjoorGeoLocationViewModel)">
|
||||
<summary>
|
||||
update an existing location
|
||||
</summary>
|
||||
<param name="updated"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGeoLocationService.DeleteLocationAsync(System.Int32)">
|
||||
<summary>
|
||||
delete location
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGeoLocationService.GetLocationAsync(System.Int32)">
|
||||
<summary>
|
||||
get location by id
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGeoLocationService.GetLocationsAsync">
|
||||
<summary>
|
||||
get all locations
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.Implementation.ArtifactService">
|
||||
<summary>
|
||||
IArtifactService implementation
|
||||
@ -11243,6 +11309,58 @@
|
||||
</summary>
|
||||
<param name="context"></param>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.Implementation.GeoLocationService">
|
||||
<summary>
|
||||
geo location service implementation
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GeoLocationService.AddLocationAsync(System.String,System.Double,System.Double)">
|
||||
<summary>
|
||||
add new location
|
||||
</summary>
|
||||
<param name="name"></param>
|
||||
<param name="x"></param>
|
||||
<param name="y"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GeoLocationService.UpdateLocationAsync(RMuseum.Models.Ganjoor.ViewModels.GanjoorGeoLocationViewModel)">
|
||||
<summary>
|
||||
update an existing location
|
||||
</summary>
|
||||
<param name="updated"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GeoLocationService.DeleteLocationAsync(System.Int32)">
|
||||
<summary>
|
||||
delete location
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GeoLocationService.GetLocationAsync(System.Int32)">
|
||||
<summary>
|
||||
get location by id
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GeoLocationService.GetLocationsAsync">
|
||||
<summary>
|
||||
get all locations
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="F:RMuseum.Services.Implementation.GeoLocationService._context">
|
||||
<summary>
|
||||
Database Context
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GeoLocationService.#ctor(RMuseum.DbContext.RMuseumDbContext)">
|
||||
<summary>
|
||||
constructor
|
||||
</summary>
|
||||
<param name="context"></param>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.Implementation.ImportedFromDesktopGanjoor.GPersianTextSync">
|
||||
<summary>
|
||||
Persian specific text utility class
|
||||
|
||||
48
RMuseum/Services/IGeoLocationService.cs
Normal file
48
RMuseum/Services/IGeoLocationService.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RMuseum.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// geo location service
|
||||
/// </summary>
|
||||
public interface IGeoLocationService
|
||||
{
|
||||
/// <summary>
|
||||
/// add new location
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorGeoLocationViewModel>> AddLocationAsync(string name, double x, double y);
|
||||
|
||||
/// <summary>
|
||||
/// update an existing location
|
||||
/// </summary>
|
||||
/// <param name="updated"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> UpdateLocationAsync(GanjoorGeoLocationViewModel updated);
|
||||
|
||||
/// <summary>
|
||||
/// delete location
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> DeleteLocationAsync(int id);
|
||||
|
||||
/// <summary>
|
||||
/// get location by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorGeoLocationViewModel>> GetLocationAsync(int id);
|
||||
|
||||
/// <summary>
|
||||
/// get all locations
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorGeoLocationViewModel[]>> GetLocationsAsync();
|
||||
}
|
||||
}
|
||||
185
RMuseum/Services/Implementation/GeoLocationService.cs
Normal file
185
RMuseum/Services/Implementation/GeoLocationService.cs
Normal file
@ -0,0 +1,185 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NetTopologySuite.Geometries;
|
||||
using RMuseum.DbContext;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RMuseum.Services.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// geo location service implementation
|
||||
/// </summary>
|
||||
public class GeoLocationService : IGeoLocationService
|
||||
{
|
||||
/// <summary>
|
||||
/// add new location
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorGeoLocationViewModel>> AddLocationAsync(string name, double x, double y)
|
||||
{
|
||||
name = name == null ? "" : name.Trim();
|
||||
if (string.IsNullOrEmpty(name))
|
||||
return new RServiceResult<GanjoorGeoLocationViewModel>(null, "نام اجباری است.");
|
||||
if (null != await _context.GanjoorGeoLocations.Where(l => l.Name == name).FirstOrDefaultAsync())
|
||||
return new RServiceResult<GanjoorGeoLocationViewModel>(null, "نام تکراری است.");
|
||||
Point point = new Point(x, y);
|
||||
if(null != await _context.GanjoorGeoLocations.Where(l => l.Location == point).FirstOrDefaultAsync())
|
||||
return new RServiceResult<GanjoorGeoLocationViewModel>(null, "مختصات تکراری است.");
|
||||
try
|
||||
{
|
||||
GanjoorGeoLocation location = new GanjoorGeoLocation()
|
||||
{
|
||||
Name = name,
|
||||
Location = point
|
||||
};
|
||||
_context.GanjoorGeoLocations.Add(location);
|
||||
await _context.SaveChangesAsync();
|
||||
return new RServiceResult<GanjoorGeoLocationViewModel>
|
||||
(
|
||||
new GanjoorGeoLocationViewModel()
|
||||
{
|
||||
Id = location.Id,
|
||||
Name = location.Name,
|
||||
X = location.Location.X,
|
||||
Y = location.Location.Y
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<GanjoorGeoLocationViewModel>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// update an existing location
|
||||
/// </summary>
|
||||
/// <param name="updated"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> UpdateLocationAsync(GanjoorGeoLocationViewModel updated)
|
||||
{
|
||||
try
|
||||
{
|
||||
var location = await _context.GanjoorGeoLocations.Where(l => l.Id == updated.Id).SingleOrDefaultAsync();
|
||||
if (location == null)
|
||||
return new RServiceResult<bool>(false, "اطلاعات مکان یافت نشد.");
|
||||
|
||||
location.Name = updated.Name;
|
||||
location.Location.X = updated.X;
|
||||
location.Location.Y = updated.Y;
|
||||
_context.Update(location);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// delete location
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> DeleteLocationAsync(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var location = await _context.GanjoorGeoLocations.Where(l => l.Id == id).SingleOrDefaultAsync();
|
||||
if (location == null)
|
||||
return new RServiceResult<bool>(false, "اطلاعات طرح مکان یافت نشد.");
|
||||
|
||||
_context.Remove(location);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get location by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorGeoLocationViewModel>> GetLocationAsync(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new RServiceResult<GanjoorGeoLocationViewModel>
|
||||
(
|
||||
await _context.GanjoorGeoLocations
|
||||
.Where(l => l.Id == id)
|
||||
.Select(l =>
|
||||
new GanjoorGeoLocationViewModel()
|
||||
{
|
||||
Id = l.Id,
|
||||
Name = l.Name,
|
||||
X = l.Location.X,
|
||||
Y = l.Location.Y
|
||||
})
|
||||
.SingleOrDefaultAsync()
|
||||
);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<GanjoorGeoLocationViewModel>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get all locations
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorGeoLocationViewModel[]>> GetLocationsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new RServiceResult<GanjoorGeoLocationViewModel[]>
|
||||
(
|
||||
await _context.GanjoorGeoLocations
|
||||
.Select(l =>
|
||||
new GanjoorGeoLocationViewModel()
|
||||
{
|
||||
Id = l.Id,
|
||||
Name = l.Name,
|
||||
X = l.Location.X,
|
||||
Y = l.Location.Y
|
||||
})
|
||||
.OrderBy(l => l.Name).ToArrayAsync()
|
||||
);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<GanjoorGeoLocationViewModel[]>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Database Context
|
||||
/// </summary>
|
||||
protected readonly RMuseumDbContext _context;
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public GeoLocationService(RMuseumDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -292,6 +292,9 @@ namespace RMuseum
|
||||
//numbering service
|
||||
services.AddTransient<IGanjoorNumberingService, GanjoorNumberingService>();
|
||||
|
||||
//geo location service
|
||||
services.AddTransient<IGeoLocationService, GeoLocationService>();
|
||||
|
||||
//upload limit for IIS
|
||||
services.Configure<IISServerOptions>(options =>
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user