XD
XD
CC#
Created by XD on 11/9/2023 in #help
❔ (MVC web app) How can I handle exceptions/errors in this case?
No description
24 replies
CC#
Created by XD on 11/7/2023 in #help
❔ Why isn't one of my Identity user field being updated?
Code: https://gist.github.com/JsPeanut/b59cc1d4da3ababc532fe3b6e8a9ad69 The void ChangeUserCategoryValue, which is called at line 180 and 208, is responsible for changing user's corresponding field. It doesn't work for some reason and I can't figure it out
6 replies
CC#
Created by XD on 10/7/2023 in #help
❔ Show error text message under update text box through server validation without refreshing
No description
28 replies
CC#
Created by XD on 10/3/2023 in #help
❔ Form with put or delete method
Since I can't add a method="put" or "delete" to my forms, how else can I add a put or delete method to my forms? I want to execute a function from the controller after submitting the form that will update/delete. I'm not using actions because this is an SPA, and I can't do something like, specifying a post method in the form and then, in the .cshtmlcs write code for a PUT inside an OnPost function because it's an MVC app
11 replies
CC#
Created by XD on 9/19/2023 in #help
❔ Is there a way to make this more cleaner?
<div class="buttons">
<div class="dropdown">
<a button type="button" class="btn btn-success">
<svg>
<path></path>
</svg>
Add a new habit
</a>
<a button type="button" class="btn btn-success">
<svg>
<path></path>
</svg>
Log a habit
</a>
@*<div class="dropdown">*@
<button class="btn btn-success dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" asp-page="./Index" asp-route-sorttype="Today">Today</a>
<a class="dropdown-item" asp-page="./Index" asp-route-sorttype="Yesterday">Yesterday</a>
<a class="dropdown-item" asp-page="./Index" asp-route-sorttype="DateAdded">Date added</a>
<a class="dropdown-item" asp-page="./Index" asp-route-sorttype="AddedOrder">Added order</a>
<a class="dropdown-item search-link" asp-page="./Index">Search for date</a>
</div>
<br />
<form id="search" style="display: none;">
<p> Title: <input type="text" id="searchInput" asp-for="SearchString" /> <input type="submit" value="Filter" /> </p>
</form>
@*</div>*@
@{
if (Model.SumMessage != null)
{
<br />
<span style="white-space: pre-line">@Model.SumMessage</span>
}
}
</div>
</div>

@{
if (Model.SumMessage != null)
{
<br />
}
}
<br />
<table id="records" class="table">
<thead>
<tr>
...
<div class="buttons">
<div class="dropdown">
<a button type="button" class="btn btn-success">
<svg>
<path></path>
</svg>
Add a new habit
</a>
<a button type="button" class="btn btn-success">
<svg>
<path></path>
</svg>
Log a habit
</a>
@*<div class="dropdown">*@
<button class="btn btn-success dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" asp-page="./Index" asp-route-sorttype="Today">Today</a>
<a class="dropdown-item" asp-page="./Index" asp-route-sorttype="Yesterday">Yesterday</a>
<a class="dropdown-item" asp-page="./Index" asp-route-sorttype="DateAdded">Date added</a>
<a class="dropdown-item" asp-page="./Index" asp-route-sorttype="AddedOrder">Added order</a>
<a class="dropdown-item search-link" asp-page="./Index">Search for date</a>
</div>
<br />
<form id="search" style="display: none;">
<p> Title: <input type="text" id="searchInput" asp-for="SearchString" /> <input type="submit" value="Filter" /> </p>
</form>
@*</div>*@
@{
if (Model.SumMessage != null)
{
<br />
<span style="white-space: pre-line">@Model.SumMessage</span>
}
}
</div>
</div>

@{
if (Model.SumMessage != null)
{
<br />
}
}
<br />
<table id="records" class="table">
<thead>
<tr>
...
As you can see, if
Model.SumMessage
Model.SumMessage
is not null, I will add a span that will contain that message. I need two <br> tags in case I show the message. One above my span, and the other one above my <table> tag. Problem is, I feel those if statements I added don't look very clean. What do you think?
48 replies
CC#
Created by XD on 9/16/2023 in #help
❔ I get Invalid ModelType because my hidden field is empty
So I have a field (Unit of measurement) that will be hidden if the user chooses the option ''Check-in''. If the user chooses that option and then uploads the form, the field will be shown, followed by the error ''The UnitOfMeasurement field is required". How can I prevent this from happening? I want the UnitOfMeasurement field to be equal to "Done" The cshtml.cs code: https://pastebin.com/vRYqHbCr The cshtml code: https://pastebin.com/QhW9CvRH
2 replies
CC#
Created by XD on 9/16/2023 in #help
❔ How do I hide or show a div based on the value of a property of my selected option?
When I select a habit type, that habit type has a Measurability property, and I want to show or hide divs based on the value of this property. How can I do it?
<form method="post">
<label asp-for="HabitLog.HabitTypeName" class="control-label">Select the habit to log</label>
<select asp-for="HabitLog.HabitTypeName" class="form-control">
<option value=" ">Select an option</option>
@foreach (var habitType in Model.HabitTypes)
{
<option value="@habitType.Name">@habitType.Name</option>
}
</select>
<br />
*Other fields*
<form method="post">
<label asp-for="HabitLog.HabitTypeName" class="control-label">Select the habit to log</label>
<select asp-for="HabitLog.HabitTypeName" class="form-control">
<option value=" ">Select an option</option>
@foreach (var habitType in Model.HabitTypes)
{
<option value="@habitType.Name">@habitType.Name</option>
}
</select>
<br />
*Other fields*
public class HabitType
{
public int Id { get; set; }

public string ImagePath { get; set; }

public string Name { get; set; }

public string Measurability { get; set; }

public string UnitOfMeasurement { get; set; }
}
public class HabitType
{
public int Id { get; set; }

public string ImagePath { get; set; }

public string Name { get; set; }

public string Measurability { get; set; }

public string UnitOfMeasurement { get; set; }
}
By the way, the reason for which I don't want to do it with the name/value of the selected option, is because I would have to hardcode these options in a JavaScript function, but the user is able to add new habit types.
10 replies
CC#
Created by XD on 9/12/2023 in #help
❔ How can I sort my list by day? Razor Pages
The user is able to log and track habits, and I want they to be able to sort their habits in a way like this: - Today - Yesterday - Search for specific date So I had this idea: First add this button:
<form method="post">
<div class="form-group">
<input type="submit" value="Sort by date" class="btn btn-success" />
</div>
</form>

