Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using O2NextGen.ESender.Api.Helpers;
using O2NextGen.ESender.Api.Mappings;
using O2NextGen.ESender.Api.Models;
using O2NextGen.ESender.Business.Services;

namespace O2NextGen.ESender.Api.Controllers
{
[Route("board")]
public class BoardController : Controller
{
private readonly IEmailSender _emailSender;
private readonly IEmailSenderService _emailSenderService;

public BoardController(IEmailSender emailSender, IEmailSenderService emailSenderService)
{
_emailSender = emailSender;
_emailSenderService = emailSenderService;
}

[HttpGet]
[Route("")]
public async Task<IActionResult> Index()
{
var models = await _emailSenderService.GetAllAsync(CancellationToken.None);
return View(models.ToViewModel());
}

[HttpGet]
[Route("{id}")]
public async Task<IActionResult> Detail(long id)
{
var emailRequest = await _emailSenderService.GetByIdAsync(id, CancellationToken.None);
if (emailRequest == null)
return NotFound();
return View(emailRequest.ToViewModel());
}

[HttpPost]
[Route("id")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(long id, MailRequestViewModel model)
{
var certificate = await _emailSenderService.GetByIdAsync(id, CancellationToken.None);
if (certificate == null)
return NotFound();
certificate.From = model.From;
certificate.To = model.To;
certificate.Subject = model.Subject;
certificate.Body = model.Body;

return RedirectToAction("Index");
}

[HttpGet]
[Route("create")]
public IActionResult Create()
{
return View();
}

[HttpPost]
[Route("")]
public async Task<IActionResult> CreateReally(MailRequestViewModel model)
{
var emailRequest = await _emailSenderService.AddAsync(model.ToModel(), CancellationToken.None);
await _emailSender.Send(model.To, model.Subject, model.Body);
return RedirectToAction("Index");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using O2NextGen.ESender.Api.Helpers;
Expand All @@ -10,66 +8,69 @@

namespace O2NextGen.ESender.Api.Controllers
{
[Route("emailsender")]
public class EmailSenderController : Controller
[Route("api/[controller]")]
public class EmailSenderController : ControllerBase
{
#region Fields

private readonly IEmailSender _emailSender;
private readonly IEmailSenderService _emailSenderService;

#endregion

#region Ctors
public EmailSenderController(IEmailSender emailSender, IEmailSenderService emailSenderService)
{
_emailSender = emailSender;
_emailSenderService = emailSenderService;
}
#endregion

#region Methods

[HttpGet]
[Route("")]
public async Task<IActionResult> Index()
public async Task<IActionResult> GetAllAsync()
{
var models = await _emailSenderService.GetAllAsync(CancellationToken.None);
return View(models.ToViewModel());
return Ok(models.ToViewModel());
}

[HttpGet]
[Route("{id}")]
public async Task<IActionResult> Detail(long id)
public async Task<IActionResult> GetByIdAsync(long id, CancellationToken ct)
{
var emailRequest =await _emailSenderService.GetByIdAsync(id, CancellationToken.None);
if (emailRequest == null)
var certificate = await _emailSenderService.GetByIdAsync(id, ct);
if (certificate == null)
return NotFound();
return View(emailRequest.ToViewModel());
return Ok(certificate.ToViewModel());
}

[HttpPost]
[HttpPut]
[Route("id")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(long id, MailRequestViewModel model)
public async Task<IActionResult> UpdateAsync(long id, MailRequestViewModel model, CancellationToken ct)
{
var certificate = await _emailSenderService.GetByIdAsync(id, CancellationToken.None);
if (certificate == null)
return NotFound();
certificate.From = model.From;
certificate.To = model.To;
certificate.Subject = model.Subject;
certificate.Body = model.Body;

return RedirectToAction("Index");
var certificate = await _emailSenderService.UpdateAsync(model.ToModel(), ct);
return Ok(certificate.ToViewModel());
}

[HttpGet]
[Route("create")]
public IActionResult Create()
[HttpPost]
[HttpPut]
[Route("")]
public async Task<IActionResult> AddAsync(MailRequestViewModel model, CancellationToken ct)
{
return View();
var certificate = await _emailSenderService.AddAsync(model.ToModel(), ct);
return CreatedAtAction(nameof(GetByIdAsync), new {id = certificate.Id}, certificate);
}

[HttpPost]
[Route("")]
public async Task<IActionResult> CreateReally(MailRequestViewModel model)
#endregion

[HttpDelete]
[Route("id")]
public async Task<IActionResult> RemoveAsync(long id,CancellationToken ct)
{
var emailRequest = await _emailSenderService.AddAsync(model.ToModel(), CancellationToken.None);
await _emailSender.Send(model.To, model.Subject, model.Body);
return RedirectToAction("Index");
await _emailSenderService.RemoveAsync(id, ct);
return NoContent();
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.EntityFrameworkCore;

namespace O2NextGen.ESender.Api.Filters
{
public class ApiExceptionFilter: IExceptionFilter

{
public void OnException(ExceptionContext context)
{
if (context.ExceptionHandled is DbUpdateConcurrencyException)
{
context.Result =
new ConflictObjectResult(new {Message = "Entity was updated, please refresh your copy."});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using O2NextGen.ESender.Api.Filters;
using O2NextGen.ESender.Api.Helpers;
using O2NextGen.ESender.Business.Services;
using O2NextGen.ESender.Impl.Services;
Expand Down Expand Up @@ -34,5 +36,15 @@ public static IServiceCollection AddBusiness(this IServiceCollection services)
services.AddSingleton<IEmailSender, EmailSender>();
return services;
}

public static IServiceCollection AddRequiredMvcComponents(this IServiceCollection services)
{
services.AddTransient<ApiExceptionFilter>();

var mvcBuilder = services.AddMvcCore(options => { options.Filters.Add<ApiExceptionFilter>(); });
mvcBuilder.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
mvcBuilder.AddJsonFormatters();
return services;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Folder Include="wwwroot\" />
<Folder Include="Models\" />
<Folder Include="Views\" />
<Folder Include="Views\EmailSender\" />
<Folder Include="Views\Board\" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 12 additions & 1 deletion src/Services/e-sender/O2NextGen.ESender.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Builder;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -35,6 +36,16 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseHsts();
}
app.Use(async (context, next) =>
{
context.Response.OnStarting(() =>
{
context.Response.Headers.Add("X-Power-By", "O2NextGen: E-Sender");
return Task.CompletedTask;
});

await next.Invoke();
});
app.UseHttpsRedirection();
app.UseMvc();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model MailRequestViewModel

<form asp-controller="EmailSender" asp-action="CreateReally" method="post">
<form asp-controller="Board" asp-action="CreateReally" method="post">
<label asp-for="From">From</label>
<input asp-for="From" />
<label asp-for="To">To</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

@model MailRequestViewModel

<form asp-controller="EmailSender" asp-action="Edit" asp-route-id="@Model.Id">
<form asp-controller="Board" asp-action="Edit" asp-route-id="@Model.Id">
<label asp-for="From">From</label>
<input asp-for="From" />
<label asp-for="To">To</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@model IEnumerable<MailRequestViewModel>
<h1> E-Sender Service</h1>
<h2>Administration board v1.0.0.0</h2>
<style>
table { border-spacing: 5px;/*use to work like cellspacing */
width : 200px;
height: auto;
}

th, td { padding: 5px; } /*use to work like cellpadding */
</style>
<table>
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.From)
</th>
<th>
@Html.DisplayNameFor(model => model.To)
</th>
<th>
@Html.DisplayNameFor(model => model.Subject)
</th>
<th>
@Html.DisplayNameFor(model => model.Body)
</th>
</tr>
</thead>
<tbody>
@foreach (var b in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => b.Id)
</td>
<td>
@Html.DisplayFor(modelItem => b.From)
</td>
<td>
@Html.DisplayFor(modelItem => b.To)
</td>
<td>
@Html.DisplayFor(modelItem => b.Subject)
</td>
<td>
@Html.DisplayFor(modelItem => b.Body)
</td>
</tr>
}
</tbody>
</table>
@* @foreach (var certificate in Model) *@
@* { *@
@* <li> *@
@* @certificate.Id | @certificate.From | @certificate.To | @certificate.Subject | @certificate.Body *@
@* $1$ | <a asp-controller="Board" asp-action="Detail" asp-route-id="@certificate.Id">Edit</a> #1# *@
@* </li> *@
@* } *@

@* <a asp-controller="Board" asp-action="Create">Create</a> *@
Loading