Link to home
Start Free TrialLog in
Avatar of HawaiiDragon
HawaiiDragon

asked on

MVVM Row keeps getting inserted and not UPDATED

Hello all, Still GREEN when it comes to MVVM:

I have a row that needs to be updated. NOW... when I attempt to do the update it just inserts a new row

// the code needs to be updated where the ATPCodeID= ATPCodeID and NOT insert new rows.. grrrrrr
    public override void SaveChanges()
        {
            ATPCode code = (from c in Db.ATPCodes
                            where c.ATPCodeID == Request.ATPCodeID
                            select c).First();

            code.DisplayText = Request.DisplayText;


            if (Request.ActiveFlag.Value == false)
            {
                code.InactivationDateTime = Dt.CurrentDateTime;
                code.InactivationUserID = Request.Requestor.UserID;

            }

            else
            {
                code.InactivationDateTime = null;
                code.InactivationUserID = null;
            }
        
            code.ModifiedUserID = Request.Requestor.UserID;
            code.ModifiedDateTime = Dt.CurrentDateTime;
                        
            Db.ATPCodes.Add(code);
            Db.SaveChanges();

        }

Open in new window

Avatar of HawaiiDragon
HawaiiDragon

ASKER

public override void SaveChanges()
        {
            database = Db.ATPCodes.Where(a => a.ATPCodeID == Request.ATPCodeID).FirstOrDefault();
            database.DisplayText = Request.DisplayText;
            database.ModifiedUserID = Request.Requestor.UserID;
            database.ModifiedDateTime = Dt.CurrentDateTime;
            if (Request.ActiveFlag.Value == false)
            {
                database.InactivationDateTime = Dt.CurrentDateTime;
                database.InactivationUserID = Request.Requestor.UserID;

            }

            else
            {
                database.InactivationDateTime = null;
                database.InactivationUserID = null;
            }


            Db.SaveChanges();
           
                     
        }
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial