public ActionResult AddNewPerson(PersonObject personToAdd) { // For the purposes of this example where just assuming everything works all of the time. // Ideally though, you'd want to return some kind of status from your data tier here var addedRecord = PretendData.DataSource.AddNew(personToAdd); var response = new UpdateResponse { Error = false, Message = "", attachedObject = addedRecord }; //var response = new UpdateResponse { Error = true, Message = "Record failed to update beacuse it's broken.", attachedObject = null }; return Json(response); }
public static PersonObject Update(PersonObject personDetails) { var thePerson = _theData.SingleOrDefault(x => x.RecordId == personDetails.RecordId); if(null != thePerson) { thePerson.FirstName = personDetails.FirstName; thePerson.SecondName = personDetails.SecondName; thePerson.EmailAddress = personDetails.EmailAddress; return thePerson; } return null; }
public static PersonObject AddNew(PersonObject personDetails) { int newId; if(!_theData.Any()) { newId = 1; } else { newId = _theData.Max(x => x.RecordId) + 1; } personDetails.RecordId = newId; _theData.Add(personDetails); // return the record with the RecordId modified as required return personDetails; }
public ActionResult UpdateOnePerson(PersonObject personToUpdate) { // For the purposes of this example where just assuming everything works all of the time. // Ideally though, you'd want to return some kind of status from your data tier here var updatedPerson = PretendData.DataSource.Update(personToUpdate); UpdateResponse response; if(null != updatedPerson) { response = new UpdateResponse { Error = false, Message = "", attachedObject = updatedPerson }; } else { response = new UpdateResponse { Error = true, Message = "Record failed to update beacuse it's broken.", attachedObject = null }; } return Json(response); }