basic crud dun

This commit is contained in:
Torma Kristóf 2021-05-03 18:15:26 +02:00
parent 8930d4e20d
commit 1d61c35126
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
7 changed files with 192 additions and 3 deletions

View File

@ -0,0 +1,26 @@
using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.Interface;
using HanyadikHetVan.Services;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace HanyadikHetVan.Controllers
{
[Route("api/pause")]
[ApiController]
public class PauseController
{
private readonly PauseService _pauseService;
private readonly IRepository<Pause> _pause;
public PauseController(IRepository<Pause> pause, PauseService pauseService)
{
_pauseService = pauseService;
_pause = pause;
}
}
}

View File

@ -0,0 +1,26 @@
using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.Interface;
using HanyadikHetVan.Services;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace HanyadikHetVan.Controllers
{
[Route("api/weeklytimespan")]
[ApiController]
public class WeeklyTimeSpanController
{
private readonly WeeklyTimeSpanService _weeklytimespanService;
private readonly IRepository<WeeklyTimeSpan> _weeklytimespan;
public WeeklyTimeSpanController(IRepository<WeeklyTimeSpan> weeklytimespan, WeeklyTimeSpanService weeklytimespanService)
{
_weeklytimespanService = weeklytimespanService;
_weeklytimespan = weeklytimespan;
}
}
}

View File

@ -15,6 +15,10 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.13" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.1.4" />
</ItemGroup>
</Project>

View File

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace HanyadikHetVan.Interface

View File

@ -0,0 +1,60 @@
using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace HanyadikHetVan.Services
{
public class PauseService
{
private readonly IRepository<Pause> _pause;
public PauseService(IRepository<Pause> pause)
{
_pause = pause ?? throw new ArgumentNullException(nameof(pause));
}
public IEnumerable<Pause> GetAllPauses()
{
return _pause.GetAll().ToList();
}
public async Task<Pause> AddPause(Pause pause)
{
return await _pause.Create(pause);
}
public bool DeletePause(int pauseId)
{
try
{
var item = _pause.GetAll().Where(x => x.Id == pauseId).FirstOrDefault();
_pause.Delete(item);
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdatePause(Pause pause)
{
try
{
var DataList = _pause.GetAll().ToList();
foreach (var item in DataList)
{
_pause.Update(item);
}
return true;
}
catch (Exception)
{
return true;
}
}
}
}

View File

@ -0,0 +1,60 @@
using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace HanyadikHetVan.Services
{
public class WeeklyTimeSpanService
{
private readonly IRepository<WeeklyTimeSpan> _weeklytimespan;
public WeeklyTimeSpanService(IRepository<WeeklyTimeSpan> weeklytimespan)
{
_weeklytimespan = weeklytimespan ?? throw new ArgumentNullException(nameof(weeklytimespan));
}
public IEnumerable<WeeklyTimeSpan> GetAllWeeklyTimeSpans()
{
return _weeklytimespan.GetAll().ToList();
}
public async Task<WeeklyTimeSpan> AddWeeklyTimeSpan(WeeklyTimeSpan weeklytimespan)
{
return await _weeklytimespan.Create(weeklytimespan);
}
public bool DeleteWeeklyTimeSpan(int weeklytimespanId)
{
try
{
var item = _weeklytimespan.GetAll().Where(x => x.Id == weeklytimespanId).FirstOrDefault();
_weeklytimespan.Delete(item);
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdateWeeklyTimeSpan(WeeklyTimeSpan weeklytimespan)
{
try
{
var DataList = _weeklytimespan.GetAll().ToList();
foreach (var item in DataList)
{
_weeklytimespan.Update(item);
}
return true;
}
catch (Exception)
{
return true;
}
}
}
}

View File

@ -1,4 +1,7 @@
using HanyadikHetVan.Data;
using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.Interface;
using HanyadikHetVan.Repository;
using HanyadikHetVan.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
@ -8,6 +11,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
namespace HanyadikHetVan
{
@ -26,6 +30,10 @@ namespace HanyadikHetVan
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddTransient<IRepository<Pause>, PauseRepository>();
services.AddTransient<IRepository<WeeklyTimeSpan>, WeeklyTimeSpanRepository>();
services.AddTransient<WeeklyTimeSpanService>();
services.AddTransient<PauseService>();
services.AddTransient<HanyadikHetVanJsonService>();
services.AddTransient<HanyadikHetVanService>();
services.AddDatabaseDeveloperPageExceptionFilter();
@ -61,6 +69,11 @@ namespace HanyadikHetVan
services.AddRazorPages();
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Hanyadik Het Van API", Version = "v1" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -70,6 +83,8 @@ namespace HanyadikHetVan
{
app.UseDeveloperExceptionPage();
app.UseMigrationsEndPoint();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "HanyadikHetVan v1"));
}
else
{