fork download
  1. using System.Linq;
  2. using System.Reflection;
  3. using System.Web.Mvc;
  4. using Scheduling.Domain.Abstact;
  5. using Scheduling.Domain.Entities;
  6. using Scheduling.WebUI.Models;
  7.  
  8. namespace Scheduling.WebUI.Controllers
  9. {
  10. public class EmployeesController : Controller
  11. {
  12. private IDbContext context;
  13. public int pageSize = 10;
  14.  
  15. public EmployeesController(IDbContext ctx)
  16. {
  17. context = ctx;
  18. }
  19.  
  20. public ViewResult List(int page = 1)
  21. {
  22. ViewBag.Counter = (page - 1) * pageSize + 1;
  23. EmployeeListViewModel model = new EmployeeListViewModel()
  24. {
  25. Employees = (from e in context.Employee
  26. join s in context.Staff on new { EmployeeId = e.Id } equals new { s.EmployeeId } into s_join
  27. from s in s_join.DefaultIfEmpty()
  28. join d in context.Department on new { s.DepartmentId } equals new { DepartmentId = d.Id }
  29. into d_join
  30. from d in d_join.DefaultIfEmpty()
  31. where
  32. d.Id == 3 &&
  33. d.CompanyId == 1
  34. select e)
  35. .OrderBy(e => e.Id)
  36. .Skip((page - 1) * pageSize)
  37. .Take(pageSize),
  38.  
  39. PagingInfo = new PagingInfo
  40. {
  41. CurrentPage = page,
  42. ItemsPerPage = pageSize,
  43. TotalItems = (from e in context.Employee
  44. join s in context.Staff on new { EmployeeId = e.Id } equals new { s.EmployeeId } into s_join
  45. from s in s_join.DefaultIfEmpty()
  46. join d in context.Department on new { s.DepartmentId } equals new { DepartmentId = d.Id }
  47. into d_join
  48. from d in d_join.DefaultIfEmpty()
  49. where
  50. d.Id == 3 &&
  51. d.CompanyId == 1
  52. select e).Count()
  53. }
  54. };
  55.  
  56.  
  57. return View(model);
  58. }
  59.  
  60. public ViewResult Edit(int id)
  61. {
  62. Employee emp = context.Employee.Find(id);
  63.  
  64. return View(emp);
  65. }
  66.  
  67. [HttpPost]
  68. public ActionResult Edit(Employee emp)
  69. {
  70. if (ModelState.IsValid)
  71. {
  72. if (emp.Id != 0)
  73. {
  74. Employee dbEntry = context.Employee.Find(emp.Id);
  75.  
  76. if (dbEntry != null)
  77. {
  78. PropertyInfo[] properties = typeof (Employee).GetProperties();
  79. foreach (var property in properties)
  80. {
  81. if (property.Name != "Id" && property.Name != "Staff")
  82. {
  83. property.SetValue(dbEntry, property.GetValue(emp));
  84. }
  85. }
  86. }
  87. }
  88. else if (emp.Id == 0)
  89. {
  90. emp.Staff.Add(new Staff()
  91. {
  92. PostId = 2,
  93. DepartmentId = 3
  94. });
  95. context.Employee.Add(emp);
  96.  
  97. }
  98. context.SaveChanges();
  99. return RedirectToAction("List");
  100. }
  101.  
  102. return View(emp);
  103. }
  104.  
  105. [HttpPost]
  106. public RedirectToRouteResult Delete(int id)
  107. {
  108. Employee dbEntry = context.Employee.Find(id);
  109. if (dbEntry != null)
  110. {
  111. context.Employee.Remove(dbEntry);
  112. context.SaveChanges();
  113. }
  114. return RedirectToAction("List");
  115. }
  116.  
  117.  
  118. public ViewResult Create()
  119. {
  120. return View("Edit", new Employee());
  121. }
  122.  
  123.  
  124.  
  125. }
  126. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(3,18): error CS0234: The type or namespace name `Mvc' does not exist in the namespace `System.Web'. Are you missing an assembly reference?
prog.cs(4,18): error CS0234: The type or namespace name `Domain' does not exist in the namespace `Scheduling'. Are you missing an assembly reference?
prog.cs(5,18): error CS0234: The type or namespace name `Domain' does not exist in the namespace `Scheduling'. Are you missing an assembly reference?
prog.cs(6,24): error CS0234: The type or namespace name `Models' does not exist in the namespace `Scheduling.WebUI'. Are you missing an assembly reference?
prog.cs(10,40): error CS0246: The type or namespace name `Controller' could not be found. Are you missing an assembly reference?
prog.cs(12,17): error CS0246: The type or namespace name `IDbContext' could not be found. Are you missing an assembly reference?
prog.cs(15,36): error CS0246: The type or namespace name `IDbContext' could not be found. Are you missing an assembly reference?
prog.cs(20,16): error CS0246: The type or namespace name `ViewResult' could not be found. Are you missing an assembly reference?
prog.cs(60,16): error CS0246: The type or namespace name `ViewResult' could not be found. Are you missing an assembly reference?
prog.cs(68,16): error CS0246: The type or namespace name `ActionResult' could not be found. Are you missing an assembly reference?
prog.cs(106,16): error CS0246: The type or namespace name `RedirectToRouteResult' could not be found. Are you missing an assembly reference?
prog.cs(118,16): error CS0246: The type or namespace name `ViewResult' could not be found. Are you missing an assembly reference?
Compilation failed: 12 error(s), 0 warnings
stdout
Standard output is empty