0

Guys I've a EntityModel called mapsModel, which has an entity Type called 'BodyChartNew'

For Inserting records I'm using a Handler called InsertMap, In this handler I'm using the code like as follows:

using System;
using System.Web;

public class InsertMap : IHttpHandler
{

    private mapsModel.mapsEntities _dataContext = new mapsModel.mapsEntities();

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        // Extract form fields
        var title = context.Request["title"];
        var note = context.Request["remarks"];
        var referenceID = context.Request["patient_id"];
        var diagnosisID = context.Request["diagnosis_id"];

        // Create Chart to insert
        var mapsToInsert = new mapsModel.BodyChart { MapCode = title, Remarks = note, PatientID = Convert.ToInt32(referenceID), DiagnosisID = Convert.ToInt32(diagnosisID) };

        // Save new movie to DB
        try
        {
            _dataContext.AddToBodyChart(mapsToInsert);
            _dataContext.SaveChanges();
            // Return success
            context.Response.Write("success");
        }
        catch
        {
            context.Response.Write("fail");
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

I'm calling this Handler from my JQuery Code, This is working fine for me with INSERT, what I need is UPDATE code. What is the UPDATE statement to update the records based on referenceID and diagnosisID ?

Please help me!

1 Answer 1

3

You need to bring down the entity from the database (something like

var entity = _dataContext.BodyChart.Single(e => e.PatientID = context.Request["patient_id"]);

modify properties you want to modify and call

_dataContext.SaveChanges()
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.