TreeController.cs 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.AspNetCore.Http;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Configuration;
  10. using SuperAdmin.Models.Http;
  11. using SuperAdmin.Models.Object;
  12. using SuperAdmin.Models.View;
  13. using SuperCms.Extensions;
  14. using static SuperAdmin.Models.View.CommonModel;
  15. namespace SuperAdmin.Controllers
  16. {
  17. public class TreeController : BaseController
  18. {
  19. private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
  20. public TreeController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
  21. {
  22. // init
  23. }
  24. public IActionResult Index(String id)
  25. {
  26. try
  27. {
  28. if (!CheckAuthToken())
  29. {
  30. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  31. }
  32. string serviceName = GetParameter(UtilsController.Constant.SERVICE_NAME);
  33. HttpContext.Session.SetComplexData("serviceName", serviceName);
  34. if (!CheckAuthToken())
  35. {
  36. return RedirectToAction("Index", "Home");
  37. }
  38. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  39. TreeViewModel model = new TreeViewModel();
  40. model.rows = new RowStructures();
  41. model.rows.data = new List<RowStructure>();
  42. if (rows == null || 1 == 1)
  43. {
  44. GetRequest request = new GetRequest();
  45. request.ID = id != null ? id : BaseController.PARENT_ID;
  46. String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  47. AppResponse res = new AppResponse(rs);
  48. if (res.status == UtilsController.Constant.SUCCESS)
  49. {
  50. RowStructures rowsGet = new RowStructures(configuration, rs);
  51. rowsGet.data.ForEach(x => model.rows.data.Add(x));
  52. }
  53. HttpContext.Session.SetComplexData("rows", model.rows);
  54. }
  55. else
  56. {
  57. rows.data.ForEach(x => model.rows.data.Add(x));
  58. model.rows.data = model.rows.data.FindAll(x => x.parent_id == BaseController.PARENT_ID);
  59. }
  60. return View("Index", model);
  61. }
  62. catch (Exception ex)
  63. {
  64. log.Error("Exception " + ex);
  65. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
  66. }
  67. }
  68. public IActionResult GetTreeData(String id)
  69. {
  70. try
  71. {
  72. if (!CheckAuthToken())
  73. {
  74. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  75. }
  76. TreeViewModel model = new TreeViewModel();
  77. model.rows = new RowStructures();
  78. model.rows.data = new List<RowStructure>();
  79. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  80. List<RowStructure> rowGetSession = rows != null ? rows.data.FindAll(x => x.parent_id == id) : null;
  81. if (rowGetSession == null || rowGetSession.Count == 0)
  82. {
  83. GetRequest request = new GetRequest();
  84. request.ID = id;
  85. String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  86. AppResponse res = new AppResponse(rs);
  87. if (res.status == UtilsController.Constant.SUCCESS)
  88. {
  89. RowStructures rowsGet = new RowStructures(configuration, rs);
  90. rowsGet.data.ForEach(x => rows.data.Add(x));
  91. model.rows = rowsGet;
  92. }
  93. HttpContext.Session.SetComplexData("rows", rows);
  94. }
  95. else
  96. {
  97. model.rows.data = rowGetSession;
  98. }
  99. return PartialView("TreePartial", model);
  100. }
  101. catch (Exception ex)
  102. {
  103. log.Error("Exception " + ex);
  104. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
  105. }
  106. }
  107. public IActionResult GetTableData(String id)
  108. {
  109. try
  110. {
  111. if (!CheckAuthToken())
  112. {
  113. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  114. }
  115. TreeViewModel model = new TreeViewModel();
  116. model.rows = new RowStructures();
  117. model.rows.data = new List<RowStructure>();
  118. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  119. if (rows != null)
  120. {
  121. RowStructure parent = rows.data.Find(x => x.id == id);
  122. model.parent = parent;
  123. List<RowStructure> rowGetSession = rows != null ? rows.data.FindAll(x => x.parent_id == id) : null;
  124. if (rowGetSession == null || rowGetSession.Count == 0)
  125. {
  126. GetRequest request = new GetRequest();
  127. request.ID = id;
  128. String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  129. AppResponse res = new AppResponse(rs);
  130. if (res.status == UtilsController.Constant.SUCCESS)
  131. {
  132. RowStructures rowsGet = new RowStructures(configuration, rs);
  133. rowsGet.data.ForEach(x => rows.data.Add(x));
  134. model.rows = rowsGet;
  135. }
  136. HttpContext.Session.SetComplexData("rows", rows);
  137. }
  138. else
  139. {
  140. model.rows.data = rowGetSession;
  141. }
  142. }
  143. return PartialView("TablePartial", model);
  144. }
  145. catch (Exception ex)
  146. {
  147. log.Error("Exception " + ex);
  148. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
  149. }
  150. }
  151. // data
  152. private string UploadedFile(String folder, IFormFile image)
  153. {
  154. try
  155. {
  156. //string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "img");
  157. string uploadsFolder = GetParameter(UtilsController.Constant.PATH_OUTSIDE);
  158. uploadsFolder = Path.Combine(uploadsFolder, folder);
  159. if (!Directory.Exists(uploadsFolder))
  160. {
  161. Directory.CreateDirectory(uploadsFolder);
  162. }
  163. string uniqueFileName = Guid.NewGuid().ToString() + "_" + image.FileName;
  164. string filePath = Path.Combine(uploadsFolder, uniqueFileName);
  165. using (var fileStream = new FileStream(filePath, FileMode.Create))
  166. {
  167. image.CopyTo(fileStream);
  168. }
  169. return Path.Combine(folder, uniqueFileName);
  170. }
  171. catch (Exception ex)
  172. {
  173. log.Error("Exception: " + ex);
  174. return "";
  175. }
  176. }
  177. public IActionResult Adding(String id)
  178. {
  179. try
  180. {
  181. if (!CheckAuthToken())
  182. {
  183. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  184. }
  185. EventViewModel model = new EventViewModel();
  186. if (id != BaseController.PARENT_ID)
  187. {
  188. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  189. model.parent = rows.data.Find(x => x.id == id);
  190. }
  191. Provinces provinces = HttpContext.Session.GetComplexData<Provinces>("provinces");
  192. Topics topics = HttpContext.Session.GetComplexData<Topics>("topics");
  193. if (provinces == null)
  194. {
  195. provinces = new Provinces();
  196. provinces.data = new List<Province>();
  197. AppRequest userRequest = new AppRequest();
  198. userRequest.language = UtilsController.Constant.LANGUAGE_GLOBAL;
  199. String rsProvince = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_PROVINCES));
  200. AppResponse resProvince = new AppResponse(rsProvince);
  201. if (resProvince.status == UtilsController.Constant.SUCCESS)
  202. {
  203. provinces = new Provinces(rsProvince);
  204. HttpContext.Session.SetComplexData("provinces", provinces);
  205. }
  206. }
  207. if (topics == null)
  208. {
  209. topics = new Topics();
  210. topics.data = new List<Topic>();
  211. AppRequest topicRequest = new AppRequest();
  212. topicRequest.language = UtilsController.Constant.LANGUAGE_GLOBAL;
  213. String rsTopic = SendPost(topicRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_TOPICS));
  214. AppResponse resTopic = new AppResponse(rsTopic);
  215. if (resTopic.status == UtilsController.Constant.SUCCESS)
  216. {
  217. topics = new Topics(rsTopic);
  218. HttpContext.Session.SetComplexData("topics", topics);
  219. }
  220. }
  221. model.provinces = provinces;
  222. model.topics = topics;
  223. return PartialView("~/Views/Tree/Event/Adding.cshtml", model);
  224. }
  225. catch (Exception ex)
  226. {
  227. log.Error("Exception " + ex);
  228. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
  229. }
  230. }
  231. [ValidateAntiForgeryToken]
  232. [HttpPost]
  233. public JsonResult AddingAction(RowStructure data, IFormFile icon, IFormFile logo)
  234. {
  235. try
  236. {
  237. if (!CheckAuthToken())
  238. {
  239. return Json(new
  240. {
  241. code = UtilsController.Constant.AUTHEN_FAIL,
  242. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
  243. });
  244. }
  245. String page = HttpContext.Session.GetComplexData<String>("page");
  246. // check image upload
  247. if (icon != null && (icon.FileName.EndsWith(".png") || icon.FileName.EndsWith(".jpg") || icon.FileName.EndsWith(".jpeg"))
  248. && logo != null)
  249. {
  250. //List<IFormFile> newFiles = new List<IFormFile>();
  251. //newFiles.Add(icon);
  252. //newFiles.Add(logo);
  253. //Task<IActionResult> resUpload = OnPostUploadAsync(newFiles);
  254. //data.realIcon = icon.FileName;
  255. //data.realLogo = logo.FileName;
  256. String resIcon = UploadedFile(data.parent_id, icon);
  257. String resLogo = UploadedFile(data.parent_id, logo);
  258. if (resIcon != "" && resLogo != "")
  259. {
  260. data.realIcon = resIcon;
  261. data.realLogo = resLogo;
  262. }
  263. else
  264. {
  265. return Json(new
  266. {
  267. error_code = UtilsController.Constant.FAILURE,
  268. error_content = "An error happens with your logo or your icon.",
  269. });
  270. }
  271. }
  272. else if (icon != null || logo != null)
  273. {
  274. return Json(new
  275. {
  276. error_code = UtilsController.Constant.FAILURE,
  277. error_content = "An error happens with your logo",
  278. });
  279. }
  280. data.sv_id = GetParameter(UtilsController.Constant.SERVICE_ID);
  281. data.from_date = convertToDateTimeServer(data.from_date);
  282. data.to_date = convertToDateTimeServer(data.to_date);
  283. // push event to the server
  284. ActionRequest userRequest = new ActionRequest();
  285. userRequest.NOTE = "";
  286. userRequest.PARENT_ID = data.parent_id;
  287. userRequest.CODE = data.code;
  288. userRequest.NAME_GLOBAL = data.name_global;
  289. userRequest.NAME_LOCAL = data.name_local;
  290. userRequest.DESCRIPTION_GLOBAL = data.description_global;
  291. userRequest.DESCRIPTION_LOCAL = data.description_local;
  292. userRequest.INTRODUCTION_GLOBAL = data.introduction_global;
  293. userRequest.INTRODUCTION_LOCAL = data.introduction_local;
  294. userRequest.ICON = data.realIcon;
  295. userRequest.LOGO = data.realLogo;
  296. userRequest.CONTENT = data.content;
  297. userRequest.CONTENT_TYPE = UtilsController.Constant.TEXT_TYPE;
  298. userRequest.IS_SHOW = data.is_show;
  299. userRequest.PROVINCE_ID = UtilsController.Constant.ALL_CATEGORIES;
  300. userRequest.TOPIC_ID = UtilsController.Constant.ALL_CATEGORIES;
  301. userRequest.FROM_DATE = data.from_date;
  302. userRequest.TO_DATE = data.to_date;
  303. userRequest.TYPE = UtilsController.Constant.ADMIN_TYPE;
  304. String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.INSERT_DATA));
  305. AppResponse res = new AppResponse(rs);
  306. if (res.status == UtilsController.Constant.SUCCESS)
  307. {
  308. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  309. data.id = res.newsId;
  310. data.name = data.name_global;
  311. rows.data.Add(data);
  312. HttpContext.Session.SetComplexData("rows", rows);
  313. List<String> ids = new List<string>();
  314. ids.Add(data.parent_id);
  315. return Json(new
  316. {
  317. code = UtilsController.Constant.SUCCESS,
  318. message = "Adding successful",
  319. ids = ids,
  320. });
  321. }
  322. else
  323. {
  324. return Json(new
  325. {
  326. code = UtilsController.Constant.FAILURE,
  327. message = "We have a problem!",
  328. });
  329. }
  330. }
  331. catch (Exception ex)
  332. {
  333. log.Error("Exception " + ex);
  334. return Json(new
  335. {
  336. code = UtilsController.Constant.EXCEPTION,
  337. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
  338. });
  339. }
  340. }
  341. public IActionResult Editing(String id, String action)
  342. {
  343. try
  344. {
  345. if (!CheckAuthToken())
  346. {
  347. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  348. }
  349. if (id == null)
  350. {
  351. //return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
  352. id = BaseController.PARENT_ID;
  353. }
  354. EventViewModel model = new EventViewModel();
  355. model.action = action;
  356. if (action == "add")
  357. {
  358. if (id != BaseController.PARENT_ID)
  359. {
  360. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  361. model.parent = rows.data.Find(x => x.id == id);
  362. }
  363. }
  364. else
  365. {
  366. // edit
  367. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  368. model.now = rows.data.Find(x => x.id == id);
  369. model.parent = rows.data.Find(x => x.id == model.now.parent_id);
  370. if (model.now != null)
  371. {
  372. // get details
  373. GetRequest request1 = new GetRequest();
  374. request1.ID = id;
  375. request1.isGetContet = UtilsController.Constant.GET_CONTENT;
  376. String rs1 = SendPost(request1, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_ID));
  377. AppResponse res1 = new AppResponse(rs1);
  378. if (res1.status == UtilsController.Constant.SUCCESS)
  379. {
  380. RowStructures rowsGet = new RowStructures(configuration, rs1);
  381. model.now = rowsGet.data[0];
  382. }
  383. }
  384. HttpContext.Session.SetComplexData("editing", model.now);
  385. }
  386. //Provinces provinces = HttpContext.Session.GetComplexData<Provinces>("provinces");
  387. //Topics topics = HttpContext.Session.GetComplexData<Topics>("topics");
  388. //if (provinces == null)
  389. //{
  390. // provinces = new Provinces();
  391. // provinces.data = new List<Province>();
  392. // AppRequest userRequest = new AppRequest();
  393. // userRequest.language = UtilsController.Constant.LANGUAGE_GLOBAL;
  394. // String rsProvince = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_PROVINCES));
  395. // AppResponse resProvince = new AppResponse(rsProvince);
  396. // if (resProvince.status == UtilsController.Constant.SUCCESS)
  397. // {
  398. // provinces = new Provinces(rsProvince);
  399. // HttpContext.Session.SetComplexData("provinces", provinces);
  400. // }
  401. //}
  402. //if (topics == null)
  403. //{
  404. // topics = new Topics();
  405. // topics.data = new List<Topic>();
  406. // AppRequest topicRequest = new AppRequest();
  407. // topicRequest.language = UtilsController.Constant.LANGUAGE_GLOBAL;
  408. // String rsTopic = SendPost(topicRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_TOPICS));
  409. // AppResponse resTopic = new AppResponse(rsTopic);
  410. // if (resTopic.status == UtilsController.Constant.SUCCESS)
  411. // {
  412. // topics = new Topics(rsTopic);
  413. // HttpContext.Session.SetComplexData("topics", topics);
  414. // }
  415. //}
  416. //model.provinces = provinces;
  417. //model.topics = topics;
  418. // get all parents
  419. GetRequest request = new GetRequest();
  420. request.ID = id;
  421. request.isGetChildById = "2"; // get all parents
  422. String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  423. AppResponse res = new AppResponse(rs);
  424. if (res.status == UtilsController.Constant.SUCCESS)
  425. {
  426. model.categories = new RowStructures(configuration, rs);
  427. }
  428. return PartialView("~/Views/Tree/Event/Editing.cshtml", model);
  429. }
  430. catch (Exception ex)
  431. {
  432. log.Error("Exception " + ex);
  433. return Redirect(HttpContext.Session.GetComplexData<RowStructures>(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
  434. }
  435. }
  436. [ValidateAntiForgeryToken]
  437. [HttpPost]
  438. public JsonResult EditingAction(RowStructure data, IFormFile icon, IFormFile logo, string action)
  439. {
  440. try
  441. {
  442. if (!CheckAuthToken())
  443. {
  444. return Json(new
  445. {
  446. code = UtilsController.Constant.AUTHEN_FAIL,
  447. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
  448. });
  449. }
  450. String page = HttpContext.Session.GetComplexData<String>("page");
  451. // check image upload
  452. if (icon != null && (icon.FileName.EndsWith(".png") || icon.FileName.EndsWith(".jpg") || icon.FileName.EndsWith(".jpeg")) && logo != null)
  453. {
  454. String resIcon = UploadedFile(data.parent_id, icon);
  455. //String resLogo = UploadedFile(logo);
  456. if (resIcon != "")
  457. {
  458. data.realIcon = resIcon;
  459. //data.realLogo = resLogo;
  460. }
  461. else
  462. {
  463. return Json(new
  464. {
  465. error_code = UtilsController.Constant.FAILURE,
  466. error_content = "An error happens with your logo or your icon.",
  467. });
  468. }
  469. }
  470. if (logo != null)
  471. {
  472. //String resIcon = UploadedFile(icon);
  473. String resLogo = UploadedFile(data.parent_id, logo);
  474. if (resLogo != "")
  475. {
  476. //data.realIcon = resIcon;
  477. data.realLogo = resLogo;
  478. }
  479. else
  480. {
  481. return Json(new
  482. {
  483. error_code = UtilsController.Constant.FAILURE,
  484. error_content = "An error happens with your logo or your icon.",
  485. });
  486. }
  487. }
  488. //else if (icon != null || logo != null)
  489. //{
  490. // return Json(new
  491. // {
  492. // error_code = UtilsController.Constant.FAILURE,
  493. // error_content = "An error happens with your logo",
  494. // });
  495. //}
  496. RowStructure edit = HttpContext.Session.GetComplexData<RowStructure>("editing");
  497. data.sv_id = GetParameter(UtilsController.Constant.SERVICE_ID);
  498. data.from_date = convertToDateTimeServer(data.from_date);
  499. data.to_date = convertToDateTimeServer(data.to_date);
  500. // push event to the server
  501. ActionRequest userRequest = new ActionRequest();
  502. userRequest.NOTE = "";
  503. userRequest.PARENT_ID = data.parent_id;
  504. userRequest.NAME_GLOBAL = data.name_global;
  505. userRequest.NAME_GLOBAL1 = data.name_global1;
  506. userRequest.NAME_GLOBAL2 = data.name_global2;
  507. userRequest.NAME_LOCAL = data.name_local;
  508. userRequest.DESCRIPTION_GLOBAL = data.description_global;
  509. userRequest.DESCRIPTION_GLOBAL1 = data.description_global1;
  510. userRequest.DESCRIPTION_GLOBAL2 = data.description_global2;
  511. userRequest.DESCRIPTION_LOCAL = data.description_local;
  512. userRequest.INTRODUCTION_GLOBAL = data.introduction_global;
  513. userRequest.INTRODUCTION_GLOBAL1 = data.introduction_global1;
  514. userRequest.INTRODUCTION_GLOBAL2 = data.introduction_global2;
  515. userRequest.INTRODUCTION_LOCAL = data.introduction_local;
  516. userRequest.ICON = data.realIcon;
  517. userRequest.LOGO = data.realLogo;
  518. userRequest.CONTENT = data.content;
  519. userRequest.CONTENT_GLOBAL = data.content_global;
  520. userRequest.CONTENT_GLOBAL1 = data.content_global1;
  521. userRequest.CONTENT_GLOBAL2 = data.content_global2;
  522. userRequest.CONTENT_TYPE = UtilsController.Constant.TEXT_TYPE;
  523. userRequest.IS_SHOW = UtilsController.Constant.WAIT_APPROVAL;//data.is_show;
  524. userRequest.PROVINCE_ID = UtilsController.Constant.ALL_CATEGORIES;
  525. userRequest.TOPIC_ID = UtilsController.Constant.ALL_CATEGORIES;
  526. userRequest.FROM_DATE = data.from_date;
  527. userRequest.TO_DATE = data.to_date;
  528. userRequest.TYPE = UtilsController.Constant.EDITING;
  529. if (action == "add")
  530. {
  531. userRequest.CODE = data.code;
  532. }
  533. else
  534. {
  535. data.id = edit.id;
  536. data.parent_id = edit.parent_id;
  537. userRequest.CODE = data.code;
  538. }
  539. if (action == "add")
  540. {
  541. // add new
  542. String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.INSERT_DATA));
  543. AppResponse res = new AppResponse(rs);
  544. if (res.status == UtilsController.Constant.SUCCESS)
  545. {
  546. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  547. data.id = res.newsId;
  548. data.name = data.name_global;
  549. rows.data.Add(data);
  550. HttpContext.Session.SetComplexData("rows", rows);
  551. List<String> ids = new List<string>();
  552. ids.Add(data.parent_id);
  553. return Json(new
  554. {
  555. code = UtilsController.Constant.SUCCESS,
  556. message = "Adding successful",
  557. ids = ids,
  558. });
  559. }
  560. else
  561. {
  562. return Json(new
  563. {
  564. code = UtilsController.Constant.FAILURE,
  565. message = "We have a problem!",
  566. });
  567. }
  568. }
  569. else
  570. {
  571. // edit
  572. userRequest.ID = data.id;
  573. String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.UPDATE_DATA));
  574. AppResponse res = new AppResponse(rs);
  575. if (res.status == UtilsController.Constant.SUCCESS)
  576. {
  577. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  578. rows.data.Where(S => S.id == data.id).Select(S =>
  579. {
  580. S.code = data.code;
  581. S.name = data.name;
  582. S.name_global = data.name_global;
  583. S.name_global1 = data.name_global1;
  584. S.name_global2 = data.name_global2;
  585. S.name_local = data.name_local;
  586. S.description_global = data.description_global;
  587. S.description_global1 = data.description_global1;
  588. S.description_global2 = data.description_global2;
  589. S.description_local = data.description_local;
  590. S.introduction_global = data.introduction_global;
  591. S.introduction_global1 = data.introduction_global1;
  592. S.introduction_global2 = data.introduction_global2;
  593. S.introduction_local = data.introduction_local;
  594. S.icon = data.realIcon;
  595. S.logo = data.realLogo;
  596. S.content = data.content;
  597. S.content_global = data.content_global;
  598. S.content_global1 = data.content_global1;
  599. S.content_global2 = data.content_global2;
  600. S.content_type = UtilsController.Constant.TEXT_TYPE;
  601. S.is_show = data.is_show;
  602. S.province_id = data.province_id;
  603. S.topic_id = data.topic_id;
  604. S.from_date = data.from_date;
  605. S.to_date = data.to_date;
  606. S.permission = UtilsController.Constant.ADMIN_TYPE;
  607. return S;
  608. }).ToList();
  609. HttpContext.Session.SetComplexData("rows", rows);
  610. List<String> ids = new List<string>();
  611. ids.Add(data.parent_id);
  612. return Json(new
  613. {
  614. ids = ids,
  615. code = UtilsController.Constant.SUCCESS,
  616. message = "Editing successful",
  617. });
  618. }
  619. else
  620. {
  621. return Json(new
  622. {
  623. code = UtilsController.Constant.FAILURE,
  624. message = "We have a problem!",
  625. });
  626. }
  627. }
  628. }
  629. catch (Exception ex)
  630. {
  631. log.Error("Exception " + ex);
  632. return Json(new
  633. {
  634. code = UtilsController.Constant.EXCEPTION,
  635. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
  636. });
  637. }
  638. }
  639. [ValidateAntiForgeryToken]
  640. public JsonResult DeletingAction(String id)
  641. {
  642. try
  643. {
  644. if (!CheckAuthToken())
  645. {
  646. return Json(new
  647. {
  648. code = UtilsController.Constant.AUTHEN_FAIL,
  649. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
  650. });
  651. }
  652. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  653. RowStructure data = rows.data.Find(x => x.id == id);
  654. if (data == null)
  655. {
  656. return Json(new
  657. {
  658. code = UtilsController.Constant.FAILURE,
  659. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home"
  660. });
  661. }
  662. ActionRequest request = new ActionRequest();
  663. request.ID = data.id;
  664. request.TYPE = UtilsController.Constant.DELETE;
  665. String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.UPDATE_DATA));
  666. AppResponse res = new AppResponse(rs);
  667. if (res.status == UtilsController.Constant.SUCCESS)
  668. {
  669. //return Redirect("/EventAdmin/EventShowing");
  670. rows.data.RemoveAll(x => x.id == id);
  671. HttpContext.Session.SetComplexData("rows", rows);
  672. List<String> ids = new List<string>();
  673. ids.Add(data.parent_id);
  674. List<String> funcs = new List<string>();
  675. funcs.Add(UtilsController.Constant.GetTableAction);
  676. List<String> paras = new List<string>();
  677. paras.Add(data.parent_id);
  678. return Json(new
  679. {
  680. ids = ids,
  681. code = UtilsController.Constant.SUCCESS,
  682. message = "Deleting successful",
  683. functions = funcs,
  684. parameters = paras,
  685. });
  686. }
  687. else
  688. {
  689. return Json(new
  690. {
  691. code = UtilsController.Constant.FAILURE,
  692. message = "We have a problem!",
  693. });
  694. }
  695. }
  696. catch (Exception ex)
  697. {
  698. log.Error("Exception " + ex);
  699. return Json(new
  700. {
  701. code = UtilsController.Constant.EXCEPTION,
  702. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home"
  703. });
  704. }
  705. }
  706. [ValidateAntiForgeryToken]
  707. public JsonResult MovingAction(String sourceID, String destinationID)
  708. {
  709. try
  710. {
  711. if (!CheckAuthToken())
  712. {
  713. return Json(new
  714. {
  715. code = UtilsController.Constant.AUTHEN_FAIL,
  716. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
  717. });
  718. }
  719. if (sourceID == null || destinationID == null)
  720. {
  721. return Json(new
  722. {
  723. code = UtilsController.Constant.FAILURE,
  724. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
  725. });
  726. }
  727. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  728. RowStructure source = rows.data.Find(x => x.id == sourceID);
  729. RowStructure destination = rows.data.Find(x => x.id == destinationID);
  730. if (source == null || destination == null)
  731. {
  732. return Json(new
  733. {
  734. code = UtilsController.Constant.FAILURE,
  735. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
  736. });
  737. }
  738. String oldParent = source.parent_id;
  739. // update source parent id to destination
  740. source.parent_id = destination.id;
  741. // push event to the server
  742. ActionRequest userRequest = new ActionRequest();
  743. userRequest.ID = source.id;
  744. userRequest.NOTE = "";
  745. userRequest.PARENT_ID = source.parent_id;
  746. userRequest.CODE = source.code;
  747. userRequest.NAME_GLOBAL = source.name_global;
  748. userRequest.NAME_LOCAL = source.name_local;
  749. userRequest.DESCRIPTION_GLOBAL = source.description_global;
  750. userRequest.DESCRIPTION_LOCAL = source.description_local;
  751. userRequest.INTRODUCTION_GLOBAL = source.introduction_global;
  752. userRequest.INTRODUCTION_LOCAL = source.introduction_local;
  753. userRequest.ICON = source.realIcon;
  754. userRequest.LOGO = source.realLogo;
  755. userRequest.CONTENT = source.content;
  756. userRequest.CONTENT_TYPE = UtilsController.Constant.TEXT_TYPE;
  757. userRequest.IS_SHOW = source.is_show;
  758. userRequest.PROVINCE_ID = source.province_id;
  759. userRequest.TOPIC_ID = source.topic_id;
  760. userRequest.FROM_DATE = source.from_date;
  761. userRequest.TO_DATE = source.to_date;
  762. userRequest.TYPE = UtilsController.Constant.ADMIN_TYPE;
  763. String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.UPDATE_DATA));
  764. AppResponse res = new AppResponse(rs);
  765. if (res.status == UtilsController.Constant.SUCCESS)
  766. {
  767. rows.data.Where(S => S.id == source.id).Select(S =>
  768. {
  769. S.parent_id = source.parent_id;
  770. return S;
  771. }).ToList();
  772. HttpContext.Session.SetComplexData("rows", rows);
  773. List<String> ids = new List<string>();
  774. ids.Add(destination.id);
  775. ids.Add(oldParent);
  776. return Json(new
  777. {
  778. ids = ids,
  779. code = UtilsController.Constant.SUCCESS,
  780. message = "Moving successful",
  781. });
  782. }
  783. else
  784. {
  785. return Json(new
  786. {
  787. code = UtilsController.Constant.FAILURE,
  788. message = "We have a problem!",
  789. });
  790. }
  791. }
  792. catch (Exception ex)
  793. {
  794. log.Error("Exception " + ex);
  795. return Json(new
  796. {
  797. code = UtilsController.Constant.EXCEPTION,
  798. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home"
  799. });
  800. }
  801. }
  802. [ValidateAntiForgeryToken]
  803. public JsonResult CopyingAction(String sourceID, String destinationID)
  804. {
  805. try
  806. {
  807. if (!CheckAuthToken())
  808. {
  809. return Json(new
  810. {
  811. code = UtilsController.Constant.AUTHEN_FAIL,
  812. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
  813. });
  814. }
  815. if (sourceID == null || destinationID == null)
  816. {
  817. return Json(new
  818. {
  819. code = UtilsController.Constant.FAILURE,
  820. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
  821. });
  822. }
  823. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  824. RowStructure source = rows.data.Find(x => x.id == sourceID);
  825. RowStructure destination = rows.data.Find(x => x.id == destinationID);
  826. if (source == null || destination == null)
  827. {
  828. return Json(new
  829. {
  830. code = UtilsController.Constant.FAILURE,
  831. message = "We have a problem. Parent id was not found!",
  832. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
  833. });
  834. }
  835. MapData map = new MapData();
  836. map.oldData = source;
  837. DistributedByLevel one = new DistributedByLevel();
  838. one.mapData = new List<MapData>();
  839. one.mapData.Add(map);
  840. one.level = 1;
  841. List<DistributedByLevel> listOne = new List<DistributedByLevel>();
  842. listOne.Add(one);
  843. List<DistributedByLevel> dataCopy = GetAllDataSource(1, listOne);
  844. Boolean res = CopyAllDataSource(destinationID, dataCopy, 1, new List<DistributedByLevel>());
  845. if (res)
  846. {
  847. List<String> ids = new List<string>();
  848. ids.Add(source.parent_id);
  849. ids.Add(destination.id);
  850. return Json(new
  851. {
  852. ids = ids,
  853. code = UtilsController.Constant.SUCCESS,
  854. message = "Copying successful",
  855. });
  856. }
  857. else
  858. {
  859. return Json(new
  860. {
  861. code = UtilsController.Constant.FAILURE,
  862. message = "We have a problem!",
  863. });
  864. }
  865. }
  866. catch (Exception ex)
  867. {
  868. log.Error("Exception " + ex);
  869. return Json(new
  870. {
  871. code = UtilsController.Constant.EXCEPTION,
  872. message = "We have a problem. Exception!",
  873. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home"
  874. });
  875. }
  876. }
  877. private List<DistributedByLevel> GetAllDataSource(int level, List<DistributedByLevel> result)
  878. {
  879. DistributedByLevel now = result.Find(x => x.level == level);
  880. DistributedByLevel newDis = new DistributedByLevel();
  881. newDis.level = level + 1;
  882. newDis.mapData = new List<MapData>();
  883. int check = 1;
  884. for (int i = 0; i < now.mapData.Count; i++)
  885. {
  886. GetRequest request = new GetRequest();
  887. request.ID = now.mapData[i].oldData.id;
  888. request.isGetContet = UtilsController.Constant.GET_CONTENT;
  889. String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  890. AppResponse res = new AppResponse(rs);
  891. if (res.status == UtilsController.Constant.SUCCESS)
  892. {
  893. RowStructures rowsGet = new RowStructures(configuration, rs);
  894. for (int a = 0; a < rowsGet.data.Count; a++)
  895. {
  896. MapData map = new MapData();
  897. map.oldData = rowsGet.data[a];
  898. newDis.mapData.Add(map);
  899. }
  900. }
  901. else
  902. {
  903. check *= 0;
  904. }
  905. }
  906. if (check == 1)
  907. {
  908. result.Add(newDis);
  909. return GetAllDataSource(level + 1, result);
  910. }
  911. else
  912. {
  913. return result;
  914. }
  915. }
  916. private Boolean CopyAllDataSource(String destinationID, List<DistributedByLevel> source, int count, List<DistributedByLevel> result)
  917. {
  918. if (source.Count == count - 1)
  919. {
  920. return true;
  921. }
  922. else
  923. {
  924. DistributedByLevel child = source.Find(x => x.level == count);
  925. DistributedByLevel parent = result.Find(x => x.level == count - 1);
  926. for (int i = 0; i < child.mapData.Count; i++)
  927. {
  928. MapData childMap = child.mapData[i];
  929. MapData parentMap = count > 1 ? parent.mapData.Find(x => x.oldData.id == childMap.oldData.parent_id) : null;
  930. childMap.newData = (RowStructure)childMap.oldData.Clone();
  931. // push event to the server
  932. ActionRequest userRequest = new ActionRequest();
  933. userRequest.PARENT_ID = count > 1 ? parentMap.newData.id : destinationID;
  934. userRequest.CODE = childMap.newData.code;
  935. userRequest.NAME_GLOBAL = childMap.newData.name_global;
  936. userRequest.NAME_LOCAL = childMap.newData.name_local;
  937. userRequest.DESCRIPTION_GLOBAL = childMap.newData.description_global;
  938. userRequest.DESCRIPTION_LOCAL = childMap.newData.description_local;
  939. userRequest.INTRODUCTION_GLOBAL = childMap.newData.introduction_global;
  940. userRequest.INTRODUCTION_LOCAL = childMap.newData.introduction_local;
  941. userRequest.ICON = childMap.newData.realIcon;
  942. userRequest.LOGO = childMap.newData.realLogo;
  943. userRequest.CONTENT = childMap.newData.content;
  944. userRequest.CONTENT_TYPE = UtilsController.Constant.TEXT_TYPE;
  945. userRequest.IS_SHOW = UtilsController.Constant.ALL_TYPE;
  946. userRequest.PROVINCE_ID = UtilsController.Constant.ALL_CATEGORIES;
  947. userRequest.TOPIC_ID = UtilsController.Constant.ALL_CATEGORIES;
  948. userRequest.FROM_DATE = childMap.newData.from_date;
  949. userRequest.TO_DATE = childMap.newData.to_date;
  950. userRequest.TYPE = UtilsController.Constant.ADMIN_TYPE;
  951. userRequest.NOTE = "";
  952. String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.INSERT_DATA));
  953. AppResponse res = new AppResponse(rs);
  954. if (res.status == UtilsController.Constant.SUCCESS)
  955. {
  956. childMap.newData.id = res.newsId;
  957. childMap.newData.parent_id = count > 1 ? parentMap.newData.id : destinationID;
  958. child.mapData.Where(S => S.oldData.id == childMap.oldData.id).Select(S =>
  959. {
  960. S.newData = childMap.newData;
  961. return S;
  962. }).ToList();
  963. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
  964. rows.data.Add(childMap.newData);
  965. HttpContext.Session.SetComplexData("rows", rows);
  966. }
  967. else
  968. {
  969. return false;
  970. }
  971. }
  972. child.level = count;
  973. result.Add(child);
  974. return CopyAllDataSource(destinationID, source, count + 1, result);
  975. }
  976. }
  977. // PROCEDURES
  978. public IActionResult Approves(String page, String status)
  979. {
  980. try
  981. {
  982. if (!CheckAuthToken())
  983. {
  984. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  985. }
  986. string serviceName = GetParameter(UtilsController.Constant.SERVICE_NAME);
  987. HttpContext.Session.SetComplexData("serviceName", serviceName);
  988. EventViewModel model = new EventViewModel();
  989. //model.categories = new RowStructures();
  990. //model.categories.data = new List<RowStructure>();
  991. //model.columns = new RowStructures();
  992. //model.columns.data = new List<RowStructure>();
  993. model.page = page == null ? "1" : page;
  994. model.status = status != null ? status : UtilsController.Constant.WAIT_APPROVAL;
  995. model.events = new RowStructures();
  996. model.events.data = new List<RowStructure>();
  997. //RowStructures categories = HttpContext.Session.GetComplexData<RowStructures>("categories");
  998. //RowStructures columns = HttpContext.Session.GetComplexData<RowStructures>("columns");
  999. //if (categories == null)
  1000. //{
  1001. // // get all categories
  1002. // GetRequest request = new GetRequest();
  1003. // request.ID = BaseController.PARENT_ID;
  1004. // String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  1005. // AppResponse res = new AppResponse(rs);
  1006. // if (res.status == UtilsController.Constant.SUCCESS)
  1007. // {
  1008. // categories = new RowStructures(configuration, rs);
  1009. // }
  1010. // HttpContext.Session.SetComplexData("categories", categories);
  1011. //}
  1012. //model.categories = categories;
  1013. //if (columns == null)
  1014. //{
  1015. // columns = new RowStructures();
  1016. // columns.data = new List<RowStructure>();
  1017. // for (int i = 0; i < model.categories.data.Count; i++)
  1018. // {
  1019. // // get all columns
  1020. // GetRequest columnsReq = new GetRequest();
  1021. // columnsReq.ID = model.categories.data[i].id;
  1022. // String rsColumn = SendPost(columnsReq, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  1023. // AppResponse resColumn = new AppResponse(rsColumn);
  1024. // if (resColumn.status == UtilsController.Constant.SUCCESS)
  1025. // {
  1026. // RowStructures dataGet = new RowStructures(configuration, rsColumn);
  1027. // dataGet.data.ForEach(x => columns.data.Add(x));
  1028. // }
  1029. // }
  1030. // HttpContext.Session.SetComplexData("columns", columns);
  1031. //}
  1032. //model.columns = columns;
  1033. //for (int i = 0; i < model.columns.data.Count; i++)
  1034. //{
  1035. // // get all approved events
  1036. // GetRequest requestEvent = new GetRequest();
  1037. // //request.users = account.username;
  1038. // //request.msisdn = account.username;
  1039. // requestEvent.ID = model.columns.data[i].id;
  1040. // requestEvent.type = status == UtilsController.Constant.USER_TYPE ? UtilsController.Constant.ADMIN_TYPE : UtilsController.Constant.ALL_TYPE;
  1041. // requestEvent.rowsOnPage = UtilsController.Constant.ROWS_ON_PAGE;
  1042. // requestEvent.seqPage = page == null ? "1" : page;
  1043. // requestEvent.isGetContet = UtilsController.Constant.NOT_GET_CONTENT;
  1044. // requestEvent.isShow = status != null ? status : UtilsController.Constant.WAIT_APPROVAL;
  1045. // String rsEvent = SendPost(requestEvent, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  1046. // AppResponse resEvent = new AppResponse(rsEvent);
  1047. // if (resEvent.status == UtilsController.Constant.SUCCESS)
  1048. // {
  1049. // model.totalPage = resEvent.totalPage;
  1050. // RowStructures events = new RowStructures(configuration, rsEvent);
  1051. // events.data.ForEach(x => model.events.data.Add(x));
  1052. // }
  1053. //}
  1054. //model.events.data = model.events.data.FindAll(x => x.is_show != UtilsController.Constant.ALL_TYPE);
  1055. // get all approved events
  1056. GetRequest requestEvent = new GetRequest();
  1057. //request.users = account.username;
  1058. //request.msisdn = account.username;
  1059. requestEvent.ID = BaseController.PARENT_ID;
  1060. requestEvent.type = status == UtilsController.Constant.USER_TYPE ? UtilsController.Constant.ADMIN_TYPE : UtilsController.Constant.ALL_TYPE;
  1061. requestEvent.rowsOnPage = UtilsController.Constant.ROWS_ON_PAGE;
  1062. requestEvent.seqPage = page == null ? "1" : page;
  1063. requestEvent.isGetContet = UtilsController.Constant.NOT_GET_CONTENT;
  1064. requestEvent.isShow = status != null ? status : UtilsController.Constant.WAIT_APPROVAL;
  1065. requestEvent.isGetChildById = "1";
  1066. String rsEvent = SendPost(requestEvent, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  1067. AppResponse resEvent = new AppResponse(rsEvent);
  1068. if (resEvent.status == UtilsController.Constant.SUCCESS)
  1069. {
  1070. model.totalPage = resEvent.totalPage;
  1071. RowStructures events = new RowStructures(configuration, rsEvent);
  1072. events.data.ForEach(x => model.events.data.Add(x));
  1073. }
  1074. HttpContext.Session.SetComplexData("events", model.events);
  1075. return View("~/Views/Tree/Event/Approves.cshtml", model);
  1076. //return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Event/Approves?page=" + page + "&status=" + status);
  1077. }
  1078. catch (Exception ex)
  1079. {
  1080. log.Error("Exception " + ex);
  1081. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home");
  1082. }
  1083. }
  1084. public IActionResult Aprroving(String id)
  1085. {
  1086. try
  1087. {
  1088. if (!CheckAuthToken())
  1089. {
  1090. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
  1091. }
  1092. if (id == null)
  1093. {
  1094. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
  1095. }
  1096. string serviceName = GetParameter(UtilsController.Constant.SERVICE_NAME);
  1097. HttpContext.Session.SetComplexData("serviceName", serviceName);
  1098. EventViewModel model = new EventViewModel();
  1099. model.categories = new RowStructures();
  1100. model.categories.data = new List<RowStructure>();
  1101. model.columns = new RowStructures();
  1102. model.columns.data = new List<RowStructure>();
  1103. //RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("events");
  1104. //model.now = rows.data.Find(x => x.id == id);
  1105. //model.parent = rows.data.Find(x => x.id == model.now.parent_id);
  1106. //RowStructures categories = HttpContext.Session.GetComplexData<RowStructures>("categories");
  1107. //RowStructures columns = HttpContext.Session.GetComplexData<RowStructures>("columns");
  1108. //if (categories == null)
  1109. //{
  1110. // // get all categories
  1111. // GetRequest request = new GetRequest();
  1112. // request.ID = BaseController.PARENT_ID;
  1113. // String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  1114. // AppResponse res = new AppResponse(rs);
  1115. // if (res.status == UtilsController.Constant.SUCCESS)
  1116. // {
  1117. // categories = new RowStructures(configuration, rs);
  1118. // }
  1119. // HttpContext.Session.SetComplexData("categories", categories);
  1120. //}
  1121. //model.categories = categories;
  1122. //if (columns == null)
  1123. //{
  1124. // columns = new RowStructures();
  1125. // columns.data = new List<RowStructure>();
  1126. // for (int i = 0; i < model.categories.data.Count; i++)
  1127. // {
  1128. // // get all columns
  1129. // GetRequest columnsReq = new GetRequest();
  1130. // columnsReq.ID = BaseController.PARENT_ID;
  1131. // String rsColumn = SendPost(columnsReq, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  1132. // AppResponse resColumn = new AppResponse(rsColumn);
  1133. // if (resColumn.status == UtilsController.Constant.SUCCESS)
  1134. // {
  1135. // RowStructures dataGet = new RowStructures(configuration, rsColumn);
  1136. // dataGet.data.ForEach(x => columns.data.Add(x));
  1137. // }
  1138. // }
  1139. // HttpContext.Session.SetComplexData("columns", columns);
  1140. //}
  1141. //model.columns = columns;
  1142. //if (model.now != null)
  1143. //{
  1144. // get details
  1145. GetRequest request1 = new GetRequest();
  1146. request1.ID = id;
  1147. request1.isGetContet = UtilsController.Constant.GET_CONTENT;
  1148. String rs1 = SendPost(request1, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_ID));
  1149. AppResponse res1 = new AppResponse(rs1);
  1150. if (res1.status == UtilsController.Constant.SUCCESS)
  1151. {
  1152. RowStructures rowsGet = new RowStructures(configuration, rs1);
  1153. model.now = rowsGet.data[0];
  1154. }
  1155. // get all parents
  1156. GetRequest request = new GetRequest();
  1157. request.ID = model.now.id;
  1158. request.isGetChildById = "2"; // get all parents
  1159. String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
  1160. AppResponse res = new AppResponse(rs);
  1161. if (res.status == UtilsController.Constant.SUCCESS)
  1162. {
  1163. model.categories = new RowStructures(configuration, rs);
  1164. }
  1165. //}
  1166. HttpContext.Session.SetComplexData("approving", model.now);
  1167. return PartialView("~/Views/Tree/Event/Approving.cshtml", model);
  1168. }
  1169. catch (Exception ex)
  1170. {
  1171. log.Error("Exception " + ex);
  1172. return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
  1173. }
  1174. }
  1175. [ValidateAntiForgeryToken]
  1176. public JsonResult ApprovingAction(String action, String note)
  1177. {
  1178. try
  1179. {
  1180. if (!CheckAuthToken())
  1181. {
  1182. return Json(new
  1183. {
  1184. code = UtilsController.Constant.AUTHEN_FAIL,
  1185. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
  1186. });
  1187. }
  1188. String page = HttpContext.Session.GetComplexData<String>("page");
  1189. RowStructure data = HttpContext.Session.GetComplexData<RowStructure>("approving");
  1190. data.note = note;
  1191. // push event to the server
  1192. ActionRequest userRequest = new ActionRequest();
  1193. userRequest.ID = data.id;
  1194. userRequest.NOTE = "";
  1195. userRequest.PARENT_ID = data.parent_id;
  1196. userRequest.CODE = data.code;
  1197. userRequest.NAME_GLOBAL = data.name_global;
  1198. userRequest.NAME_LOCAL = data.name_local;
  1199. userRequest.DESCRIPTION_GLOBAL = data.description_global;
  1200. userRequest.DESCRIPTION_LOCAL = data.description_local;
  1201. userRequest.INTRODUCTION_GLOBAL = data.introduction_global;
  1202. userRequest.INTRODUCTION_LOCAL = data.introduction_local;
  1203. userRequest.ICON = data.realIcon;
  1204. userRequest.LOGO = data.realLogo;
  1205. userRequest.CONTENT = data.content;
  1206. userRequest.CONTENT_TYPE = UtilsController.Constant.TEXT_TYPE;
  1207. //userRequest.IS_SHOW = data.is_show;
  1208. userRequest.PROVINCE_ID = data.province_id;
  1209. userRequest.TOPIC_ID = data.topic_id;
  1210. userRequest.FROM_DATE = data.from_date;
  1211. userRequest.TO_DATE = data.to_date;
  1212. userRequest.TYPE = UtilsController.Constant.EDITING;
  1213. userRequest.IS_SHOW = action == UtilsController.Constant.SAVE ? data.is_show :
  1214. action == UtilsController.Constant.PUBLISH ? UtilsController.Constant.APPROVED :
  1215. UtilsController.Constant.REJECTED;
  1216. String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.UPDATE_DATA));
  1217. AppResponse res = new AppResponse(rs);
  1218. if (res.status == UtilsController.Constant.SUCCESS)
  1219. {
  1220. RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("events");
  1221. rows.data.Where(S => S.id == data.id).Select(S =>
  1222. {
  1223. S.note = data.note;
  1224. return S;
  1225. }).ToList();
  1226. HttpContext.Session.SetComplexData("events", rows);
  1227. return Json(new
  1228. {
  1229. code = UtilsController.Constant.SUCCESS,
  1230. message = "Approve successful",
  1231. });
  1232. }
  1233. else
  1234. {
  1235. return Json(new
  1236. {
  1237. code = UtilsController.Constant.FAILURE,
  1238. message = "We have a problem!",
  1239. });
  1240. }
  1241. }
  1242. catch (Exception ex)
  1243. {
  1244. log.Error("Exception " + ex);
  1245. return Json(new
  1246. {
  1247. code = UtilsController.Constant.EXCEPTION,
  1248. href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
  1249. });
  1250. }
  1251. }
  1252. }
  1253. }