Sonath
Sonath
CC#
Created by Sonath on 1/8/2024 in #help
✅ Opinion time: Handling multiple id's in the same path (ASP.NET MVC)
I want to make surveys and survey submissions. The URL will be something like /surveys/1/submissions/2 indicating that I'm checking the survey with id 1 that has the submission of id 2. There will be CRUD with Entity Framework for both surveys and submissions. Is this a good idea to use two different controllers, or can it be done on a single controller?
7 replies
CC#
Created by Sonath on 11/27/2023 in #help
Why does the following prints "Point" to the console instead of "(2, 3)"?
Point thing = new Point(2, 3);
System.Console.WriteLine(thing); // prints Point
System.Console.WriteLine(thing.ToString()); // prints (2, 3)

public class Point
{
public int X {get; private set; }
public int Y {get; private set; }

public Point(): this(0, 0)
{

}

public Point(int x, int y)
{
this.X = x;
this.Y = y;
}

// using NEW not OVERRIDE
public new string ToString()
{
return $"({X}, {Y})";
}
}
Point thing = new Point(2, 3);
System.Console.WriteLine(thing); // prints Point
System.Console.WriteLine(thing.ToString()); // prints (2, 3)

public class Point
{
public int X {get; private set; }
public int Y {get; private set; }

public Point(): this(0, 0)
{

}

public Point(int x, int y)
{
this.X = x;
this.Y = y;
}

// using NEW not OVERRIDE
public new string ToString()
{
return $"({X}, {Y})";
}
}
Is it because Console.WriteLine uses an object reference internally?
6 replies
CC#
Created by Sonath on 10/27/2023 in #help
✅ Need a good resource to learn how to build .NET Core Web API's
No description
14 replies
CC#
Created by Sonath on 10/26/2023 in #help
✅ Recommended way to handle null results from a repository GET action?
I'm learning .NET Core and in Java (yes, I did Java) I used to create custom exceptions to throw. The equivalent would be
var company = _repository.Company.GetCompany(companyId, trackChanges);
if (company is null)
throw new CompanyNotFoundException(companyId);
var company = _repository.Company.GetCompany(companyId, trackChanges);
if (company is null)
throw new CompanyNotFoundException(companyId);
Is this a good idea?
35 replies
CC#
Created by Sonath on 10/24/2023 in #help
❔ Referencing new projects with the main project
Let's say I have a main project CoreProject and I want to add 2 new projects: a LoggerService and a Contracts. The question is: Is it okay if I make LoggerService have a project reference with Contracts and then have CoreProject have a project reference with LoggerService? Does this mean that CoreProject also has a reference with Contracts because LoggerService has it?
4 replies