angular version: Angular CLI: 9.0.0-rc.7
I have encountered an issue while trying to update a record. After clicking on the edit icon, I am able to make changes to the record in the form. However, when I click on the Edit Button, the record gets updated in the browser console log but not in the database. Below is the code snippet from backendservice.ts:
//when I click on edit icon then record going to form
public editpartymaster(PartyMstId) {
return new Promise(resolve => {
let headers = new HttpHeaders({ 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' });
let options = { headers: headers, crossDomain: true, withCredentials: true };
var url = "http://localhost:000/PartyMsts/EditPatymaster?PartyMstId=" + PartyMstId;
this.httpClient.post<any>(url, options).subscribe(
(res) => {
console.log(res);
resolve(res);
},
(err) => console.log(err)
);
});
}
//edit button click event
public editpartymasterid(PartyMstId, PartyCode, PartyName, Address, PhNo1, SDate, PartyDate, RDType, Exchange) {
return new Promise(resolve => {
let headers = new HttpHeaders({ 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' });
let options = { headers: headers, crossDomain: true, withCredentials: true };
var url = "http://localhost:000/PartyMsts/EditPatymaster";
const postdata = {
'PartyMstId': PartyMstId,
'PartyCode': PartyCode,
'PartyName': PartyName,
'Address': Address,
'PhNo1': PhNo1,
'SDate': SDate,
'PartyDate': PartyDate,
'RDType': RDType,
'Exchange': Exchange
}
console.log("formdata", postdata)
return this.httpClient.post<any>(url, postdata)
.subscribe((res) => {
console.log("res partyadd add 198", res);
resolve(res);
});
});
}
Below is the code snippet from partymaster.component.ts:
PartyMstId: any;
PartyCode: any;
PartyName: any;
Address: any;
PhNo1: any;
SDate: any;
PartyDate: any;
RDType: any;
Exchange: any;
x: any;
y: any;
c: any;
partylist: any;
constructor(public myservice: BackendService) {}
//edit icon click event
onGridRowClicked(e: any) {
if (e.event.target !== undefined) {
let actionType = e.event.target.getAttribute("data-action-type");
if (actionType == "edit") {
console.log("e", e.data.PartyMstId);
console.log("View edit action clicked");
this.myservice.editpartymaster(e.data.PartyMstId).then((data: any) => {
if (data.message == "your record update") {
this.PartyMstId = e.data.PartyMstId;
this.PartyCode = e.data.PartyCode;
this.PartyName = e.data.PartyName;
this.Address = e.data.Address;
this.PhNo1 = e.data.PhNo1;
this.SDate = e.data.SDate;
this.PartyDate = e.data.PartyDate;
this.RDType = e.data.RDType;
this.Exchange = e.data.Exchange;
}
});
}
else if (actionType == "delete") {
console.log("View delete action clicked");
}
//edit button click event
editbuttonclickevent() {
console.log("---PartyMstId---", this.PartyMstId);
console.log("---PartyCode---", this.PartyCode);
console.log("---PartyName---", this.PartyName);
console.log("---Address---", this.Address);
console.log("---PhNo1---", this.PhNo1);
console.log("---SDate---", this.SDate);
console.log("---PartyDate---", this.PartyDate);
console.log("---RDType---", this.RDType);
console.log("---Exchange---", this.Exchange);
this.myservice.editpartymasterid(this.PartyMstId, this.PartyCode,
this.PartyName, this.Address, this.PhNo1, this.SDate, this.PartyDate,
this.RDType, this.Exchange).then((data: any) => {
console.log("list data")
if (data.message == "your record update") {
this.list();
}
});
}
In the provided ASP.NET MVC service code below, the issue seems to be related to updating the database after making changes to the record:
public ActionResult EditPatymaster(int PartyMstId)
{
var partymst = poly.PartyMsts.Find(PartyMstId);
partymstmodel partymstupdate = new partymstmodel();
partymstupdate.PartyCode = partymst.PartyCode;
partymstupdate.PartyName = partymst.PartyName;
partymstupdate.Address = partymst.Address;
partymstupdate.PhNo1 = partymst.PhNo1;
partymstupdate.SDate = partymst.SDate;
partymstupdate.PartyDate = partymst.PartyDate;
partymstupdate.RDType = partymst.RDType;
return View(partymstupdate);
}
[HttpPost]
public JsonResult EditPatymaster(partymstmodel partymst, int PartyMstId)
{
var partymstupdate = poly.PartyMsts.Find(PartyMstId);
if(partymstupdate!=null)
{
partymstupdate.PartyCode = partymst.PartyCode;
partymstupdate.PartyName = partymst.PartyName;
partymstupdate.Address = partymst.Address;
partymstupdate.PhNo1 = partymst.PhNo1;
partymstupdate.SDate = partymst.SDate;
partymstupdate.PartyDate = partymst.PartyDate;
partymstupdate.RDType = partymst.RDType;
HttpResponseMessage response = staticvariable.client.PutAsJsonAsync("PartyMsts", partymst).Result;
var data = new
{
message = "your record update",
};
return Json(data, JsonRequestBehavior.AllowGet);
}
else
{
var data = new
{
message = "your record not updated",
};
return Json(data, JsonRequestBehavior.AllowGet);
}
}
The issue described states that the console log shows the updated record, but the database does not reflect these changes. You can view the browser logs for more information:
https://i.sstatic.net/RDDG4.png
Although the console log displays the updated record, it appears that the database fields are not being updated as expected:
https://i.sstatic.net/RpxCJ.png
If you have any insights on how to resolve this issue, your help would be greatly appreciated. Thank you.