Guest User

Untitled

a guest
Jan 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. /// <summary>
  2. /// GetPetition Method returns an Petition based on petition id supplied
  3. /// </summary>
  4. /// <param name="id"></param>
  5. /// <returns></returns>
  6. public Petition GetPetition(int ? id)
  7. {
  8.  
  9. using (petitionEntities1 pe = new petitionEntities1())
  10. {
  11. pe.Connection.Open();
  12. try
  13. {
  14. return pe.Petitions.Where(x => x.Id == id).FirstOrDefault();
  15. }
  16. catch (Exception ex)
  17. {
  18. return null;
  19. }
  20. }
  21. }
  22.  
  23. /// <summary>
  24. /// GetAllPetitions does exactly what it says, it returns all Petitions in a list
  25. /// </summary>
  26. /// <returns></returns>
  27. public List<Petition> GetAllPetitions()
  28. {
  29.  
  30. using (petitionEntities1 pe = new petitionEntities1())
  31. {
  32. try
  33. {
  34. return pe.Petitions.ToList<Petition>();
  35. }
  36. catch (Exception ex)
  37. {
  38.  
  39. return null;
  40. }
  41. }
  42. }
  43.  
  44. /// <summary>
  45. /// PutPetition , adds a petition to the database
  46. /// </summary>
  47. /// <param name="petition"></param>
  48. /// <returns></returns>
  49. public int PutPetition(Petition petition)
  50. {
  51. using (petitionEntities1 pe = new petitionEntities1())
  52. {
  53. try
  54. {
  55. pe.Petitions.AddObject(petition);
  56. pe.SaveChanges();
  57. pe.AcceptAllChanges();
  58. return 1;
  59.  
  60. }
  61. catch (Exception ex)
  62. {
  63.  
  64. return -1;
  65. }
  66. }
  67. }
  68.  
  69. var a = sc.PutPetition(petition);
Add Comment
Please, Sign In to add comment