-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9958676
commit af83030
Showing
33 changed files
with
12,323 additions
and
12,280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AutoMapper" Version="9.0.0" /> | ||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.0.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<ActiveDebugProfile>ASPNETCore.Web</ActiveDebugProfile> | ||
</PropertyGroup> | ||
</Project> |
243 changes: 124 additions & 119 deletions
243
...ETCore/Controllers/FoodItemsController.cs → ...re.Web/Controllers/FoodItemsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,124 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using AspNetCoreAngularSignalR.Dtos; | ||
using AspNetCoreAngularSignalR.Hubs; | ||
using AspNetCoreAngularSignalR.Models; | ||
using AspNetCoreAngularSignalR.Repositories; | ||
using AutoMapper; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace AspNetCoreAngularSignalR.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class FoodItemsController : Controller | ||
{ | ||
private readonly IFoodRepository _foodRepository; | ||
private readonly IHubContext<CoolMessagesHub> _coolMessageHubContext; | ||
|
||
public FoodItemsController(IFoodRepository foodRepository, IHubContext<CoolMessagesHub> hubContext) | ||
{ | ||
_foodRepository = foodRepository; | ||
_coolMessageHubContext = hubContext; | ||
} | ||
|
||
[HttpGet] | ||
public ActionResult<List<FoodItemDto>> GetAllFoods() | ||
{ | ||
var foods = _foodRepository.GetAll(); | ||
return Ok(foods.Select(x => Mapper.Map<FoodItemDto>(x))); | ||
} | ||
|
||
[HttpGet] | ||
[Route("{id:int}", Name = nameof(GetSingleFood))] | ||
public ActionResult<FoodItemDto> GetSingleFood(int id) | ||
{ | ||
FoodItem foodItem = _foodRepository.GetSingle(id); | ||
|
||
if (foodItem == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(Mapper.Map<FoodItemDto>(foodItem)); | ||
} | ||
|
||
[HttpPost] | ||
public ActionResult AddFoodToList([FromBody] FoodItemDto viewModel) | ||
{ | ||
if (viewModel == null) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
FoodItem item = Mapper.Map<FoodItem>(viewModel); | ||
item.Created = DateTime.Now; | ||
FoodItem newFoodItem = _foodRepository.Add(item); | ||
|
||
_coolMessageHubContext.Clients.All.SendAsync("FoodAdded",newFoodItem); | ||
|
||
return CreatedAtRoute( | ||
nameof(GetSingleFood), | ||
new { id = newFoodItem.Id }, | ||
Mapper.Map<FoodItemDto>(newFoodItem)); | ||
} | ||
|
||
[HttpPut] | ||
[Route("{foodItemId:int}")] | ||
public ActionResult<FoodItemDto> UpdateFoodInList(int foodItemId, [FromBody] FoodItemDto viewModel) | ||
{ | ||
if (viewModel == null) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
|
||
FoodItem singleById = _foodRepository.GetSingle(foodItemId); | ||
|
||
if (singleById == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
singleById.ItemName = viewModel.ItemName; | ||
|
||
FoodItem newFoodItem = _foodRepository.Update(singleById); | ||
_coolMessageHubContext.Clients.All.SendAsync("FoodUpdated", newFoodItem); | ||
return Ok(Mapper.Map<FoodItemDto>(newFoodItem)); | ||
} | ||
|
||
[HttpDelete] | ||
[Route("{foodItemId:int}")] | ||
public ActionResult DeleteFoodFromList(int foodItemId) | ||
{ | ||
|
||
FoodItem singleById = _foodRepository.GetSingle(foodItemId); | ||
|
||
if (singleById == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
_foodRepository.Delete(foodItemId); | ||
|
||
_coolMessageHubContext.Clients.All.SendAsync("FoodDeleted"); | ||
return NoContent(); | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using AspNetCoreAngularSignalR.Dtos; | ||
using AspNetCoreAngularSignalR.Hubs; | ||
using AspNetCoreAngularSignalR.Models; | ||
using AspNetCoreAngularSignalR.Repositories; | ||
using AutoMapper; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace AspNetCoreAngularSignalR.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class FoodItemsController : Controller | ||
{ | ||
private readonly IFoodRepository _foodRepository; | ||
private readonly IHubContext<ChatHub> _chatHubContext; | ||
private readonly IMapper _mapper; | ||
|
||
public FoodItemsController( | ||
IFoodRepository foodRepository, | ||
IHubContext<ChatHub> hubContext, | ||
IMapper mapper) | ||
{ | ||
_foodRepository = foodRepository; | ||
_chatHubContext = hubContext; | ||
_mapper = mapper; | ||
} | ||
|
||
[HttpGet] | ||
public ActionResult<List<FoodItemDto>> GetAllFoods() | ||
{ | ||
var foods = _foodRepository.GetAll(); | ||
return Ok(foods.Select(x => _mapper.Map<FoodItemDto>(x))); | ||
} | ||
|
||
[HttpGet] | ||
[Route("{id:int}", Name = nameof(GetSingleFood))] | ||
public ActionResult<FoodItemDto> GetSingleFood(int id) | ||
{ | ||
FoodItem foodItem = _foodRepository.GetSingle(id); | ||
|
||
if (foodItem == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(_mapper.Map<FoodItemDto>(foodItem)); | ||
} | ||
|
||
[HttpPost] | ||
public ActionResult AddFoodToList([FromBody] FoodItemDto viewModel) | ||
{ | ||
if (viewModel == null) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
FoodItem item = _mapper.Map<FoodItem>(viewModel); | ||
item.Created = DateTime.Now; | ||
FoodItem newFoodItem = _foodRepository.Add(item); | ||
|
||
_chatHubContext.Clients.All.SendAsync("FoodAdded", newFoodItem); | ||
|
||
return CreatedAtRoute( | ||
nameof(GetSingleFood), | ||
new { id = newFoodItem.Id }, | ||
_mapper.Map<FoodItemDto>(newFoodItem)); | ||
} | ||
|
||
[HttpPut] | ||
[Route("{foodItemId:int}")] | ||
public ActionResult<FoodItemDto> UpdateFoodInList(int foodItemId, [FromBody] FoodItemDto viewModel) | ||
{ | ||
if (viewModel == null) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
|
||
FoodItem singleById = _foodRepository.GetSingle(foodItemId); | ||
|
||
if (singleById == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
singleById.ItemName = viewModel.ItemName; | ||
|
||
FoodItem newFoodItem = _foodRepository.Update(singleById); | ||
_chatHubContext.Clients.All.SendAsync("FoodUpdated", newFoodItem); | ||
return Ok(_mapper.Map<FoodItemDto>(newFoodItem)); | ||
} | ||
|
||
[HttpDelete] | ||
[Route("{foodItemId:int}")] | ||
public ActionResult DeleteFoodFromList(int foodItemId) | ||
{ | ||
|
||
FoodItem singleById = _foodRepository.GetSingle(foodItemId); | ||
|
||
if (singleById == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
_foodRepository.Delete(foodItemId); | ||
|
||
_chatHubContext.Clients.All.SendAsync("FoodDeleted"); | ||
return NoContent(); | ||
} | ||
} | ||
} |
22 changes: 11 additions & 11 deletions
22
backend/ASPNETCore/Dtos/FoodItemDto.cs → ...ETCore/ASPNETCore.Web/Dtos/FoodItemDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
using System; | ||
|
||
namespace AspNetCoreAngularSignalR.Dtos | ||
{ | ||
public class FoodItemDto | ||
{ | ||
public int Id { get; set; } | ||
public string ItemName { get; set; } | ||
public DateTime Created { get; set; } | ||
} | ||
} | ||
using System; | ||
|
||
namespace AspNetCoreAngularSignalR.Dtos | ||
{ | ||
public class FoodItemDto | ||
{ | ||
public int Id { get; set; } | ||
public string ItemName { get; set; } | ||
public DateTime Created { get; set; } | ||
} | ||
} |
31 changes: 14 additions & 17 deletions
31
...SPNETCore/Extensions/MappingExtensions.cs → ...TCore.Web/Extensions/MappingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
using AspNetCoreAngularSignalR.Dtos; | ||
using AspNetCoreAngularSignalR.Models; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace ASPNETCore.Extensions | ||
{ | ||
public static class MappingExtensions | ||
{ | ||
public static void AddMappingProfiles(this IServiceCollection services) | ||
{ | ||
AutoMapper.Mapper.Initialize(mapper => | ||
{ | ||
mapper.CreateMap<FoodItem, FoodItemDto>().ReverseMap(); | ||
}); | ||
} | ||
} | ||
} | ||
using ASPNETCore.Web.MappingProfiles; | ||
using AutoMapper; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace ASPNETCore.Extensions | ||
{ | ||
public static class MappingExtensions | ||
{ | ||
public static void AddMappingProfiles(this IServiceCollection services) | ||
{ | ||
services.AddAutoMapper(typeof(FoodMappings)); | ||
} | ||
} | ||
} |
28 changes: 14 additions & 14 deletions
28
backend/ASPNETCore/Hubs/CoolMessagesHub.cs → ...ASPNETCore/ASPNETCore.Web/Hubs/ChatHub.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
using System.Threading.Tasks; | ||
using AspNetCoreAngularSignalR.Models; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace AspNetCoreAngularSignalR.Hubs | ||
{ | ||
public class CoolMessagesHub : Hub | ||
{ | ||
public Task SendMessage(ChatMessage chatMessage) | ||
{ | ||
return Clients.All.SendAsync("Send", chatMessage); | ||
} | ||
} | ||
} | ||
using System.Threading.Tasks; | ||
using AspNetCoreAngularSignalR.Models; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace AspNetCoreAngularSignalR.Hubs | ||
{ | ||
public class ChatHub : Hub | ||
{ | ||
public Task SendMessage(ChatMessage chatMessage) | ||
{ | ||
return Clients.All.SendAsync("Send", chatMessage); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/ASPNETCore/ASPNETCore.Web/MappingProfiles/FoodMappings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using AspNetCoreAngularSignalR.Dtos; | ||
using AspNetCoreAngularSignalR.Models; | ||
using AutoMapper; | ||
|
||
namespace ASPNETCore.Web.MappingProfiles | ||
{ | ||
public class FoodMappings : Profile | ||
{ | ||
public FoodMappings() | ||
{ | ||
CreateMap<FoodItem, FoodItemDto>().ReverseMap(); | ||
} | ||
} | ||
} |
Oops, something went wrong.