basic crud dun
This commit is contained in:
parent
8930d4e20d
commit
1d61c35126
26
HanyadikHetVan/Controllers/PauseController.cs
Normal file
26
HanyadikHetVan/Controllers/PauseController.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs
Normal file
26
HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,10 @@
|
|||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" 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="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>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace HanyadikHetVan.Interface
|
namespace HanyadikHetVan.Interface
|
||||||
|
60
HanyadikHetVan/Services/PauseService.cs
Normal file
60
HanyadikHetVan/Services/PauseService.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
HanyadikHetVan/Services/WeeklyTimeSpanService.cs
Normal file
60
HanyadikHetVan/Services/WeeklyTimeSpanService.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,7 @@
|
|||||||
using HanyadikHetVan.Data;
|
using HanyadikHetVan.Data;
|
||||||
|
using HanyadikHetVan.Data.Entities;
|
||||||
|
using HanyadikHetVan.Interface;
|
||||||
|
using HanyadikHetVan.Repository;
|
||||||
using HanyadikHetVan.Services;
|
using HanyadikHetVan.Services;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
@ -8,6 +11,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
namespace HanyadikHetVan
|
namespace HanyadikHetVan
|
||||||
{
|
{
|
||||||
@ -26,6 +30,10 @@ namespace HanyadikHetVan
|
|||||||
services.AddDbContext<ApplicationDbContext>(options =>
|
services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
options.UseSqlServer(
|
options.UseSqlServer(
|
||||||
Configuration.GetConnectionString("DefaultConnection")));
|
Configuration.GetConnectionString("DefaultConnection")));
|
||||||
|
services.AddTransient<IRepository<Pause>, PauseRepository>();
|
||||||
|
services.AddTransient<IRepository<WeeklyTimeSpan>, WeeklyTimeSpanRepository>();
|
||||||
|
services.AddTransient<WeeklyTimeSpanService>();
|
||||||
|
services.AddTransient<PauseService>();
|
||||||
services.AddTransient<HanyadikHetVanJsonService>();
|
services.AddTransient<HanyadikHetVanJsonService>();
|
||||||
services.AddTransient<HanyadikHetVanService>();
|
services.AddTransient<HanyadikHetVanService>();
|
||||||
services.AddDatabaseDeveloperPageExceptionFilter();
|
services.AddDatabaseDeveloperPageExceptionFilter();
|
||||||
@ -61,6 +69,11 @@ namespace HanyadikHetVan
|
|||||||
services.AddRazorPages();
|
services.AddRazorPages();
|
||||||
|
|
||||||
services.AddControllers();
|
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.
|
// 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.UseDeveloperExceptionPage();
|
||||||
app.UseMigrationsEndPoint();
|
app.UseMigrationsEndPoint();
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "HanyadikHetVan v1"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user