forked from Vonage/vonage-dotnet-code-snippets
/
ApplicationController.cs
63 lines (56 loc) · 1.82 KB
/
ApplicationController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Nexmo.Api;
namespace NexmoDotnetCodeSnippets.Controllers
{
public class ApplicationController : Controller
{
public ApplicationController()
{
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult CreateApplication(string name)
{
var result = Senders.ApplicationSender.CreateApp(name);
ViewBag.creationResult = $"Your app {result.Name} has been created. ID {result.Id}";
return View("Index");
}
[HttpPost]
public ActionResult GetApplication(string id)
{
var APPLICATION_ID = id;
var results = Senders.ApplicationSender.GetApplication(id);
ViewBag.getResult = $"App public key: {results.Keys.PublicKey}";
return View("Index");
}
[HttpPost]
public ActionResult ListAvailableApplications()
{
var appList = Senders.ApplicationSender.GetAllApplications();
ViewBag.listResults = appList;
return View("Index");
}
[HttpPost]
public ActionResult UpdateApplication(string id, string name)
{
var result = Senders.ApplicationSender.UpdateApplication(id, name);
ViewBag.updateResult = $"Your app {result.Id} has been updated. ID {result.Name}";
return View("Index");
}
[HttpPost]
public ActionResult DeleteApplication(string id)
{
var result = Senders.ApplicationSender.DeleteApplication(id);
if (result)
ViewBag.deleteResult = "App deleted";
return View("Index");
}
}
}