forked from sander1095/DnDCombatTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Saving to Core functionality, It's a Basic list of parties whic…
…h are lists of characters, Added newtonsoft to forms to it works. sander1095#6
- Loading branch information
1 parent
4b89c86
commit 3333636
Showing
8 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
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,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DnDCombatTracker.Core.Data | ||
{ | ||
public static class FileIO | ||
{ | ||
public static string GetFileString(string fileName, string folder) | ||
{ | ||
if (!File.Exists(string.Join("\\", folder, fileName))) | ||
{ | ||
return null; | ||
} | ||
|
||
var path = Path.GetFullPath(string.Join("\\", folder, fileName)); | ||
|
||
|
||
var str = File.ReadAllText(string.Join("\\", folder, fileName)); | ||
|
||
return str; | ||
} | ||
|
||
public static void SaveFileString(string fileName, string folder, string content) | ||
{ | ||
File.WriteAllText(string.Join("\\", folder, fileName), content); | ||
} | ||
} | ||
} |
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,7 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" /> | ||
</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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace DnDCombatTracker.Core | ||
{ | ||
public class Party | ||
{ | ||
public Guid partyId { get; set; } | ||
public string Name { get; set; } | ||
public List<Character> Characters { get; set; } | ||
public string Notes { get; set; } | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/DnDCombatTracker.Core/PartyManagement/PartyManagerService.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,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace DnDCombatTracker.Core | ||
{ | ||
public class PartyManagerService | ||
{ | ||
|
||
public List<Party> GetParties(string filename, string folder) | ||
{ | ||
var partyStr = Data.FileIO.GetFileString(filename, folder); | ||
|
||
if (partyStr == null) | ||
{ | ||
return new List<Party>(); | ||
} | ||
var parties = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Party>>(partyStr); | ||
|
||
return parties; | ||
} | ||
|
||
public void SaveParty(string filename, string folder, Party party) | ||
{ | ||
var parties = GetParties(filename, folder); | ||
|
||
var PartyToUpdate = parties.FirstOrDefault(x => x.partyId == party.partyId); | ||
|
||
if (PartyToUpdate == null) | ||
{ | ||
parties.Add(party); | ||
} | ||
else | ||
{ | ||
PartyToUpdate = party; | ||
} | ||
|
||
SaveParties(filename, folder, parties); | ||
} | ||
|
||
public void SaveParties(string filename, string folder, List<Party> parties) | ||
{ | ||
var partiesString = Newtonsoft.Json.JsonConvert.SerializeObject(parties); | ||
|
||
Data.FileIO.SaveFileString(filename, folder, partiesString); | ||
} | ||
} | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net461" /> | ||
</packages> |