Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read app credentials fom seed data. Fixes#284
- Loading branch information
julie
authored and
julie
committed
Mar 20, 2017
1 parent
1b71e73
commit a0dc685
Showing
12 changed files
with
201 additions
and
8 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
Slack.Automation/Promact.Core.Repository/AppCredentialRepository/AppCredentialRepository.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,51 @@ | ||
using Promact.Erp.DomainModel.DataRepository; | ||
using Promact.Erp.DomainModel.Models; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Promact.Core.Repository.AppCredentialRepository | ||
{ | ||
public class AppCredentialRepository : IAppCredentialRepository | ||
{ | ||
|
||
private readonly IRepository<AppCredential> _appCredentialDataRepository; | ||
|
||
public AppCredentialRepository(IRepository<AppCredential> appCredentialDataRepository) | ||
{ | ||
_appCredentialDataRepository = appCredentialDataRepository; | ||
} | ||
|
||
/// <summary> | ||
/// Get the app credentials of the given module - JJ | ||
/// </summary> | ||
/// <param name="module"></param> | ||
/// <returns>object of AppCredential</returns> | ||
public async Task<AppCredential> FetchAppCredentialByModule(string module) | ||
{ | ||
return await _appCredentialDataRepository.FirstOrDefaultAsync(x => x.Module == module); | ||
} | ||
|
||
/// <summary> | ||
/// Adds the app's credentials to the database - JJ | ||
/// </summary> | ||
/// <param name="appCredential"></param> | ||
/// <returns></returns> | ||
public async Task<int> AddAppCredentialAsync(AppCredential appCredential) | ||
{ | ||
AppCredential credential = await FetchAppCredentialByModule(appCredential?.Module); | ||
if (credential == null) | ||
{ | ||
appCredential.CreatedOn = DateTime.UtcNow.Date; | ||
_appCredentialDataRepository.Insert(appCredential); | ||
} | ||
else | ||
{ | ||
credential.ClientId = appCredential.ClientId; | ||
credential.ClientSecret = appCredential.ClientSecret; | ||
_appCredentialDataRepository.Update(credential); | ||
} | ||
return await _appCredentialDataRepository.SaveChangesAsync(); | ||
} | ||
|
||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Slack.Automation/Promact.Core.Repository/AppCredentialRepository/IAppCredentialRepository.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,22 @@ | ||
using Promact.Erp.DomainModel.Models; | ||
using System.Threading.Tasks; | ||
|
||
namespace Promact.Core.Repository.AppCredentialRepository | ||
{ | ||
public interface IAppCredentialRepository | ||
{ | ||
/// <summary> | ||
/// Get the app credentials of the given module - JJ | ||
/// </summary> | ||
/// <param name="module"></param> | ||
/// <returns>object of AppCredential</returns> | ||
Task<AppCredential> FetchAppCredentialByModule(string module); | ||
|
||
/// <summary> | ||
/// Adds the app's credentials to the database - JJ | ||
/// </summary> | ||
/// <param name="appCredential"></param> | ||
/// <returns></returns> | ||
Task<int> AddAppCredentialAsync(AppCredential appCredential); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
Slack.Automation/Promact.Erp.DomainModel/ApplicationClass/SeedData.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,11 @@ | ||
using Promact.Erp.DomainModel.Models; | ||
using System.Collections.Generic; | ||
|
||
|
||
namespace Promact.Erp.DomainModel.ApplicationClass | ||
{ | ||
public class SeedData | ||
{ | ||
public List<AppCredential> AppCredential { get; set; } | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
Slack.Automation/Promact.Erp.DomainModel/Models/AppCredential.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,16 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Promact.Erp.DomainModel.Models | ||
{ | ||
public class AppCredential : ModelBase | ||
{ | ||
[Required] | ||
public string Module { get; set; } | ||
|
||
[Required] | ||
public string ClientId { get; set; } | ||
|
||
[Required] | ||
public string ClientSecret { get; set; } | ||
} | ||
} |
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
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
25 changes: 25 additions & 0 deletions
25
Slack.Automation/Promact.Erp.Web/CredentialSeedData/credentialSeedData.example.json
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,25 @@ | ||
{ | ||
"AppCredential": [ | ||
{ | ||
"Module": "scrum", | ||
"ClientId": "234444.2532324", | ||
"ClientSecret": "jkdfsh76278234" | ||
|
||
}, | ||
{ | ||
"Module": "task", | ||
"ClientId": "87980.324324789", | ||
"ClientSecret": "lk87324jdf90978fd" | ||
}, | ||
{ | ||
"Module": "leave", | ||
"ClientId": "76896df789.435345", | ||
"ClientSecret": "ewrret4356fg3456" | ||
}, | ||
{ | ||
"Module": "redmine", | ||
"ClientId": "56365dfg456546.5654rgth6urt", | ||
"ClientSecret": "4567gfh56776trhrgh" | ||
} | ||
] | ||
} |
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
37 changes: 37 additions & 0 deletions
37
Slack.Automation/Promact.Erp.Web/Views/Home/OAuthAppCredential.cshtml
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,37 @@ | ||
|
||
@model Promact.Erp.DomainModel.Models.AppCredential | ||
@{ | ||
ViewBag.Title = "Enter App Credential"; | ||
Layout = null; | ||
} | ||
|
||
<h2>@ViewBag.Title.</h2> | ||
|
||
@using (Html.BeginForm("OAuthAppCredential", "Home", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) | ||
{ | ||
@Html.AntiForgeryToken() | ||
<h4>Change Password Form</h4> | ||
<hr /> | ||
@Html.ValidationSummary("", new { @class = "text-danger" }) | ||
<div class="form-group"> | ||
@Html.LabelFor(m => m.ClientId, new { @class = "col-md-2 control-label" }) | ||
<div class="col-md-10"> | ||
@Html.TextBoxFor(m => m.ClientId, new { @class = "form-control" }) | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
@Html.LabelFor(m => m.ClientSecret, new { @class = "col-md-2 control-label" }) | ||
<div class="col-md-10"> | ||
@Html.TextBoxFor(m => m.ClientSecret, new { @class = "form-control" }) | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="col-md-offset-2 col-md-10"> | ||
<input type="submit" value="Add" class="btn btn-default" /> | ||
</div> | ||
</div> | ||
} | ||
@section Scripts { | ||
@Scripts.Render("~/bundles/jqueryval") | ||
} |