PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/PMT_DotNet/Web/Controllers/projectController.cs

https://gitlab.com/Antar/PMT_DotNet
C# | 391 lines | 263 code | 94 blank | 34 comment | 23 complexity | db16f809fe3d4412f5b20f3506b81848 MD5 | raw file
  1. using Domain.Entities;
  2. using Service;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Web;
  9. using System.Web.Mvc;
  10. using Rotativa;
  11. using Data.Models;
  12. namespace Web.Controllers
  13. {
  14. public class projectController : Controller, IDisposable
  15. {
  16. ProjectService Pservice = null;
  17. CategoryService Cservice = null;
  18. ClientService CLservice = null;
  19. TeamService Tservice = null;
  20. public projectController()
  21. {
  22. Pservice = new ProjectService();
  23. Cservice = new CategoryService();
  24. CLservice = new ClientService();
  25. Tservice = new TeamService();
  26. }
  27. // GET: project
  28. public ActionResult AllProject()
  29. {
  30. var project = Pservice.GetMany();
  31. List<project> pr = new List<project>();
  32. foreach (var item in project)
  33. {
  34. pr.Add(
  35. new project
  36. {
  37. IdProject = item.IdProject,
  38. Description = item.Description,
  39. Name = item.Name,
  40. Priority = item.Priority,
  41. Type = item.Type,
  42. EndDate = item.EndDate,
  43. StartDate = item.StartDate,
  44. DocumentsUrl = item.DocumentsUrl
  45. });
  46. }
  47. return View(pr);
  48. }
  49. [HttpPost]
  50. public ActionResult AllProject(String search)
  51. {
  52. var projects = Pservice.GetMany(p => p.Name == search);
  53. List<project> pr = new List<project>();
  54. List<category> cl = new List<category>();
  55. foreach (var item in projects)
  56. {
  57. pr.Add(
  58. new project
  59. {
  60. IdProject = item.IdProject,
  61. Description = item.Description,
  62. Name = item.Name,
  63. Priority = item.Priority,
  64. Type = item.Type,
  65. EndDate = item.EndDate,
  66. StartDate = item.StartDate,
  67. DocumentsUrl = item.DocumentsUrl
  68. });
  69. }
  70. return View(pr);
  71. }
  72. public ActionResult Index()
  73. {
  74. return View();
  75. }
  76. // GET: project/Details/5
  77. public ActionResult Details(int id)
  78. {
  79. if (id == null)
  80. {
  81. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  82. }
  83. project p = Pservice.GetById(id);
  84. if (p == null)
  85. {
  86. return HttpNotFound();
  87. }
  88. return View(p);
  89. }
  90. // GET: project/Create
  91. public ActionResult Create()
  92. {
  93. var categories = Cservice.GetMany(); ;
  94. var clients = CLservice.GetMany();
  95. var teams = Tservice.GetMany();
  96. ViewBag.category = new SelectList(categories, "IdCategory", "Name");
  97. ViewBag.client = new SelectList(clients, "IdClient", "Name");
  98. ViewBag.team = new SelectList(teams, "id_team", "nom_team");
  99. return View();
  100. }
  101. // POST: project/Create
  102. [HttpPost]
  103. public ActionResult Create(project p, HttpPostedFileBase doc)
  104. {
  105. if (!ModelState.IsValid || doc == null || doc.ContentLength == 0)
  106. {
  107. RedirectToAction("Create");
  108. }
  109. //if (doc != null )
  110. //{
  111. // //p.DocumentsUrl = doc.FileName;
  112. // project pr = new project
  113. // {
  114. // IdProject = p.IdProject,
  115. // Description = p.Description,
  116. // Name = p.Name,
  117. // Priority = p.Priority,
  118. // Type = p.Type,
  119. // EndDate = p.EndDate,
  120. // StartDate = p.StartDate,
  121. // DocumentsUrl = p.DocumentsUrl ,
  122. // Category_IdCategory = p.Category_IdCategory ,
  123. // id_client = p.id_client ,
  124. // id_team = p.id_team
  125. // };
  126. // Pservice.Add(pr);
  127. // Pservice.commit();
  128. // Pservice.Dispose();
  129. // // Sauvgarde de l'image
  130. // var path = Path.Combine(Server.MapPath("~/Content/Upload/"), doc.FileName);
  131. // doc.SaveAs(path);
  132. // return RedirectToAction("Index");
  133. //}
  134. //return View();
  135. if (!ModelState.IsValid)
  136. {
  137. return Create();
  138. }
  139. p.DocumentsUrl = doc.FileName;
  140. project pr = new project
  141. {
  142. IdProject = p.IdProject,
  143. Description = p.Description,
  144. Name = p.Name,
  145. Priority = p.Priority,
  146. Type = p.Type,
  147. EndDate = p.EndDate,
  148. StartDate = p.StartDate,
  149. DocumentsUrl = p.DocumentsUrl,
  150. Category_IdCategory = p.Category_IdCategory,
  151. id_client = p.id_client,
  152. id_team = p.id_team
  153. };
  154. Pservice.Add(pr);
  155. Pservice.commit();
  156. Pservice.Dispose();
  157. var path = Path.Combine(Server.MapPath("~/Content/Upload/"), doc.FileName);
  158. doc.SaveAs(path);
  159. return RedirectToAction("Index");
  160. }
  161. // GET: project/Edit/5
  162. public ActionResult Edit(int id)
  163. {
  164. if (id == null)
  165. {
  166. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  167. }
  168. project p = Pservice.GetById(id);
  169. if (p == null)
  170. {
  171. return HttpNotFound();
  172. }
  173. return View(p);
  174. }
  175. // POST: project/Edit/5
  176. [HttpPost]
  177. public ActionResult Edit(int id, project p)
  178. {
  179. if (!ModelState.IsValid)
  180. {
  181. return EditDetails();
  182. }
  183. if (ModelState.IsValid)
  184. {
  185. Pservice.Update(p);
  186. Pservice.commit();
  187. Pservice.Dispose();
  188. return RedirectToAction("Index");
  189. }
  190. return View(p);
  191. }
  192. // GET: project/Delete/5
  193. public ActionResult Delete(int id)
  194. {
  195. if (id == null)
  196. {
  197. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  198. }
  199. project p = Pservice.GetById(id);
  200. if (p == null)
  201. {
  202. return HttpNotFound();
  203. }
  204. return View(p);
  205. }
  206. // POST: project/Delete/5
  207. [HttpPost]
  208. public ActionResult Delete(int id, project p)
  209. {
  210. Pservice.Delete(p);
  211. Pservice.commit();
  212. Pservice.Dispose();
  213. return RedirectToAction("Index");
  214. }
  215. public ActionResult EditDetails()
  216. {
  217. var categories = Cservice.GetMany(); ;
  218. var clients = CLservice.GetMany();
  219. var teams = Tservice.GetMany();
  220. ViewBag.category = new SelectList(categories, "IdCategory", "Name");
  221. ViewBag.client = new SelectList(clients, "IdClient", "Name");
  222. ViewBag.team = new SelectList(teams, "id_team", "nom_team");
  223. return View();
  224. }
  225. public ActionResult UploadFile(HttpPostedFileBase file)
  226. {
  227. if (ModelState.IsValid)
  228. {
  229. string path = Server.MapPath("~/Files/" + file.FileName); // location
  230. file.SaveAs(path);
  231. @ViewBag.Path = path;
  232. }
  233. return View();
  234. }
  235. public ActionResult ExportPDF()
  236. {
  237. return new ActionAsPdf("index")
  238. {
  239. FileName = Server.MapPath("~/Content/Files/products.pdf")
  240. };
  241. }
  242. public ActionResult Chat()
  243. {
  244. return View();
  245. }
  246. public ActionResult ActiveList()
  247. {
  248. var project = Pservice.ActiveProject();
  249. List<project> pr = new List<project>();
  250. foreach (var item in project)
  251. {
  252. pr.Add(
  253. new project
  254. {
  255. IdProject = item.IdProject,
  256. Description = item.Description,
  257. Name = item.Name,
  258. Priority = item.Priority,
  259. Type = item.Type,
  260. EndDate = item.EndDate,
  261. StartDate = item.StartDate,
  262. DocumentsUrl = item.DocumentsUrl
  263. });
  264. }
  265. return View(pr);
  266. }
  267. public ActionResult PassedList()
  268. {
  269. var project = Pservice.PassedProject();
  270. List<project> pr = new List<project>();
  271. foreach (var item in project)
  272. {
  273. pr.Add(
  274. new project
  275. {
  276. IdProject = item.IdProject,
  277. Description = item.Description,
  278. Name = item.Name,
  279. Priority = item.Priority,
  280. Type = item.Type,
  281. EndDate = item.EndDate,
  282. StartDate = item.StartDate,
  283. DocumentsUrl = item.DocumentsUrl
  284. });
  285. }
  286. return View(pr);
  287. }
  288. protected override void Dispose(bool disposing)
  289. {
  290. if (disposing)
  291. {
  292. Pservice.Dispose();
  293. }
  294. base.Dispose(disposing);
  295. }
  296. }
  297. }