GIGA BRAIN
GIGA BRAIN
CC#
Created by GIGA BRAIN on 8/9/2023 in #help
❔ Getting information from web api
135 replies
CC#
Created by GIGA BRAIN on 7/31/2023 in #help
❔ Question about setting up dependency injection (console app with no async stuff)
So I've been trying to set up a dependency injection in my program for the first time to no avail. From what I've learned, a dependency injection allows you to use methods from another class without having to explicitly instantiate a new instance of the class which allows for loosely coupled code and less dependencies. I was told I should be injecting my DBContext instead of calling a new context every time I do a database action. I think the way I have been approaching this fix is wrong in that I'm creating an interface for my Helpers class when in reality I should be making an interface for my PhoneBookContext class. Am I on the right track? Any feedback is appreciated. Pasted code: https://paste.mod.gg/hhwsmajvkxnq/2
78 replies
CC#
Created by GIGA BRAIN on 7/24/2023 in #help
❔ Program showing unwanted entries after multiple uses
69 replies
CC#
Created by GIGA BRAIN on 7/21/2023 in #help
❔ Program showing unwanted entries after multiple uses
38 replies
CC#
Created by GIGA BRAIN on 7/19/2023 in #help
❔ Adding database entries with EF Core
I'm completely new to EF Core. I have two tables, Contact and Number. The two tables are connected through FK ContactId in the Number table. I want to create an entry but not sure how I would be able to add information to both tables, here is the pastebin: https://paste.mod.gg/cilvbumgkbvh/0 (Also, does anyone know how to make a field a foreign key after i've done the add-migration and update-database?)
27 replies
CC#
Created by GIGA BRAIN on 6/21/2023 in #help
❔ Null warning from accessing weather results from an API call
174 replies
CC#
Created by GIGA BRAIN on 6/17/2023 in #help
❔ Accessing json results for a weather api console app
https://paste.mod.gg/jtzzrouisnhf/0 I'm trying to access the temperatures, but when I try to get back a list according to how i have it in the WeatherInfo.cs class, it doesn't work. Any suggestions?
20 replies
CC#
Created by GIGA BRAIN on 6/3/2023 in #help
Help with Simon game logic
I'm trying to code this game: https://github.com/dotnet/dotnet-console-games/tree/main/Projects/Simon I'm currently stuck on trying to add a pattern to a list. Currently I have an array (string[] Renders) that holds each frame state of the game and a method that shows one of the patterns randomly. My thought process on the game logic is that after every pattern is shown and correctly repeated, it is added to the list. Rinse and repeat, but obviously call the list with it's previous pattern history. Link to code: https://paste.mod.gg/qieexdztawyd/0
8 replies
CC#
Created by GIGA BRAIN on 6/2/2023 in #help
✅ Using an async method to print contents of an array
I'm trying to make a simon game and the next step I've decided on is that I need a method to draw the simon map. I'm using an async method so that I can delay the time in which it takes to show the next map, but when I call the method it only shows the first map. When I use the code without putting it inside a method, it works fine. I don't understand what I'm doing wrong:
29 replies
CC#
Created by GIGA BRAIN on 1/14/2023 in #help
❔ OOP Product Inventory Project
89 replies
CC#
Created by GIGA BRAIN on 1/12/2023 in #help
❔ OOP Help
BankAccount.cs
namespace Classes;

public class BankAccount
{
// These are fields / properties / characteristics
public string Number { get; set; }
public string Owner { get; set; }
public decimal Balance {
get
{
decimal balance = 0;
foreach (var item in allTransactions)
{
balance += item.Amount;
}
return balance;
}
}

// private = it can only be accessed by the code in THIS class (BankAccount)
// static = this is shared by all of the BankAccount objects
private static int accountNumberSeed = 1234567890;

private List<Transaction> allTransactions = new List<Transaction>();

// This is a constructor to assign values / initialize objects of this class type
public BankAccount(string name, decimal initialBalance)
{
Number = accountNumberSeed.ToString();
accountNumberSeed++;

Owner = name;
// MakeDeposit(initialBalance, DateTime.Now, "Initial balance");
}

// These are methods
public void MakeDeposit(decimal amount, DateTime date, string note)
{
if (amount <= 0)
{
throw new ArgumentOutOfRangeException(nameof(amount), "Amount of deposit must be positive");
var deposit = new Transaction(amount, date, note);
allTransactions.Add(deposit);
}
}

public void MakeWithdrawal(decimal amount, DateTime date, string note)
{
if (amount <= 0)
{
throw new ArgumentOutOfRangeException(nameof(amount), "Amount of withdrawal must be positive");
}
if (Balance - amount < 0)
{
throw new InvalidOperationException("Not enough sufficient funds for this withdrawal");
}
var withdrawal = new Transaction(-amount, date, note);
allTransactions.Add(withdrawal);
}
}
namespace Classes;

public class BankAccount
{
// These are fields / properties / characteristics
public string Number { get; set; }
public string Owner { get; set; }
public decimal Balance {
get
{
decimal balance = 0;
foreach (var item in allTransactions)
{
balance += item.Amount;
}
return balance;
}
}

// private = it can only be accessed by the code in THIS class (BankAccount)
// static = this is shared by all of the BankAccount objects
private static int accountNumberSeed = 1234567890;

private List<Transaction> allTransactions = new List<Transaction>();

// This is a constructor to assign values / initialize objects of this class type
public BankAccount(string name, decimal initialBalance)
{
Number = accountNumberSeed.ToString();
accountNumberSeed++;

Owner = name;
// MakeDeposit(initialBalance, DateTime.Now, "Initial balance");
}

// These are methods
public void MakeDeposit(decimal amount, DateTime date, string note)
{
if (amount <= 0)
{
throw new ArgumentOutOfRangeException(nameof(amount), "Amount of deposit must be positive");
var deposit = new Transaction(amount, date, note);
allTransactions.Add(deposit);
}
}

public void MakeWithdrawal(decimal amount, DateTime date, string note)
{
if (amount <= 0)
{
throw new ArgumentOutOfRangeException(nameof(amount), "Amount of withdrawal must be positive");
}
if (Balance - amount < 0)
{
throw new InvalidOperationException("Not enough sufficient funds for this withdrawal");
}
var withdrawal = new Transaction(-amount, date, note);
allTransactions.Add(withdrawal);
}
}
91 replies
CC#
Created by GIGA BRAIN on 1/3/2023 in #help
Binary To Decimal Program Help
13 replies