Skip to content

Commit 6c28273

Browse files
committed
Updating
1 parent 7ab1e5e commit 6c28273

File tree

16 files changed

+258
-96
lines changed

16 files changed

+258
-96
lines changed

AzureDevOpsStateTracker.Functions/AzureDevOpsStateTracker.Functions.csproj

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@
33
<TargetFramework>netcoreapp3.1</TargetFramework>
44
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
55
<UserSecretsId>035287d5-0b94-46fd-b3a9-b927fdb7b8ed</UserSecretsId>
6+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
67
</PropertyGroup>
78
<ItemGroup>
89
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
9-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.17">
10-
<PrivateAssets>all</PrivateAssets>
11-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12-
</PackageReference>
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.17">
14-
<PrivateAssets>all</PrivateAssets>
15-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16-
</PackageReference>
17-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.13" />
10+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.18" />
1811
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
1912
</ItemGroup>
2013
<ItemGroup>

AzureDevOpsStateTracker.Functions/WorkItemFunctions.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
using AzureDevopsStateTracker.DTOs.Create;
2+
using AzureDevopsStateTracker.DTOs.Update;
3+
using AzureDevopsStateTracker.Services;
4+
using AzureDevOpsStateTracker.Functions.Extensions;
5+
using Microsoft.AspNetCore.Http;
16
using Microsoft.AspNetCore.Mvc;
27
using Microsoft.Azure.WebJobs;
38
using Microsoft.Azure.WebJobs.Extensions.Http;
4-
using Microsoft.AspNetCore.Http;
59
using Microsoft.Extensions.Logging;
6-
using AzureDevopsStateTracker.Services;
7-
using AzureDevOpsStateTracker.Functions.Extensions;
810
using Newtonsoft.Json;
9-
using AzureDevopsStateTracker.DTOs.Create;
10-
using AzureDevopsStateTracker.DTOs.Update;
11-
using System.Net;
1211
using System;
12+
using System.Net;
13+
using System.Threading.Tasks;
1314

