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!

Unknown Coder
  • 1,510
  • 2
  • 28
  • 56

1 Answers1

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()
Pawel
  • 31,342
  • 4
  • 73
  • 104