Hello, Programmers,
I am stuck at one particular problem and that is to query the database in a certain way that it brings in only the current user profile details.
This is the way i construct my own profile. i created a class for profile in that when a user is entering his details when registering, the details also copies to the profile value. In that way, i created a controller through scaffolding with the normal CRUD operation but because of i have copied the information i need from the registration page, there is no need for the create page that is scaffolded so i deleted the create page and left just the details and edit page.
My problem now is how to query the database so that it can return the details of that particular user. See below for what i have tried but it doesn't seem to work.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<actionresult> Edit([Bind(Include="ProfileViewModelId,SocialId,DescriptiveId,FirstName,LastName,Address,Post,Comment,Picture,Phone,Email,Country,Description,SocialViewModelId,Facebook,Twitter,Youtube,DateOfBirth,DateEdited")] ProfileViewModel profileviewmodel)
{
if (ModelState.IsValid)
{
profileviewmodel.DateEdited = DateTime.UtcNow;
var pro = from p in db.profiles
where p.user.username == websecurity.currentusername
select p;
db.Entry(profileviewmodel).State = EntityState.Modified;
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewBag.ProfileViewModelId = new SelectList(db.UserSocials, "SocialViewModelId", "Facebook", profileviewmodel.ProfileViewModelId);
return View(profileviewmodel);
}
N.B
one more thing, i have also created a separate class for description, social(facebook,twiiter,youtube); but why is it that after i created the controller the class i reference to, their initial Id is included in the controller and view?
Please, is my relationship wrong this is what i did....
public class profile{
public int Id {get;set;}
public int SocialId {get;set;
public int DescriptionId {get;set;
public string FirstName {get;set;}
public string LastName {get;set;}
public virtual Social Social {get;set;}
public virtual Description Description {get;set;}
}
public class Social{
public int Id {get;set;}
public string Facebook {get;set;}
public string twitter {get;set;}
public string youtube {get;set;}
}
public class Description{
public int Id {get;set;}
public string SelfDescription {get;set;}
}