❔ I have a project and I need to implement a functionality to create a membership for users

I need help with using exporting & importing data in a text file in a my console application project
60 Replies
Jimmacle
Jimmacle2y ago
what have you tried and what problem are you currently having?
The king of kings
Let me show you
The king of kings
Here is my plan for the project I'm trying to take user inputs save them in a variable and then pass this variable as a path to write it to a text file, then read the file and create a membership, ultimately it's just a practice project, is it possible? I know we could write data to a text file and read/import data from a text file
Thinker
Thinker2y ago
Why do you have a StreamWriter is a validation method...?
The king of kings
as Oh! This needs to be modified, because at the beginning I was thinking on only taking user input and validate, but the I thought this is boring. I wanna practice using text file not taking user input 🤨
Jimmacle
Jimmacle2y ago
you should practice planning out your project before writing any code list out all the data that you need, how it should be organized, and what actions you need to do with it
The king of kings
Well! I have done that. But not very precisely as you mentioned about the data. I have planed the project on a piece of paper as a diagram.
Jimmacle
Jimmacle2y ago
could you share that?
The king of kings
Although it's not considered as completed yet Do you think I need to use a softwire to draw a diagram flow?
Jimmacle
Jimmacle2y ago
it's probably easier than trying to do it on paper i would comment that a part that says "apply logic" isn't useful to write down, you should be more specific about what the code needs to be doing
Jimmacle
Jimmacle2y ago
for example, this is a very rough outline of a feature i'm working on for one of my work projects
The king of kings
Ok! Yeah! I think using software is better and more efficient Teknik to see the flow of the project than using the typical way with pen and paper. Ok! It looks a bit cryptic to me and not really understand some of these outlines. But it looks more organized and splited into multiple sections.
Jimmacle
Jimmacle2y ago
I basically sketched out what data I need and what has to be done with it Which you should have a good idea of before writing any code Otherwise you might get stuck with code you have to rewrite because you didn't plan ahead
The king of kings
Ok! Yeah! You're absolutely right. Planning the project and get a very clear view about the sections that needs to be implemented will save too much time. So I could do that? .
Jimmacle
Jimmacle2y ago
yes it's not exactly clear what you want to do, which is why i suggested planning it out more thoroughly it's easier for us to help if you have a good plan
The king of kings
I mean the docs shows that you could write any string value to a text file, so instead of hardcoding the "Hello World!!"string, I could write the users data and store in a text file in the program.
The king of kings
Sounds great. I'll plan the project, so you'd get a glimpse of what I'm trying to create. I'll go and plan it then. Thanks a lot so far 🤗 Just a quick question, let's say I took all these user inputs, should I be saving each data in each its property?
public string FirstName { get; }
public string LastName { get; }
public int Age { get; }
public string EmailAddress { get; }
public string HomeAddress { get; }
public string PhoneNumber { get; }
public string Id { get; }
public string FirstName { get; }
public string LastName { get; }
public int Age { get; }
public string EmailAddress { get; }
public string HomeAddress { get; }
public string PhoneNumber { get; }
public string Id { get; }
I mean those are variables too, right?
Jimmacle
Jimmacle2y ago
yes, if the data is related to each other (like different data about one user) you should group them in a class
The king of kings
Ok They are already in a class
namespace HockeyArenaSytem
{
public class Membership
{

public string FirstName { get; }
public string LastName { get; }
public int Age { get; }
public string EmailAddress { get; }
public string HomeAddress { get; }
public string PhoneNumber { get; }
public string Id { get; }

public Membership(string firstname, string lastname, string emailaddress, string homeaddress, string phonenumber, string id)
{
/*ArgumentException.ThrowIfNullOrEmpty(FirstName);
ArgumentException.ThrowIfNullOrEmpty(LastName);
ArgumentException.ThrowIfNullOrEmpty(EmailAddress);
ArgumentException.ThrowIfNullOrEmpty(HomeAddress);
ArgumentException.ThrowIfNullOrEmpty(PhoneNumber);*/

FirstName = firstname;
LastName = lastname;
EmailAddress = emailaddress;
HomeAddress = homeaddress;
PhoneNumber = phonenumber;
Id = id;

}
namespace HockeyArenaSytem
{
public class Membership
{

public string FirstName { get; }
public string LastName { get; }
public int Age { get; }
public string EmailAddress { get; }
public string HomeAddress { get; }
public string PhoneNumber { get; }
public string Id { get; }

public Membership(string firstname, string lastname, string emailaddress, string homeaddress, string phonenumber, string id)
{
/*ArgumentException.ThrowIfNullOrEmpty(FirstName);
ArgumentException.ThrowIfNullOrEmpty(LastName);
ArgumentException.ThrowIfNullOrEmpty(EmailAddress);
ArgumentException.ThrowIfNullOrEmpty(HomeAddress);
ArgumentException.ThrowIfNullOrEmpty(PhoneNumber);*/

FirstName = firstname;
LastName = lastname;
EmailAddress = emailaddress;
HomeAddress = homeaddress;
PhoneNumber = phonenumber;
Id = id;

}
Jimmacle
Jimmacle2y ago
yes
The king of kings
But shouldn't I be using seters too to set value for each property?
Jimmacle
Jimmacle2y ago
it depends do you want to change the data after instantiating the class?
The king of kings
Right now I'm using only the getters to get their values Although, I haven't done the logic part e.g. while loop, other methods, lists and etc..
The king of kings
I had modify the last square to user membership
Jimmacle
Jimmacle2y ago
so i don't think a flowchart is the correct type of diagram for this
The king of kings
Ok
Jimmacle
Jimmacle2y ago
a flowchart models one process from start to finish, you put a whole bunch of stuff in here you probably want to look at a class diagram or even just a plain list with bullet points like i showed above
The king of kings
Yeah! This will require making a lot of stuff and it will take some time to draw everything. Exactly, I totally agree with you. Your method and the way you structure your project flow is much easier and faster bing done than using this type of software. I wasted some time on this, but I learned something too at least when planing in future projects.
Jimmacle
Jimmacle2y ago
if you do want to do diagrams i recommend looking at the different types of diagrams available and understand how each one can help you plan your project for example, a flowchart might be good to plan out the logic of a single method planning your class definitions and relationships between them would be done with a class diagram
The king of kings
Yeah! That's right bro. Ok! So how do I find this type of diagram to be able to use it for this type of project? Can you recommend me for one?
Jimmacle
Jimmacle2y ago
just did
The king of kings
You mean just like you did? .
Jimmacle
Jimmacle2y ago
i mean i just gave you 2 examples of diagram types and when to use them
The king of kings
Ok! So I think I will keep the flowchart the way it is currently to see what I'm building, then I would need to plan the logic or the classes as a list with bullet points, right?
Jimmacle
Jimmacle2y ago
that's not what a flowchart should be used for but sure this is the point where you should do some additional research
The king of kings
Aha! Ok! I get that. You're right. I'm planing the logic on a simple file just like you did anyway
The king of kings
This just a the primary planing, I haven't done the whole yet. What do you think?
Jimmacle
Jimmacle2y ago
looks like a good start
The king of kings
Awesome I thought your off line because of difference in timezones, other wise I was gonna ask you in the first place. Should I try writing this code solo first even if do it wrongly?
Jimmacle
Jimmacle2y ago
always try it first if you ask someone how to do it before you even try, you won't learn as much
The king of kings
That's a very good advice. Very wise said and done. I should be validating the user input first, before adding any invalid data to a text file, right?
Jimmacle
Jimmacle2y ago
what do you think? what would happen if you didn't?
The king of kings
These are good questions that makes me think more deeply when it comes to data I mean although this is just a console application, but still I should validate, because what if the user inputs only one character instead of a name? What if the age is 2000? What if the email address is invalid? I think I need to practice these validations to get ready for applying them in GUI apps when working professionally, w d y think? Plus, I should make sure that these data are separated by a delimiters, so the data don't get mixed other wise I won't be able to read them later.
Jimmacle
Jimmacle2y ago
correct
The king of kings
Awesome There's something called regex where you pass a certain collection of characters inside parentheses and you use them for validation, but not sure exactly how? I mean the format should be as long as input is not null or the following characters then store the value in a variable, otherwise I think an exception will be thrown.
The king of kings
I'm gonna review these attached links and learn how to apply the Regex to my project, thanks 😉 To be honest, didn't quite understand the content in those links, would be able to explain?
friedice
friedice2y ago
Do you know how to add validation to a property?
The king of kings
@IceGPTI've done it this way in my previous project
The king of kings
But without using a method though
friedice
friedice2y ago
<a:cat_no:768672517325717544>
friedice
friedice2y ago
well idk if you're doing a web project but you can google thumbsupcat
The king of kings
No, man it's just a console application. I don't think I could use this docs as validation for my project
friedice
friedice2y ago
ubk
Useful scripts | Basic and Advanced Day to day used scripts
DataAnnotation based validation in C# Console Application
Data annotation based validation in C# console application.
friedice
friedice2y ago
sure heres the 2nd link i found under google you dont necessarily have to do it this way
The king of kings
Ok! Awesome bro. I'll definitely take a look at this link. Thanks a lot
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server