Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Briefly

i'm creating a social site in MVC5..... I've a model User where i have some of these properties fname,lname,username,email,isNew...etc

so i have set isNew to false and when i press Login Button i have an if condition:

if(isNew==true) than redirect...to Index(A.M) Home(C) ....

else redirect....to NewUser(A.M) Steps(C)...

Now when i clicked Login Button its works pretty good i mean it redirect me to Steps(Controller) NewUser(ActionMethod) now here i want to set isNew value to true but i've no idea how to do this

What I have tried:

i have tried this below code...i just want isNew value set to true in
C#
database when NewUser() Method calls 

public ActionResult NewUser(User model)
    {
        using (DbAccess db=new DbAccess())
        {

            var original=db.users.Find(model.uid);
            original.isNew = true;
              //var entry = db.Entry(original);
              //entry.Property(e => e.isNew).IsModified = true;
            db.SaveChanges();
        }
        return Content("Welcome");
    }

and


public ActionResult NewUser(User model)
        {
            using (DbAccess db=new DbAccess())
            {

                var username = User.Identity.Name;
               db.users.Where(m => m.username == username).FirstOrDefault();
               
                //var user = HttpContext.User.Identity.Name;
                //db.users.Attach(model);
                //db.Entry(model).Property(x => x.isNew).IsModified = true;
                db.SaveChanges();
                
                //var original=db.users.Find(model.uid);
                //original.isNew = true;
                //var entry = db.Entry(original);
                //entry.Property(e => e.isNew).IsModified = true;
                //db.SaveChanges();
            }
            return Content("Welcome");
        }
Posted
Updated 6-Jul-16 20:10pm
v2

1 solution

ah i find out the solution...

C#
var user=db.users.Where(m => m.isNew == false).FirstOrDefault();
             user.isNew = true;
 
Share this answer
 
Comments
Dilsher khan 5-Aug-16 14:33pm    
thanks

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