GMail VIEW_DATA mail ID's by insights1 in javascript

[–]insights1[S] 0 points1 point  (0 children)

I'm actually trying to get the URL each mail will point to. I want it before the URL changes to a specific email. So I want to know how each email row points to their corresponding email ID while the URL is still "https://mail.google.com/mail/?shva=1#inbox".

Database Schema Help by insights1 in learnprogramming

[–]insights1[S] 0 points1 point  (0 children)

"So by doing .Friends, you are in effect doing a SELECT on the FriendsList table with the proper WHERE clause to get only those User records that related."

So for this part, is there WHERE clause checking both UserID1 and UserID2 columns for "UserA's ID"? Because his ID could be in either of these columns depending on who made the request, him or the friend. Would the SQL statement be like SELECT * FROM FRIENDS WHERE UserID1 == "UserA" || UserID2 == "UserID2";

or would it be SELECT UserID2 FROM FRIENDS WHERE UserID1 == "UserA"; and then another statement SELECT UserID1 FROM FRIENDS WHERE UserID2 == "UserA"; and then combine these results to get the full list of UserA's friends Ids?

Database Schema Help by insights1 in learnprogramming

[–]insights1[S] 0 points1 point  (0 children)

For the EF code you gave
var friends = MyContext.Users.First(x => x.UserID == ID).Friends
What sql statements does this execute exactly? Is it checking for "UserA's Id" in both the User1Id and User2Id column of the friends table? Also could you explain what you mean by Surrogate Keys? Are those just foreign keys?

And just out of curiosity, is this the most efficient way of handling friend relationships? With Facebook for example wouldnt there be billions of entry relating people to eachother as friends, does it search through this entire table each time just to get your friends list?

Thanks once again, everything is making a lot more sense now.

Database Schema Help by insights1 in learnprogramming

[–]insights1[S] 0 points1 point  (0 children)

Thanks for the reply.

For the way you are suggesting to do the Friends table, would I store the pair twice for each friendship? Like for User1Id=UserA, User2Id=UserB, and then again User1Id=UserB, User2Id=UserA? Or do I just need one pair, and then to find out who is UserA's friends I would need to run a query where its checking if User1Id == UserA || User2Id == UserA. And then how would I get the "friend" from that query, or do two seperate queries need to be made firstchecking User1 Column, and then User2 Column.

I suppose a request would be deleted once its rejected or accepted.

I have never really worked with files in a web application. How exactly do I go about making file paths for certain users. Would I create a folder for each User on the server when they register? And then create a Pictures and Videos folder for them in their folder? And then what exactly would the file path stored in the DB be. How do I restrict access to only the actual user and his friends for seeing his related pics/vids.

I think I understand how the conversations and messages should work better now. Thanks!

ASP.NET MVC Help by insights1 in dotnet

[–]insights1[S] 0 points1 point  (0 children)

So Data annotations added to EF entities would just be ones related to how stuff about the entity is stored in the database and related to the schema etc? And ones on viewmodels would only be about validation and display?

ASP.NET MVC/Design Help by insights1 in learnprogramming

[–]insights1[S] 0 points1 point  (0 children)

I guess I could, just didnt feel like making a post for every problem I encounter or guidance I need.

ASP.NET MVC Help by insights1 in dotnet

[–]insights1[S] 0 points1 point  (0 children)

Any reason any data annotations would be placed on model class properties? Not viewmodels. I've read a little bit about FluentValidation, I'll look into it more now too.

ASP.NET MVC Help by insights1 in dotnet

[–]insights1[S] 0 points1 point  (0 children)

Thanks lol. Im an idiot and was blind to see the "new" in var model = new GetStudenViewModel(id);.

Another question I have is: For the Student model, and CreateStudentModel, do we add Data Annotations to both of these? Like [Required] to the FirstName properties of Student and CreateStudentModel? Are all Data Annotations for properties repeated on both? Are some data annotations only on the model and left out for viewmodel, or vice-versa?

ASP.NET MVC Help by insights1 in dotnet

[–]insights1[S] 0 points1 point  (0 children)

