Guest User

Untitled

a guest
Dec 13th, 2017
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. public interface IEmployeeService
  2. {
  3. [OperationContract]
  4. [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
  5. RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped ,
  6. UriTemplate = "getEmployee/")]
  7. List<EmployeeEntity> getEmployee();
  8.  
  9. [OperationContract]
  10. [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
  11. RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,
  12. UriTemplate = "getEmployeeFromDb/")]
  13. List<Student> getEmployeeFromDb();
  14.  
  15. [OperationContract]
  16. [WebInvoke(Method = "DELETE", ResponseFormat = WebMessageFormat.Json,
  17. RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,
  18. UriTemplate = "/DeleteEmployee")]
  19. string DeleteEmployee(string Id);
  20. }
  21.  
  22. public string DeleteEmployee(string Id)
  23. {
  24. int iEmpId = 0; int.TryParse(Id, out iEmpId);
  25. if (iEmpId > 0)
  26. {
  27. StudentEntityModel Db = new StudentEntityModel();
  28. Student Std = Db.Student.Where(w => w.Sid == iEmpId).FirstOrDefault();
  29. if(Std !=null)
  30. {
  31. Db.Student.Remove(Std);
  32. Db.SaveChanges();
  33. return "Deleted";
  34. }
  35. else { return "Failed."; }
  36. } else { return "Failed."; }
  37. }
  38. public List<EmployeeEntity> getEmployee()
  39. {
  40. return new List<EmployeeEntity> {
  41. new EmployeeEntity {Sid=1,Name="Muruganvc", Gender="Male" , Email="muruganvc@gmail.com" },
  42. new EmployeeEntity {Sid=2,Name="Keerthis", Gender="Female" , Email="Keerthis@gmail.com" },
  43. new EmployeeEntity {Sid=3,Name="Divyap", Gender="Female" , Email="Divyap@gmail.com" },
  44. };
  45. }
  46. public List<Student> getEmployeeFromDb()
  47. {
  48. StudentEntityModel Db = new StudentEntityModel();
  49. return Db.Student.ToList();
  50. }
  51. }
Add Comment
Please, Sign In to add comment