// GET: Contact/Delete/5 public ActionResult Delete(Guid id) { try { var contact = _contactApp.GetById(id); var address = _addressApp.GetById(contact.Id); if (address != null) { _addressApp.Remove(address); } var phones = _phoneApp.GetPhoneByIdContact(contact.Id); foreach (var ph in phones) { _phoneApp.Remove(ph); } _contactApp.Remove(contact); return(RedirectToAction("List")); } catch (Exception ex) { return(View()); } }
public Task <HttpResponseMessage> DeletePhone(int phoneId) { HttpResponseMessage response = new HttpResponseMessage(); try { var phone = _service.GetById(phoneId); if (phone != null) { _service.Remove(phone); response = Request.CreateResponse(HttpStatusCode.OK, "Telefone excluído."); } else { response = Request.CreateResponse(HttpStatusCode.BadRequest, "Telefone não encontrado."); } } catch (Exception) { response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao excluir telefone."); } var tsc = new TaskCompletionSource <HttpResponseMessage>(); tsc.SetResult(response); return(tsc.Task); }