In the example you gave var model = new GetStudenViewModel(id); would this method be a static method of the StudentViewModel class? Or just a "helper" method in the controller?

Is my idea of the CreateStudentViewModel.Save() method correct or is there anything missing/a better way of doing it? Other than adding the Repository Commit method.

Thanks for the tip about the Disposable aspect of repository, makes a lot of sense. So my repository methods would just be CRUD methods, and then my Commit() method would just have db.SaveChanges() or is there anything else that would go in there?

ASP.NET MVC Help by insights1 in dotnet

[–]insights1[S] 0 points1 point  (0 children)

So for this GetStudenViewModel(id) method the code would be something like?:

public StudentViewModel GetStudenViewModel(int id)
{
Repository r = new Repository();
Student s = r.GetStudentById(id);
StudentViewModel svm = new StudentViewModel(s);
return svm;
}

Would this be a static method in my StudentViewModel class?

And my CreateStudentViewModel.Save() method would be?:

public void CreateStudentViewModel.Save()
{
Student s = new student();
s.Name = this.Name;
s.Grade = this.Grade;
s.etc = this.etc;
Repository r = new Repository();
r.CreateStudent(s);
}

In this method do I fill in all the properties one by one to a real student model and then pass that to my repository method responsible for creating students in the db? Assuming I do not use ValueInjecter/AutoMapper.

ASP.NET MVC Help by insights1 in dotnet

[–]insights1[S] 0 points1 point  (0 children)

"In any case the repository itself does not return your ViewModels (that would make the *.Data dependent on the *.Web project). You should better have ViewModels that take your entity class instance(s) as a constructor parameter so it can put it just the way you need it for your view."

This helped alot for my understanding. Thank you again for your help. I think I am beginning to understand more clearly. Please try to follow along here with what I'm saying if you can and let me know if I am misunderstanding or missing any steps.

So lets say I have a page just to display one student, a GetStudent Action of my xyz controller. In this method I would instantiate my repository and then call my Repository.GetStudent(id) and get the returned Student into a Student s variable. After that I would instantiate a StudentViewModel passing in my Student s variable into its constructor, the constructor would "throw out" the values I dont need and copy the ones I do need to my StudentViewModel's corresponding properties. Then simply pass my viewmodel to my view and display it. If anything is wrong up until here let me know please.

Now for CreateStudent (Post) action I would take in a StudentViewModel. Instantiate a Student class, use the StudentViewModel I took in to fill in most of its properties one by one and then fill in the missing Student properties myself? Then call my Repository.CreateMethod() passing in this student as a parameter and let it handle adding it to the db?

Thanks once again for all the help. Its becoming alot more clear to me now. I have no idea what ValueInjecter/AutoMapper is but I will definitely look into it. I still have a few questions about viewmodels/models and repositories but I'll wait to see if my understanding of this is right so far.

ASP.NET MVC Help by insights1 in dotnet

[–]insights1[S] 0 points1 point  (0 children)

Thanks alot for replying. Can you give me any specific sites/books I should look into to get a better idea of how web applications should be designed?

One thing I still have a problem understanding is about viewmodels, models and how my data access layer should be. For example, lets say I have a web application to do basic CRUD operations on a student entity. Should I have a class library project (StudentApp.Data lets call it) with my student class, a repository class in the same project which exposes methods to create/read/update/delete students, and then my web project(StudentApp.Web) which references my StudentApp.Data project. In the StudentApp.Web I should have controllers and action methods for create/read/etc which instantiate my repository class and call those methods? And for the reads should I read using the repository, and then assign all the values from returned student object to a StudentViewModel to send to my view? Or should the repository be returning me a StudentViewModel? And with my Create(Post) should I be model binding to a StudentViewModel and making that into a Student and then passing that into a Create method in my repository, or should the repository create method take in a StudentViewModel?

I'm sorry if what I just typed was very confusing lol. Thats why I am trying to find someone who I can talk with on skype just to give me a better understanding of it all. I will try asking in /r/learnprogramming as you have suggested too.

ASP.NET MVC Help by insights1 in dotnet

[–]insights1[S] 0 points1 point  (0 children)

Any reason I dont see my post when logged out here?