<form method="post">
<div class="form-group">
<input type="submit" value="Sort by date" class="btn btn-success" />
</div>
</form>

Then, for the post method (just added the code for sorting habits added today to test first):
public IActionResult OnPost()
{
HabitLogs = GetAllLogs();

HabitLogs = HabitLogs.Where(x => x.Date.Day == DateTime.Now.Day).Select(x => x).ToList();

return Page();
}
public IActionResult OnPost()
{
HabitLogs = GetAllLogs();

HabitLogs = HabitLogs.Where(x => x.Date.Day == DateTime.Now.Day).Select(x => x).ToList();

return Page();
}
The problem comes when I press the button. I get an ArgumentNullException right at the line where my ImagePath variable is declared (I guess it is because I removed one of the records from HabitLogs): https://pastebin.com/3c6kN1E8 Any advice on how can I sort this list? I'm a beginner in Razor Pages
2 replies
CC#
Created by XD on 9/10/2023 in #help
❔ Why isn't my form being submitted?
As far as I can see, my form is not being submitted because the HabitType is null (there must be something wrong with the section and option tags but I can't tell) Basically, the user is supposed to log their habits through a form which will insert the values into the database. Select and option tags will make the user choose which kind of habit he will log (the HabitLog class contains a HabitType property), the foreach loop will loop through each habit type which exists. The other two ones are for the user to log the date and quantity. Appreciate any help! LogHabit.cshtml: https://pastebin.com/CFusfz41 LogHabit.cshtmlcs: https://pastebin.com/JED3jAMP HabitLog class: https://pastebin.com/CJ1HK88K HabitType class: https://pastebin.com/Ly8Qtg0i
31 replies
CC#
Created by XD on 6/4/2023 in #help
❔ Any tips on how to make this function cleaner? I feel it's a mess
I tried to copy this interactive menu from this video: https://www.youtube.com/watch?v=YyD1MRJY0qI Source code: https://github.com/ricardogerbaudo/Console.InteractiveMenu My code: https://github.com/JsPeanut/InteractiveMenu/blob/main/TestingArea/TestingArea/Program.cs I feel my function is a mess... Would appreciate any help
32 replies
CC#
Created by XD on 5/20/2023 in #help
❔ I tried to substract two TimeSpan objects but nothing happened
I have been trying to add to add a goal feature in my application (a coding tracker), but I haven't been able to update the progress of the goal of the user What I'm trying to do here is: 1. Store in a variable each coding session which has been started after the first goal was added by the user (example, user added his goal 1 hour ago, so then every coding session after the user added his goal, will be stored) 2. Add to GoalProgress all the durations of those sessions 3. Return GoalProgress to use it later
public static TimeSpan DisplayGoal()
{
TimeSpan GoalProgress = TimeSpan.Zero;

var csSinceGoalWasAdded = CodingSessions.Where(cs => cs.StartTime >= (Goals.First().AddedDate)).ToList();

foreach (var j in csSinceGoalWasAdded)
{
GoalProgress += j.Duration;
}

return GoalProgress;
}
public static TimeSpan DisplayGoal()
{
TimeSpan GoalProgress = TimeSpan.Zero;

var csSinceGoalWasAdded = CodingSessions.Where(cs => cs.StartTime >= (Goals.First().AddedDate)).ToList();

foreach (var j in csSinceGoalWasAdded)
{
GoalProgress += j.Duration;
}

return GoalProgress;
}
Then here comes the problem:
Console.WriteLine($"\nWelcome to my Coding Tracker (...)")
if (CodingController.Goals.Count != 0)
{
Console.WriteLine($"Reminder: You are {CodingController.Goals.First().GoalValue - CodingController.DisplayGoal()} hours away from completing your last goal!");
}
Console.WriteLine($"\nWelcome to my Coding Tracker (...)")
if (CodingController.Goals.Count != 0)
{
Console.WriteLine($"Reminder: You are {CodingController.Goals.First().GoalValue - CodingController.DisplayGoal()} hours away from completing your last goal!");
}
I tried to calculate the progress by substracting GoalProgress to GoalValue, but the value of that operation will always be equal to GoalValue (the original goal the user inserted) This is the void in which the values of my Goal model are inserted into my SQLite database:
14 replies