Skip to content

Commit

Permalink
Merge pull request #129 from PlanBGmbH/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
MarkusMeyer13 authored Mar 3, 2020
2 parents 58a0790 + c21f963 commit 74e9bab
Show file tree
Hide file tree
Showing 28 changed files with 1,534 additions and 787 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.0.100
dotnet-version: 3.1.101
- name: Build with dotnet
run: dotnet build PlanB.Butler.sln --configuration Release

Expand All @@ -23,4 +23,15 @@ jobs:
with:
dotnet-version: 2.2.108
- name: Test with dotnet
run: dotnet test PlanB.Butler.Library/PlanB.Butler.Library.Test/PlanB.Butler.Library.Test.csproj --configuration Release
run: dotnet test PlanB.Butler.Library/PlanB.Butler.Library.Test/PlanB.Butler.Library.Test.csproj --configuration Release --collect:"Code Coverage"

test-service-library:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
- name: Test with dotnet
run: dotnet test PlanB.Butler.Services/PlanB.Butler.Services.Test/PlanB.Butler.Services.Test.csproj --configuration Release --collect:"Code Coverage"
10 changes: 8 additions & 2 deletions PlanB.Butler.Admin/PlanB.Butler.Admin/Contracts/IMealService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public interface IMealService
/// Creates the meal.
/// </summary>
/// <param name="meal">The meal.</param>
/// <returns>True or false.</returns>
Task<bool> CreateMeal(MealViewModel meal);
/// <returns>Meal.</returns>
Task<MealViewModel> CreateMeal(MealViewModel meal);

/// <summary>
/// Updates the meal.
Expand All @@ -40,5 +40,11 @@ public interface IMealService
/// <returns>Meal by Id.</returns>
Task<MealViewModel> GetMeal(string id);

/// <summary>
/// Deletes the meal.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>Succes or failure.</returns>
Task<bool> DeleteMeal(string id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public async Task<IActionResult> Edit(string id, [Bind("Id,CorrelationId,Date,Pr

if (this.ModelState.IsValid)
{

var result = await this.mealService.UpdateMeal(meal);
return this.RedirectToAction(nameof(this.Index));
}
Expand All @@ -94,7 +93,7 @@ public async Task<IActionResult> Edit(string id, [Bind("Id,CorrelationId,Date,Pr
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>Meal.</returns>
public async Task<IActionResult> Edit(string? id)
public async Task<IActionResult> Edit(string id)
{
if (string.IsNullOrEmpty(id))
{
Expand All @@ -110,5 +109,42 @@ public async Task<IActionResult> Edit(string? id)

return this.View(meal);
}

/// <summary>
/// Deletes the specified identifier.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>IActionResult.</returns>
public async Task<IActionResult> Delete(string id)
{
if (string.IsNullOrEmpty(id))
{
return this.NotFound();
}

var meal = await this.mealService.GetMeal(id);

if (meal == null)
{
return this.NotFound();
}

return this.View(meal);
}

/// <summary>
/// Deletes the confirmed.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>IActionResult.</returns>
[HttpPost]
[ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string id)
{
await this.mealService.DeleteMeal(id);

return this.RedirectToAction(nameof(this.Index));
}
}
}
24 changes: 21 additions & 3 deletions PlanB.Butler.Admin/PlanB.Butler.Admin/Services/MealService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public MealService(HttpClient httpClient, IConfiguration configuration)
/// <returns>
/// True or false.
/// </returns>
public async Task<bool> CreateMeal(MealViewModel meal)
public async Task<MealViewModel> CreateMeal(MealViewModel meal)
{
Guid correlationId = Guid.NewGuid();
meal.CorrelationId = correlationId;
Expand All @@ -63,8 +63,26 @@ public async Task<bool> CreateMeal(MealViewModel meal)
Util.AddDefaultEsbHeaders(httpRequestMessage, correlationId, this.config["FunctionsKey"]);
var result = await this.httpClient.SendAsync(httpRequestMessage);
result.EnsureSuccessStatusCode();
var success = result.IsSuccessStatusCode;
return success;

MealViewModel responseModel = JsonConvert.DeserializeObject<MealViewModel>(result.Content.ReadAsStringAsync().Result);
return responseModel;
}

/// <summary>
/// Deletes the meal.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>
/// Succes or failure.
/// </returns>
public async Task<bool> DeleteMeal(string id)
{
var uri = this.config["MealsUri"].TrimEnd('/') + "/" + id;

this.httpClient.DefaultRequestHeaders.Add(Constants.FunctionsKeyHeader, this.config["FunctionsKey"]);
var response = await this.httpClient.DeleteAsync(uri);

return response.IsSuccessStatusCode;
}

/// <summary>
Expand Down
50 changes: 50 additions & 0 deletions PlanB.Butler.Admin/PlanB.Butler.Admin/Views/Meal/Delete.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@model PlanB.Butler.Admin.Models.MealViewModel

@{
ViewData["Title"] = "Delete";
}

<h1>Delete</h1>

<h3>Are you sure you want to delete this?</h3>
<div>
<h4>MealViewModel</h4>
<hr />
<dl class="row">
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Id)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Id)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Date)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Date)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Price)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Price)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Name)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Restaurant)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Restaurant)
</dd>
</dl>

