Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sav_bank/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
20 changes: 20 additions & 0 deletions sav_bank/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using sav_bank.presentation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sav_bank
{
internal class Program
{

private const string storageFile = "bank.txt";
static void Main(string[] args)
{
Console.WriteLine("Welcome to Sav Bank");
Presentaion.Present(storageFile);
}
}
}
36 changes: 36 additions & 0 deletions sav_bank/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("sav_bank")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("sav_bank")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("04e34733-76c1-48c2-98b4-a267db477078")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
99 changes: 99 additions & 0 deletions sav_bank/data/DataBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using sav_bank.model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;

namespace sav_bank.data
{
public class DataBase
{
public static bool AddData(Bank model, string fileName)
{
try
{
var currentData = GetData(fileName);
currentData.Add(model);

var options = new JsonSerializerOptions { WriteIndented = true };

string stringJson = JsonSerializer.Serialize(currentData, options: options);
File.WriteAllText(fileName, stringJson);
return true;
}
catch (System.Exception)
{

return false;
}


}

public static bool Update(Bank model, string fileName)
{
try
{
var currentData = GetData(fileName);

var index = currentData.IndexOf(model);
currentData[index] =model;

var options = new JsonSerializerOptions { WriteIndented = true };

string stringJson = JsonSerializer.Serialize(currentData, options: options);
File.WriteAllBytes(fileName, new byte[0]);
File.WriteAllText(fileName, stringJson);
return true;
}
catch (System.Exception)
{
return false;
}


}


public static List<Bank> GetData(string fileName)
{

try
{
string jsonString = File.ReadAllText(fileName);
List<Bank> bank = JsonSerializer.Deserialize<List<Bank>>(jsonString);
if (bank != null)
{
return bank;
}

return new List<Bank>();

}
catch (System.Exception)
{

return new List<Bank>();
}

}

public static Bank GetDataByUserId(string userId, string fileName)
{

var currentData = GetData(fileName);
if (currentData.Any())
{
var userData = currentData.SingleOrDefault(x => x.UserName == userId);

return userData;
}
else
{

return null;
}
}
}
}
16 changes: 16 additions & 0 deletions sav_bank/model/AccountSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sav_bank.model
{
public class AccountSummary
{
public string Date { get; set; }
public bool IsDeposit { get; set; }
public string Amount { get; set; }
public string CurrentBalance { get; set; }
}
}
101 changes: 101 additions & 0 deletions sav_bank/model/Bank.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using sav_bank.utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace sav_bank.model
{
public class Bank : IEquatable<Bank>
{
[JsonInclude]
public string UserId { get; private set; }
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
[JsonInclude]
public string AccountNumber { get; private set; }
public string Age { get; set; }
public string PhoneNumber { get; set; }
public byte[] PasswordHash { get; set; }
public byte[] PasswordSalt { get; set; }
[JsonInclude]
public decimal Balance { get; private set; }
public List<AccountSummary> AccountSummary { get; set; }
public Bank()
{

}

public Bank(string userName, string email, string phoneNumber, string firstName, string lastName, string age, byte[] passwordHash, byte[] passwordSalt)
{
UserId = PasswordHelper.GenerateUserId();
AccountNumber = PasswordHelper.GenerateAccountNumber();
UserName = userName;
Email = email;
Age = age;
FirstName = firstName;
LastName = lastName;
PhoneNumber = phoneNumber;
PasswordHash = passwordHash;
PasswordSalt = passwordSalt;
Balance = 0;
AccountSummary = new List<AccountSummary>();

}

public bool Equals(Bank other)
{
if (this.AccountNumber != other.AccountNumber) return false;
if (this.UserId != other.UserId) return false;


return true;
}

public decimal AddAcountBalance(decimal amount)
{
if(amount > 0)
{

this.Balance += amount;
AddSummary(amount.ToString(), true);
return this.Balance;
}
else
{
return -1;
}
}
public decimal Withdraw(decimal amount)
{
if (amount > 0 && this.Balance > 0 && this.Balance > amount)
{
this.Balance = this.Balance - amount;
AddSummary(amount.ToString(), false);
return this.Balance;
}
else
{
return -1;
}
}

private void AddSummary(string amount, bool isDeposit)
{
var summary = new AccountSummary()
{
Amount = amount,
Date = DateTime.Now.ToString(),
IsDeposit= isDeposit,
CurrentBalance = this.Balance.ToString(),

};

AccountSummary.Add(summary);
}
}
}
15 changes: 15 additions & 0 deletions sav_bank/model/Response.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sav_bank.model
{
public class BankResponse<T>
{
public string Code { get; set; }
public string Description { get; set; }
public T Data { get; set; }
}
}
19 changes: 19 additions & 0 deletions sav_bank/model/SignUpDtos.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sav_bank
{
public class SignUpDtos
{
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Age { get; set; }
public string PhoneNumber { get; set; }
public string Password { get; set; }
}
}
26 changes: 26 additions & 0 deletions sav_bank/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl.AsyncInterfaces" version="7.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.Configuration" version="7.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="7.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.Configuration.FileExtensions" version="7.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.Configuration.Json" version="7.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="7.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.FileProviders.Abstractions" version="7.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.FileProviders.Physical" version="7.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.FileSystemGlobbing" version="7.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.Primitives" version="7.0.0" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.IO" version="4.3.0" targetFramework="net472" />
<package id="System.Memory" version="4.5.5" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Runtime" version="4.3.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net472" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net472" />
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net472" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net472" />
<package id="System.Text.Encodings.Web" version="7.0.0" targetFramework="net472" />
<package id="System.Text.Json" version="7.0.0" targetFramework="net472" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
</packages>
Loading