0
 public ReturnMessage EditCategories(Category objCategory)
    {


        ReturnMessage objReturnMessage = new ReturnMessage();
        try
        {
            Category objCategoryNew = db.Categories.Where(x => x.CategoryId == objCategory.CategoryId).FirstOrDefault();
            if (objCategoryNew != null)
            {
                objCategoryNew = objCategory;
                db.SaveChanges();
                objReturnMessage.isSuccessfull = true;
                objReturnMessage.responseMessage = "Successfully updated.";
            }
            else
            {
                objReturnMessage.isSuccessfull = false;
                objReturnMessage.responseMessage = "Category not present.";
            }
        }
        catch (Exception ex)
        {
            objReturnMessage.isSuccessfull = false;
            objReturnMessage.responseMessage = ex.Message;
        }
        return objReturnMessage;

    }

Everything goes fine there are no exceptions still the data isn't getting updated. I don't know what's the issue. Please help?

1
  • No it isn't null contains the old data. Its coming inside the if loop itself. Commented Aug 14, 2013 at 10:36

1 Answer 1

2

The line:

objCategoryNew = objCategory;

will not work out since you change the reference objCategoryNew to objCategory, not the object itself, what you have to do is to assign each property of objCategory to objCategoryNew, something like:

objCategoryNew.Pro1 = objCategory.Pro1;
objCategoryNew.Pro2 = objCategory.Pro2;
....
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.