<form asp-action="Delete">
<input type="submit" value="Delete" class="btn btn-danger" /> |
<a asp-action="Index">Back to List</a>
</form>
</div>
30 changes: 18 additions & 12 deletions PlanB.Butler.Bot/Bots/TeamsBot.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
namespace PlanB.Butler.Bot
{
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Logging;
using System.Resources;
using System.Reflection;
// Copyright (c) PlanB. GmbH. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

// This bot is derived (view DialogBot<T>) from the TeamsACtivityHandler class currently included as part of this sample.
using System.Collections.Generic;
using System.Reflection;
using System.Resources;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Logging;

namespace PlanB.Butler.Bot
{
/// <summary>
/// This bot is derived (view DialogBot<T>) from the TeamsACtivityHandler class currently included as part of this sample.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <seealso cref="PlanB.Butler.Bot.DialogBot{T}" />
public class TeamsBot<T> : DialogBot<T> where T : Dialog
{
/// <summary>
Expand Down
25 changes: 18 additions & 7 deletions PlanB.Butler.Bot/Dialogs/NextOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ public NextOrder(IOptions<BotConfig> config, IBotTelemetryClient telemetryClient
// This array defines how the Waterfall will execute.
var waterfallSteps = new WaterfallStep[]
{
CompanyStepAsync,
this.CompanyStepAsync,
NameStepAsync,
RestaurantStepAsync,
QuantatyStepAsync,
QuantityStepAsync,
FoodStepAsync,
MealQuantatyStepAsync,
MealQuantityStepAsync,
PriceStepAsync,
SummaryStepAsync,
this.SummaryStepAsync,
};

// Add named dialogs to the DialogSet. These names are saved in the dialog state.
Expand Down Expand Up @@ -280,7 +280,13 @@ private static async Task<DialogTurnResult> RestaurantStepAsync(WaterfallStepCon
}
}

private static async Task<DialogTurnResult> QuantatyStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
/// <summary>
/// Quantities the step asynchronous.
/// </summary>
/// <param name="stepContext">The step context.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>DialogTurnResult.</returns>
private static async Task<DialogTurnResult> QuantityStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
try
{
Expand Down Expand Up @@ -364,8 +370,13 @@ private static async Task<DialogTurnResult> FoodStepAsync(WaterfallStepContext s
}
}


private static async Task<DialogTurnResult> MealQuantatyStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
/// <summary>
/// Meals the quantity step asynchronous.
/// </summary>
/// <param name="stepContext">The step context.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>DialogTurnResult.</returns>
private static async Task<DialogTurnResult> MealQuantityStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var obj = ((FoundChoice)stepContext.Result).Value;
if (stepContext.Values["rest1"].ToString() == "yes")
Expand Down
8 changes: 8 additions & 0 deletions PlanB.Butler.Bot/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Makes no sense due to Generic", Scope = "type", Target = "~T:PlanB.Butler.Bot.TeamsBot`1")]
8 changes: 7 additions & 1 deletion PlanB.Butler.Bot/PlanB.Butler.Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>latest</LangVersion>
<Company>PlanB. GmbH</Company>
<Product>PlanB Butler Bot</Product>
<Authors>PlanB. GmbH</Authors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<CodeAnalysisRuleSet />
<OutputPath>bin\Release\netcoreapp2.2\</OutputPath>
<DocumentationFile>bin\Release\netcoreapp2.2\PlanB.Butler.Bot.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<CodeAnalysisRuleSet />
<OutputPath>bin\Debug\netcoreapp2.2\</OutputPath>
<DocumentationFile>bin\Debug\netcoreapp2.2\PlanB.Butler.Bot.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,7 +35,6 @@
</ItemGroup>

<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
<None Include="AdaptiveCard.json" />
</ItemGroup>

Expand Down
18 changes: 15 additions & 3 deletions PlanB.Butler.Bot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@
//
// Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.5.0

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace PlanB.Butler.Bot
{
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

/// <summary>
/// Program.
/// </summary>
public class Program
{
/// <summary>
/// Defines the entry point of the application.
/// </summary>
/// <param name="args">The arguments.</param>
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

/// <summary>
/// Creates the web host builder.
/// </summary>
/// <param name="args">The arguments.</param>
/// <returns>IWebHostBuilder.</returns>
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
Expand Down
1 change: 1 addition & 0 deletions PlanB.Butler.Bot/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Globalization;

using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class BackendCommunication
/// <param name="storageAccountUrl">The storage account URL.</param>
/// <param name="storageAccountKey">The storage account key.</param>
/// <returns></returns>
[Obsolete("Call function instead")]
public string GetDocument(string container, string resourceName, string storageAccountUrl, string storageAccountKey)
{
using (HttpClient httpClient = new HttpClient())
Expand Down Expand Up @@ -92,6 +93,7 @@ public string GenerateStorageSasTokenWrite(string resourceName, string storageAc
return sasToken;
}

[Obsolete("Call function instead")]
public HttpStatusCode PutDocument(string container, string resourceName, string body, string queueName, string serviceBusConnectionString)
{
string label = $"{container}/{resourceName}";
Expand Down Expand Up @@ -121,6 +123,7 @@ public HttpStatusCode PutDocument(string container, string resourceName, string
/// <param name="queueName">Name of the queue.</param>
/// <param name="serviceBusConnectionString">The service bus connection string.</param>
/// <returns></returns>
[Obsolete("Call function instead")]
public HttpStatusCode PutDocumentByteArray(string container, string resourceName, byte[] body, string queueName, string serviceBusConnectionString)
{
string label = $"{container}/{resourceName}";
Expand All @@ -139,6 +142,7 @@ public HttpStatusCode PutDocumentByteArray(string container, string resourceName
}
}

[Obsolete("Call function instead")]
public string GenerateServiceBusSasToken(string serviceBusConnectionString, string que)
{
var connectionString = serviceBusConnectionString;
Expand Down
Loading

0 comments on commit 74e9bab

Please sign in to comment.