Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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.

C#
   // POST: /Profile/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [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....

C#
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;}
}
Posted
Updated 28-Apr-15 1:48am
v2
Comments
John C Rayan 28-Apr-15 8:02am    
What's the error you are getting?
Sinisa Hajnal 17-Aug-15 3:52am    
Why is a description separate class when it contains only single property (which could be included in the original class)? Especially since you already have one description property there.

Also, you didn't say what kind of error you get, what is exact message text and any other details about "doesn't work" you can provide. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900