1415
namespace AzureDevOpsStateTracker.Functions
1516
{
@@ -24,15 +25,15 @@ public WorkItemFunctions(
2425
}
2526

2627
[FunctionName("workitem")]
27-
public IActionResult Create(
28+
public async Task<IActionResult> Create(
2829
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
2930
ILogger log)
3031
{
3132

3233
try
3334
{
3435
var workItemDTO = JsonConvert.DeserializeObject<CreateWorkItemDTO>(req.GetBody());
35-
_azureDevopsStateTrackerService.Create(workItemDTO);
36+
await _azureDevopsStateTrackerService.Create(workItemDTO);
3637
}
3738
catch (Exception ex)
3839
{
@@ -43,14 +44,14 @@ public IActionResult Create(
4344
}
4445

4546
[FunctionName("workitem-update")]
46-
public IActionResult Update(
47+
public async Task<IActionResult> Update(
4748
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
4849
ILogger log)
4950
{
5051
try
5152
{
5253
var workItemDTO = JsonConvert.DeserializeObject<UpdatedWorkItemDTO>(req.GetBody());
53-
_azureDevopsStateTrackerService.Update(workItemDTO);
54+
await _azureDevopsStateTrackerService.Update(workItemDTO);
5455
}
5556
catch (Exception ex)
5657
{

AzureDevopsStateTracker/AzureDevopsStateTracker.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.18" />
910
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.16" />
1111
</ItemGroup>
1212

1313
</Project>

AzureDevopsStateTracker/DTOs/Create/CreateWorkItemDTO.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
using Newtonsoft.Json;
2+
using System.Text.Json.Serialization;
23

34
namespace AzureDevopsStateTracker.DTOs.Create
45
{
56
public class CreateWorkItemDTO
67
{
8+
[JsonPropertyName("resource")]
79
[JsonProperty("resource")]
810
public Resource Resource { get; set; }
911
}
1012

1113
public class Resource
1214
{
15+
[JsonPropertyName("id")]
1316
[JsonProperty("id")]
1417
public string Id { get; set; }
1518

19+
[JsonPropertyName("fields")]
1620
[JsonProperty("fields")]
1721
public Fields Fields { get; set; }
1822
}

AzureDevopsStateTracker/DTOs/Fields.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,76 @@
11
using Newtonsoft.Json;
22
using System;
3+
using System.Text.Json.Serialization;
34

45
namespace AzureDevopsStateTracker.DTOs
56
{
67
public class Fields
78
{
9+
[JsonPropertyName("System.AreaPath")]
810
[JsonProperty("System.AreaPath")]
911
public string AreaPath { get; set; }
1012

13+
[JsonPropertyName("System.TeamProject")]
1114
[JsonProperty("System.TeamProject")]
1215
public string TeamProject { get; set; }
1316

17+
[JsonPropertyName("System.IterationPath")]
1418
[JsonProperty("System.IterationPath")]
1519
public string IterationPath { get; set; }
1620

21+
[JsonPropertyName("System.AssignedTo")]
1722
[JsonProperty("System.AssignedTo")]
1823
public string AssignedTo { get; set; }
1924

25+
[JsonPropertyName("System.WorkItemType")]
2026
[JsonProperty("System.WorkItemType")]
2127
public string Type { get; set; }
2228

29+
[JsonPropertyName("System.CreatedDate")]
2330
[JsonProperty("System.CreatedDate")]
2431
public DateTime CreatedDate { get; set; }
2532

33+
[JsonPropertyName("System.CreatedBy")]
2634
[JsonProperty("System.CreatedBy")]
2735
public string CreatedBy { get; set; }
2836

37+
[JsonPropertyName("System.ChangedBy")]
2938
[JsonProperty("System.ChangedBy")]
3039
public string ChangedBy { get; set; }
3140

41+
[JsonPropertyName("System.State")]
3242
[JsonProperty("System.State")]
3343
public string State { get; set; }
3444

45+
[JsonPropertyName("System.Title")]
3546
[JsonProperty("System.Title")]
3647
public string Title { get; set; }
3748

49+
[JsonPropertyName("System.Tags")]
3850
[JsonProperty("System.Tags")]
3951
public string Tags { get; set; }
4052

53+
[JsonPropertyName("System.Parent")]
4154
[JsonProperty("System.Parent")]
42-
public string Parent { get; set; }
55+
public string Parent { get; set; }
4356

57+
[JsonPropertyName("Microsoft.VSTS.Scheduling.StoryPoints")]
4458
[JsonProperty("Microsoft.VSTS.Scheduling.StoryPoints")]
4559
public string StoryPoints { get; set; }
4660

61+
[JsonPropertyName("Microsoft.VSTS.Scheduling.OriginalEstimate")]
4762
[JsonProperty("Microsoft.VSTS.Scheduling.OriginalEstimate")]
4863
public string OriginalEstimate { get; set; }
4964

65+
[JsonPropertyName("Microsoft.VSTS.Scheduling.RemainingWork")]
5066
[JsonProperty("Microsoft.VSTS.Scheduling.RemainingWork")]
5167
public string RemainingWork { get; set; }
5268

69+
[JsonPropertyName("Microsoft.VSTS.Scheduling.Effort")]
5370
[JsonProperty("Microsoft.VSTS.Scheduling.Effort")]
5471
public string Effort { get; set; }
5572

73+
[JsonPropertyName("Microsoft.VSTS.Common.Activity")]
5674
[JsonProperty("Microsoft.VSTS.Common.Activity")]
5775
public string Activity { get; set; }
5876
}
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,73 @@
11
using Newtonsoft.Json;
22
using System;
3+
using System.Text.Json.Serialization;
34

45
namespace AzureDevopsStateTracker.DTOs.Update
56
{
67
public class UpdatedWorkItemDTO
78
{
9+
[JsonPropertyName("resource")]
810
[JsonProperty("resource")]
911
public Resource Resource { get; set; }
1012
}
1113

1214
public class Resource
1315
{
16+
[JsonPropertyName("workItemId")]
1417
[JsonProperty("workItemId")]
1518
public string WorkItemId { get; set; }
1619

20+
[JsonPropertyName("fields")]
1721
[JsonProperty("fields")]
1822
public ResourceFields Fields { get; set; }
1923

24+
[JsonPropertyName("revision")]
2025
[JsonProperty("revision")]
2126
public Revision Revision { get; set; }
2227
}
2328

2429
public class Revision
2530
{
31+
[JsonPropertyName("fields")]
2632
[JsonProperty("fields")]
2733
public Fields Fields { get; set; }
2834
}
2935

3036
public class ResourceFields
3137
{
38+
[JsonPropertyName("System.State")]
3239
[JsonProperty("System.State")]
3340
public OldNewValues State { get; set; }
3441

42+
[JsonPropertyName("Microsoft.VSTS.Common.StateChangeDate")]
3543
[JsonProperty("Microsoft.VSTS.Common.StateChangeDate")]
3644
public DateTimeOldNewValues StateChangeDate { get; set; }
3745

46+
[JsonPropertyName("System.ChangedBy")]
3847
[JsonProperty("System.ChangedBy")]
39-
public ChangedByOldNewValues ChangedBy { get; set; }
48+
public OldNewValues ChangedBy { get; set; }
4049
}
4150

4251
public class OldNewValues
4352
{
53+
[JsonPropertyName("oldValue")]
4454
[JsonProperty("oldValue")]
4555
public string OldValue { get; set; }
4656

57+
[JsonPropertyName("newValue")]
4758
[JsonProperty("newValue")]
4859
public string NewValue { get; set; }
4960
}
5061

5162
public class DateTimeOldNewValues
5263
{
64+
[JsonPropertyName("oldValue")]
5365
[JsonProperty("oldValue")]
5466
public DateTime OldValue { get; set; }
5567

68+
[JsonPropertyName("newValue")]
5669
[JsonProperty("newValue")]
5770
public DateTime NewValue { get; set; }
5871
}
5972

60-
public class ChangedByOldNewValues
61-
{
62-
[JsonProperty("oldValue")]
63-
public string OldValue { get; set; }
64-
65-
[JsonProperty("newValue")]
66-
public string NewValue { get; set; }
67-
}
6873
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
using AzureDevopsStateTracker.Extensions;
22
using System;
3+
using System.Runtime.InteropServices;
34

45
namespace AzureDevopsStateTracker.Data
56
{
67
public class DataBaseConfig
78
{
8-
public DataBaseConfig(string connectionsString, string schemaName = "dbo")
9+
public DataBaseConfig(string connectionsString, string schemaName = "dbo", TimeZoneInfo timeZoneInfo = null)
910
{
1011
if (connectionsString.IsNullOrEmpty())
1112
throw new ArgumentException("The ConnectionsString is required");
1213

14+
if (timeZoneInfo == null)
15+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
16+
timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time");
17+
else
18+
timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Brazil/East");
19+
1320
ConnectionsString = connectionsString;
1421
SchemaName = schemaName;
22+
TimeZoneInfo = timeZoneInfo;
1523
}
1624

1725
public static string ConnectionsString { get; private set; }
1826
public static string SchemaName { get; private set; }
27+
public static TimeZoneInfo TimeZoneInfo { get; private set; }
1928
}
2029
}

AzureDevopsStateTracker/Data/Repository.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Microsoft.EntityFrameworkCore;
55
using System;
66
using System.Collections.Generic;
7-
using System.Linq;
7+
using System.Threading.Tasks;
88

99
namespace AzureDevopsStateTracker.Data
1010
{
@@ -19,14 +19,14 @@ public Repository(AzureDevopsStateTrackerContext db)
1919
DbSet = db.Set<TEntity>();
2020
}
2121

22-
public virtual void Add(TEntity entity)
22+
public virtual async Task Add(TEntity entity)
2323
{
24-
DbSet.Add(entity);
24+
await DbSet.AddAsync(entity);
2525
}
2626

27-
public virtual void Add(IEnumerable<TEntity> entities)
27+
public virtual async Task Add(IEnumerable<TEntity> entities)
2828
{
29-
DbSet.AddRange(entities);
29+
await DbSet.AddRangeAsync(entities);
3030
}
3131

3232
public virtual void Update(TEntity entity)
@@ -44,22 +44,21 @@ public virtual void Delete(TEntity entity)
4444
DbSet.Remove(entity);
4545
}
4646

47-
public virtual TEntity GetById(string id)
47+
public virtual async Task<TEntity> GetById(string id)
4848
{
49-
return DbSet
50-
.Where(x => x.Id == id)
51-
.FirstOrDefault();
49+
return await DbSet
50+
.FirstOrDefaultAsync(x => x.Id == id);
5251
}
5352

54-
public bool Exist(string id)
53+
public async Task<bool> Exist(string id)
5554
{
56-
return DbSet
57-
.Any(x => x.Id == id);
55+
return await DbSet
56+
.AnyAsync(x => x.Id == id);
5857
}
59-
60-
public void SaveChanges()
58+
59+
public async Task SaveChangesAsync()
6160
{
62-
Db.SaveChanges();
61+
await Db.SaveChangesAsync();
6362
}
6463

6564
public void Dispose()

0 commit comments

Comments
 (0)