public ActionResult Edit(int? Id) { var recordToEdit = dbService.Get(Id); if (recordToEdit == null) { return RedirectToAction("Index"); } else { var result = new RecordViewModel { Id = recordToEdit.Id, Name = recordToEdit.Name, Surname = recordToEdit.Surname, Phone = recordToEdit.Phone }; return View("Add", result); } }
public void Add(RecordViewModel record) { var recordToEdit = db.Records.FirstOrDefault(r => r.Id == record.Id); if (record.Id == 0) { db.Records.InsertOnSubmit(new Record { Surname = record.Surname, Name = record.Name, Phone = record.Phone }); } else { recordToEdit.Surname = record.Surname; recordToEdit.Name = record.Name; recordToEdit.Phone = record.Phone; } db.SubmitChanges(); }
public ActionResult FormAdd(RecordViewModel record) { dbService.Add(record); return RedirectToAction("Index"); }