Mapper NETMAUI-ba
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WorkFlowCheck.Common.DTO;
|
||||||
|
using WorkFlowCheck.MAUI.DataLayer.Entities;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.MAUI.Mapper
|
||||||
|
{
|
||||||
|
public class MapperProfile:Profile
|
||||||
|
{
|
||||||
|
public MapperProfile()
|
||||||
|
{
|
||||||
|
CreateMap<CheckPoint, CheckPointDTO>();
|
||||||
|
CreateMap<CheckPointDTO, CheckPoint>();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ using Microsoft.Extensions.Http;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using CommunityToolkit.Maui;
|
using CommunityToolkit.Maui;
|
||||||
using WorkFlowCheck.MAUI.DataLayer;
|
using WorkFlowCheck.MAUI.DataLayer;
|
||||||
|
using WorkFlowCheck.MAUI.Mapper;
|
||||||
|
|
||||||
namespace WorkFlowCheck.MAUI
|
namespace WorkFlowCheck.MAUI
|
||||||
{
|
{
|
||||||
@@ -13,6 +14,7 @@ namespace WorkFlowCheck.MAUI
|
|||||||
public static MauiApp CreateMauiApp()
|
public static MauiApp CreateMauiApp()
|
||||||
{
|
{
|
||||||
var builder = MauiApp.CreateBuilder();
|
var builder = MauiApp.CreateBuilder();
|
||||||
|
builder.Services.AddAutoMapper(typeof(MapperProfile));
|
||||||
// appsettings.json beállítása
|
// appsettings.json beállítása
|
||||||
string jsonFilePath = Path.Combine(FileSystem.AppDataDirectory, "appsettings.json");
|
string jsonFilePath = Path.Combine(FileSystem.AppDataDirectory, "appsettings.json");
|
||||||
// Másold a fájlt a Raw erőforrásokból az AppDataDirectory-ba, ha még nincs ott
|
// Másold a fájlt a Raw erőforrásokból az AppDataDirectory-ba, ha még nincs ott
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using AutoMapper;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -14,12 +15,14 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
public readonly HttpClient _httpClient;
|
public readonly HttpClient _httpClient;
|
||||||
public readonly AppDbContext _dbContext;
|
public readonly AppDbContext _dbContext;
|
||||||
public readonly IConfiguration _configuration;
|
public readonly IConfiguration _configuration;
|
||||||
|
public readonly IMapper _mapper;
|
||||||
|
|
||||||
public BaseService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext)
|
public BaseService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
|
_mapper = mapper;
|
||||||
|
|
||||||
var apiBaseUrl = configuration["ApiBaseUrl"]; // API-cím elérése a konfigurációból
|
var apiBaseUrl = configuration["ApiBaseUrl"]; // API-cím elérése a konfigurációból
|
||||||
_httpClient.BaseAddress = new Uri(apiBaseUrl);
|
_httpClient.BaseAddress = new Uri(apiBaseUrl);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using AutoMapper;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -10,12 +11,13 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using WorkFlowCheck.Common.DTO;
|
using WorkFlowCheck.Common.DTO;
|
||||||
using WorkFlowCheck.MAUI.DataLayer;
|
using WorkFlowCheck.MAUI.DataLayer;
|
||||||
|
using WorkFlowCheck.MAUI.DataLayer.Entities;
|
||||||
|
|
||||||
namespace WorkFlowCheck.MAUI.Services
|
namespace WorkFlowCheck.MAUI.Services
|
||||||
{
|
{
|
||||||
public class SyncService : BaseService, ISyncService
|
public class SyncService : BaseService, ISyncService
|
||||||
{
|
{
|
||||||
public SyncService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext) : base(httpClient, configuration, dbContext)
|
public SyncService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper) : base(httpClient, configuration, dbContext, mapper)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -39,14 +41,12 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
var checkPointList = await _dbContext.CheckPoints.ToListAsync();
|
var checkPointList = await _dbContext.CheckPoints.ToListAsync();
|
||||||
var missingItems = response.Data.CheckPointList.Where(f => !checkPointList.Any(s => s.Id == f.Id)).ToList();
|
var missingItems = response.Data.CheckPointList.Where(f => !checkPointList.Any(s => s.Id == f.Id)).ToList();
|
||||||
|
|
||||||
foreach (var item in missingItems) {
|
var missingCheckPoint = _mapper.Map<List<CheckPoint>>(missingItems);
|
||||||
|
|
||||||
}
|
_dbContext.CheckPoints.AddRange(missingCheckPoint);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ using WorkFlowCheck.Common.DTO;
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using WorkFlowCheck.MAUI.DataLayer;
|
using WorkFlowCheck.MAUI.DataLayer;
|
||||||
|
using AutoMapper;
|
||||||
|
|
||||||
namespace WorkFlowCheck.MAUI.Services
|
namespace WorkFlowCheck.MAUI.Services
|
||||||
{
|
{
|
||||||
public class UserService : BaseService, IUserService
|
public class UserService : BaseService, IUserService
|
||||||
{
|
{
|
||||||
public UserDTO? CurrentUser { get; private set; }
|
public UserDTO? CurrentUser { get; private set; }
|
||||||
public UserService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext) : base(httpClient, configuration, dbContext)
|
public UserService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper) : base(httpClient, configuration, dbContext, mapper)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync()
|
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync()
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||||
<PackageReference Include="CommunityToolkit.Maui" Version="8.0.1" />
|
<PackageReference Include="CommunityToolkit.Maui" Version="8.0.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.12">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.12">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
|||||||
Reference in New Issue
Block a user