public async Task <ActionResult> DeleteAccount() { PetOwner po = GetOwner(); var eggs = _eggRepo.GetEggsByPetOwner(po); foreach (var egg in eggs) { _eggRepo.RemoveEgg(egg); } var listings = _listingRepo.GetListingsByUsers(po); foreach (var list in listings) { _listingRepo.RemoveListing(list); } if (po.HasImage) { _imageRepo.RemoveImage(po.Image); } _poRepo.SaveChanges(); _poRepo.RemovePO(po); var user = await _um.FindByEmailAsync(po.Email); await _um.DeleteAsync(user); _poRepo.SaveChanges(); return(Ok()); }
public ActionResult <EggDTO> DeleteEggWithID(int id) { try { var egg = GetEgg(id); _eggRepo.RemoveEgg(egg); _eggRepo.SaveChanges(); return(Ok(new EggDTO(egg))); } catch (Exception e) { ModelState.AddModelError("Error", e.Message); return(BadRequest(ModelState)); } }