Good Morning|Evening
I have this code for updating records in controller
[HttpPost]
public JsonResult Userupdate(UserProfile user)
{
try
{
if (!ModelState.IsValid)
{
return Json(new
{
Result = "ERROR",
Message = "Form is not valid! " +
"Please correct it and try again."
});
}
var usersC = from x in _db.UserProfiles where x.UserId == user.UserId select x;
//int studentCount = usersC.Count();
//List<UserProfile> students = usersC.ToList();
UserProfile vb = new UserProfile();
vb.UserId = user.UserId;
vb.UserName = user.UserName;
vb.IdentificationNumber = user.IdentificationNumber;
vb.department = user.department;
//_db.UserProfiles.Add(vb);
_db.SaveChanges();
return Json(new { Result = "OK"});
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}
I have this code for deleting records in controller
[HttpPost]
public JsonResult userdelete(int userId)
{
try
{
//_personRepository.DeletePerson(personId);
return Json(new { Result = "OK" });
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}
And you see "repository" in comment because I did not use it in my project; I used link method.
I write the following code for connection with database
UsersContext _db = new UsersContext();
BUT I didn't get the right way to delete it from database.
NOTE::: I am using jTable to show data.
can you help me :_)