| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using SuperAdmin.Models.Http;
- using SuperAdmin.Models.Object;
- using SuperAdmin.Models.View;
- using SuperCms.Extensions;
- using static SuperAdmin.Models.View.CommonModel;
- namespace SuperAdmin.Controllers
- {
- public class TreeController : BaseController
- {
- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
- public TreeController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
- {
- // init
- }
- public IActionResult Index(String id)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- string serviceName = GetParameter(UtilsController.Constant.SERVICE_NAME);
- HttpContext.Session.SetComplexData("serviceName", serviceName);
- if (!CheckAuthToken())
- {
- return RedirectToAction("Index", "Home");
- }
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- TreeViewModel model = new TreeViewModel();
- model.rows = new RowStructures();
- model.rows.data = new List<RowStructure>();
- if (rows == null || 1 == 1)
- {
- GetRequest request = new GetRequest();
- request.ID = id != null ? id : BaseController.PARENT_ID;
- String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- RowStructures rowsGet = new RowStructures(configuration, rs);
- rowsGet.data.ForEach(x => model.rows.data.Add(x));
- }
- HttpContext.Session.SetComplexData("rows", model.rows);
- }
- else
- {
- rows.data.ForEach(x => model.rows.data.Add(x));
- model.rows.data = model.rows.data.FindAll(x => x.parent_id == BaseController.PARENT_ID);
- }
- return View("Index", model);
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
- }
- }
- public IActionResult GetTreeData(String id)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- TreeViewModel model = new TreeViewModel();
- model.rows = new RowStructures();
- model.rows.data = new List<RowStructure>();
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- List<RowStructure> rowGetSession = rows != null ? rows.data.FindAll(x => x.parent_id == id) : null;
- if (rowGetSession == null || rowGetSession.Count == 0)
- {
- GetRequest request = new GetRequest();
- request.ID = id;
- String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- RowStructures rowsGet = new RowStructures(configuration, rs);
- rowsGet.data.ForEach(x => rows.data.Add(x));
- model.rows = rowsGet;
- }
- HttpContext.Session.SetComplexData("rows", rows);
- }
- else
- {
- model.rows.data = rowGetSession;
- }
- return PartialView("TreePartial", model);
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
- }
- }
- public IActionResult GetTableData(String id)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- TreeViewModel model = new TreeViewModel();
- model.rows = new RowStructures();
- model.rows.data = new List<RowStructure>();
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- if (rows != null)
- {
- RowStructure parent = rows.data.Find(x => x.id == id);
- model.parent = parent;
- List<RowStructure> rowGetSession = rows != null ? rows.data.FindAll(x => x.parent_id == id) : null;
- if (rowGetSession == null || rowGetSession.Count == 0)
- {
- GetRequest request = new GetRequest();
- request.ID = id;
- String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- RowStructures rowsGet = new RowStructures(configuration, rs);
- rowsGet.data.ForEach(x => rows.data.Add(x));
- model.rows = rowsGet;
- }
- HttpContext.Session.SetComplexData("rows", rows);
- }
- else
- {
- model.rows.data = rowGetSession;
- }
- }
- return PartialView("TablePartial", model);
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
- }
- }
- // data
- private string UploadedFile(String folder, IFormFile image)
- {
- try
- {
- //string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "img");
- string uploadsFolder = GetParameter(UtilsController.Constant.PATH_OUTSIDE);
- uploadsFolder = Path.Combine(uploadsFolder, folder);
- if (!Directory.Exists(uploadsFolder))
- {
- Directory.CreateDirectory(uploadsFolder);
- }
- string uniqueFileName = Guid.NewGuid().ToString() + "_" + image.FileName;
- string filePath = Path.Combine(uploadsFolder, uniqueFileName);
- using (var fileStream = new FileStream(filePath, FileMode.Create))
- {
- image.CopyTo(fileStream);
- }
- return Path.Combine(folder, uniqueFileName);
- }
- catch (Exception ex)
- {
- log.Error("Exception: " + ex);
- return "";
- }
- }
- public IActionResult Adding(String id)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- EventViewModel model = new EventViewModel();
- if (id != BaseController.PARENT_ID)
- {
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- model.parent = rows.data.Find(x => x.id == id);
- }
- Provinces provinces = HttpContext.Session.GetComplexData<Provinces>("provinces");
- Topics topics = HttpContext.Session.GetComplexData<Topics>("topics");
- if (provinces == null)
- {
- provinces = new Provinces();
- provinces.data = new List<Province>();
- AppRequest userRequest = new AppRequest();
- userRequest.language = UtilsController.Constant.LANGUAGE_GLOBAL;
- String rsProvince = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_PROVINCES));
- AppResponse resProvince = new AppResponse(rsProvince);
- if (resProvince.status == UtilsController.Constant.SUCCESS)
- {
- provinces = new Provinces(rsProvince);
- HttpContext.Session.SetComplexData("provinces", provinces);
- }
- }
- if (topics == null)
- {
- topics = new Topics();
- topics.data = new List<Topic>();
- AppRequest topicRequest = new AppRequest();
- topicRequest.language = UtilsController.Constant.LANGUAGE_GLOBAL;
- String rsTopic = SendPost(topicRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_TOPICS));
- AppResponse resTopic = new AppResponse(rsTopic);
- if (resTopic.status == UtilsController.Constant.SUCCESS)
- {
- topics = new Topics(rsTopic);
- HttpContext.Session.SetComplexData("topics", topics);
- }
- }
- model.provinces = provinces;
- model.topics = topics;
- return PartialView("~/Views/Tree/Event/Adding.cshtml", model);
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
- }
- }
- [ValidateAntiForgeryToken]
- [HttpPost]
- public JsonResult AddingAction(RowStructure data, IFormFile icon, IFormFile logo)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.AUTHEN_FAIL,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- // check image upload
- if (icon != null && (icon.FileName.EndsWith(".png") || icon.FileName.EndsWith(".jpg") || icon.FileName.EndsWith(".jpeg"))
- && logo != null)
- {
- //List<IFormFile> newFiles = new List<IFormFile>();
- //newFiles.Add(icon);
- //newFiles.Add(logo);
- //Task<IActionResult> resUpload = OnPostUploadAsync(newFiles);
- //data.realIcon = icon.FileName;
- //data.realLogo = logo.FileName;
- String resIcon = UploadedFile(data.parent_id, icon);
- String resLogo = UploadedFile(data.parent_id, logo);
- if (resIcon != "" && resLogo != "")
- {
- data.realIcon = resIcon;
- data.realLogo = resLogo;
- }
- else
- {
- return Json(new
- {
- error_code = UtilsController.Constant.FAILURE,
- error_content = "An error happens with your logo or your icon.",
- });
- }
- }
- else if (icon != null || logo != null)
- {
- return Json(new
- {
- error_code = UtilsController.Constant.FAILURE,
- error_content = "An error happens with your logo",
- });
- }
- data.sv_id = GetParameter(UtilsController.Constant.SERVICE_ID);
- data.from_date = convertToDateTimeServer(data.from_date);
- data.to_date = convertToDateTimeServer(data.to_date);
- // push event to the server
- ActionRequest userRequest = new ActionRequest();
- userRequest.NOTE = "";
- userRequest.PARENT_ID = data.parent_id;
- userRequest.CODE = data.code;
- userRequest.NAME_GLOBAL = data.name_global;
- userRequest.NAME_LOCAL = data.name_local;
- userRequest.DESCRIPTION_GLOBAL = data.description_global;
- userRequest.DESCRIPTION_LOCAL = data.description_local;
- userRequest.INTRODUCTION_GLOBAL = data.introduction_global;
- userRequest.INTRODUCTION_LOCAL = data.introduction_local;
- userRequest.ICON = data.realIcon;
- userRequest.LOGO = data.realLogo;
- userRequest.CONTENT = data.content;
- userRequest.CONTENT_TYPE = UtilsController.Constant.TEXT_TYPE;
- userRequest.IS_SHOW = data.is_show;
- userRequest.PROVINCE_ID = UtilsController.Constant.ALL_CATEGORIES;
- userRequest.TOPIC_ID = UtilsController.Constant.ALL_CATEGORIES;
- userRequest.FROM_DATE = data.from_date;
- userRequest.TO_DATE = data.to_date;
- userRequest.TYPE = UtilsController.Constant.ADMIN_TYPE;
- String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.INSERT_DATA));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- data.id = res.newsId;
- data.name = data.name_global;
- rows.data.Add(data);
- HttpContext.Session.SetComplexData("rows", rows);
- List<String> ids = new List<string>();
- ids.Add(data.parent_id);
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- message = "Adding successful",
- ids = ids,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- message = "We have a problem!",
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.EXCEPTION,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
- });
- }
- }
- public IActionResult Editing(String id, String action)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- if (id == null)
- {
- //return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
- id = BaseController.PARENT_ID;
- }
- EventViewModel model = new EventViewModel();
- model.action = action;
- if (action == "add")
- {
- if (id != BaseController.PARENT_ID)
- {
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- model.parent = rows.data.Find(x => x.id == id);
- }
- }
- else
- {
- // edit
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- model.now = rows.data.Find(x => x.id == id);
- model.parent = rows.data.Find(x => x.id == model.now.parent_id);
- if (model.now != null)
- {
- // get details
- GetRequest request1 = new GetRequest();
- request1.ID = id;
- request1.isGetContet = UtilsController.Constant.GET_CONTENT;
- String rs1 = SendPost(request1, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_ID));
- AppResponse res1 = new AppResponse(rs1);
- if (res1.status == UtilsController.Constant.SUCCESS)
- {
- RowStructures rowsGet = new RowStructures(configuration, rs1);
- model.now = rowsGet.data[0];
- }
- }
- HttpContext.Session.SetComplexData("editing", model.now);
- }
- //Provinces provinces = HttpContext.Session.GetComplexData<Provinces>("provinces");
- //Topics topics = HttpContext.Session.GetComplexData<Topics>("topics");
- //if (provinces == null)
- //{
- // provinces = new Provinces();
- // provinces.data = new List<Province>();
- // AppRequest userRequest = new AppRequest();
- // userRequest.language = UtilsController.Constant.LANGUAGE_GLOBAL;
- // String rsProvince = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_PROVINCES));
- // AppResponse resProvince = new AppResponse(rsProvince);
- // if (resProvince.status == UtilsController.Constant.SUCCESS)
- // {
- // provinces = new Provinces(rsProvince);
- // HttpContext.Session.SetComplexData("provinces", provinces);
- // }
- //}
- //if (topics == null)
- //{
- // topics = new Topics();
- // topics.data = new List<Topic>();
- // AppRequest topicRequest = new AppRequest();
- // topicRequest.language = UtilsController.Constant.LANGUAGE_GLOBAL;
- // String rsTopic = SendPost(topicRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_TOPICS));
- // AppResponse resTopic = new AppResponse(rsTopic);
- // if (resTopic.status == UtilsController.Constant.SUCCESS)
- // {
- // topics = new Topics(rsTopic);
- // HttpContext.Session.SetComplexData("topics", topics);
- // }
- //}
- //model.provinces = provinces;
- //model.topics = topics;
- // get all parents
- GetRequest request = new GetRequest();
- request.ID = id;
- request.isGetChildById = "2"; // get all parents
- String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- model.categories = new RowStructures(configuration, rs);
- }
- return PartialView("~/Views/Tree/Event/Editing.cshtml", model);
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Redirect(HttpContext.Session.GetComplexData<RowStructures>(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
- }
- }
- [ValidateAntiForgeryToken]
- [HttpPost]
- public JsonResult EditingAction(RowStructure data, IFormFile icon, IFormFile logo, string action)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.AUTHEN_FAIL,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- // check image upload
- if (icon != null && (icon.FileName.EndsWith(".png") || icon.FileName.EndsWith(".jpg") || icon.FileName.EndsWith(".jpeg")) && logo != null)
- {
- String resIcon = UploadedFile(data.parent_id, icon);
- //String resLogo = UploadedFile(logo);
- if (resIcon != "")
- {
- data.realIcon = resIcon;
- //data.realLogo = resLogo;
- }
- else
- {
- return Json(new
- {
- error_code = UtilsController.Constant.FAILURE,
- error_content = "An error happens with your logo or your icon.",
- });
- }
- }
- if (logo != null)
- {
- //String resIcon = UploadedFile(icon);
- String resLogo = UploadedFile(data.parent_id, logo);
- if (resLogo != "")
- {
- //data.realIcon = resIcon;
- data.realLogo = resLogo;
- }
- else
- {
- return Json(new
- {
- error_code = UtilsController.Constant.FAILURE,
- error_content = "An error happens with your logo or your icon.",
- });
- }
- }
- //else if (icon != null || logo != null)
- //{
- // return Json(new
- // {
- // error_code = UtilsController.Constant.FAILURE,
- // error_content = "An error happens with your logo",
- // });
- //}
- RowStructure edit = HttpContext.Session.GetComplexData<RowStructure>("editing");
- data.sv_id = GetParameter(UtilsController.Constant.SERVICE_ID);
- data.from_date = convertToDateTimeServer(data.from_date);
- data.to_date = convertToDateTimeServer(data.to_date);
- // push event to the server
- ActionRequest userRequest = new ActionRequest();
- userRequest.NOTE = "";
- userRequest.PARENT_ID = data.parent_id;
- userRequest.NAME_GLOBAL = data.name_global;
- userRequest.NAME_GLOBAL1 = data.name_global1;
- userRequest.NAME_GLOBAL2 = data.name_global2;
- userRequest.NAME_LOCAL = data.name_local;
- userRequest.DESCRIPTION_GLOBAL = data.description_global;
- userRequest.DESCRIPTION_GLOBAL1 = data.description_global1;
- userRequest.DESCRIPTION_GLOBAL2 = data.description_global2;
- userRequest.DESCRIPTION_LOCAL = data.description_local;
- userRequest.INTRODUCTION_GLOBAL = data.introduction_global;
- userRequest.INTRODUCTION_GLOBAL1 = data.introduction_global1;
- userRequest.INTRODUCTION_GLOBAL2 = data.introduction_global2;
- userRequest.INTRODUCTION_LOCAL = data.introduction_local;
- userRequest.ICON = data.realIcon;
- userRequest.LOGO = data.realLogo;
- userRequest.CONTENT = data.content;
- userRequest.CONTENT_GLOBAL = data.content_global;
- userRequest.CONTENT_GLOBAL1 = data.content_global1;
- userRequest.CONTENT_GLOBAL2 = data.content_global2;
- userRequest.CONTENT_TYPE = UtilsController.Constant.TEXT_TYPE;
- userRequest.IS_SHOW = UtilsController.Constant.WAIT_APPROVAL;//data.is_show;
- userRequest.PROVINCE_ID = UtilsController.Constant.ALL_CATEGORIES;
- userRequest.TOPIC_ID = UtilsController.Constant.ALL_CATEGORIES;
- userRequest.FROM_DATE = data.from_date;
- userRequest.TO_DATE = data.to_date;
- userRequest.TYPE = UtilsController.Constant.EDITING;
- if (action == "add")
- {
- userRequest.CODE = data.code;
- }
- else
- {
- data.id = edit.id;
- data.parent_id = edit.parent_id;
- userRequest.CODE = data.code;
- }
- if (action == "add")
- {
- // add new
- String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.INSERT_DATA));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- data.id = res.newsId;
- data.name = data.name_global;
- rows.data.Add(data);
- HttpContext.Session.SetComplexData("rows", rows);
- List<String> ids = new List<string>();
- ids.Add(data.parent_id);
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- message = "Adding successful",
- ids = ids,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- message = "We have a problem!",
- });
- }
- }
- else
- {
- // edit
- userRequest.ID = data.id;
- String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.UPDATE_DATA));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- rows.data.Where(S => S.id == data.id).Select(S =>
- {
- S.code = data.code;
- S.name = data.name;
- S.name_global = data.name_global;
- S.name_global1 = data.name_global1;
- S.name_global2 = data.name_global2;
- S.name_local = data.name_local;
- S.description_global = data.description_global;
- S.description_global1 = data.description_global1;
- S.description_global2 = data.description_global2;
- S.description_local = data.description_local;
- S.introduction_global = data.introduction_global;
- S.introduction_global1 = data.introduction_global1;
- S.introduction_global2 = data.introduction_global2;
- S.introduction_local = data.introduction_local;
- S.icon = data.realIcon;
- S.logo = data.realLogo;
- S.content = data.content;
- S.content_global = data.content_global;
- S.content_global1 = data.content_global1;
- S.content_global2 = data.content_global2;
- S.content_type = UtilsController.Constant.TEXT_TYPE;
- S.is_show = data.is_show;
- S.province_id = data.province_id;
- S.topic_id = data.topic_id;
- S.from_date = data.from_date;
- S.to_date = data.to_date;
- S.permission = UtilsController.Constant.ADMIN_TYPE;
- return S;
- }).ToList();
- HttpContext.Session.SetComplexData("rows", rows);
- List<String> ids = new List<string>();
- ids.Add(data.parent_id);
- return Json(new
- {
- ids = ids,
- code = UtilsController.Constant.SUCCESS,
- message = "Editing successful",
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- message = "We have a problem!",
- });
- }
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.EXCEPTION,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult DeletingAction(String id)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.AUTHEN_FAIL,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
- });
- }
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- RowStructure data = rows.data.Find(x => x.id == id);
- if (data == null)
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home"
- });
- }
- ActionRequest request = new ActionRequest();
- request.ID = data.id;
- request.TYPE = UtilsController.Constant.DELETE;
- String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.UPDATE_DATA));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- //return Redirect("/EventAdmin/EventShowing");
- rows.data.RemoveAll(x => x.id == id);
- HttpContext.Session.SetComplexData("rows", rows);
- List<String> ids = new List<string>();
- ids.Add(data.parent_id);
- List<String> funcs = new List<string>();
- funcs.Add(UtilsController.Constant.GetTableAction);
- List<String> paras = new List<string>();
- paras.Add(data.parent_id);
- return Json(new
- {
- ids = ids,
- code = UtilsController.Constant.SUCCESS,
- message = "Deleting successful",
- functions = funcs,
- parameters = paras,
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- message = "We have a problem!",
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.EXCEPTION,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult MovingAction(String sourceID, String destinationID)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.AUTHEN_FAIL,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
- });
- }
- if (sourceID == null || destinationID == null)
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
- });
- }
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- RowStructure source = rows.data.Find(x => x.id == sourceID);
- RowStructure destination = rows.data.Find(x => x.id == destinationID);
- if (source == null || destination == null)
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
- });
- }
- String oldParent = source.parent_id;
- // update source parent id to destination
- source.parent_id = destination.id;
- // push event to the server
- ActionRequest userRequest = new ActionRequest();
- userRequest.ID = source.id;
- userRequest.NOTE = "";
- userRequest.PARENT_ID = source.parent_id;
- userRequest.CODE = source.code;
- userRequest.NAME_GLOBAL = source.name_global;
- userRequest.NAME_LOCAL = source.name_local;
- userRequest.DESCRIPTION_GLOBAL = source.description_global;
- userRequest.DESCRIPTION_LOCAL = source.description_local;
- userRequest.INTRODUCTION_GLOBAL = source.introduction_global;
- userRequest.INTRODUCTION_LOCAL = source.introduction_local;
- userRequest.ICON = source.realIcon;
- userRequest.LOGO = source.realLogo;
- userRequest.CONTENT = source.content;
- userRequest.CONTENT_TYPE = UtilsController.Constant.TEXT_TYPE;
- userRequest.IS_SHOW = source.is_show;
- userRequest.PROVINCE_ID = source.province_id;
- userRequest.TOPIC_ID = source.topic_id;
- userRequest.FROM_DATE = source.from_date;
- userRequest.TO_DATE = source.to_date;
- userRequest.TYPE = UtilsController.Constant.ADMIN_TYPE;
- String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.UPDATE_DATA));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- rows.data.Where(S => S.id == source.id).Select(S =>
- {
- S.parent_id = source.parent_id;
- return S;
- }).ToList();
- HttpContext.Session.SetComplexData("rows", rows);
- List<String> ids = new List<string>();
- ids.Add(destination.id);
- ids.Add(oldParent);
- return Json(new
- {
- ids = ids,
- code = UtilsController.Constant.SUCCESS,
- message = "Moving successful",
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- message = "We have a problem!",
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.EXCEPTION,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home"
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult CopyingAction(String sourceID, String destinationID)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.AUTHEN_FAIL,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
- });
- }
- if (sourceID == null || destinationID == null)
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
- });
- }
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- RowStructure source = rows.data.Find(x => x.id == sourceID);
- RowStructure destination = rows.data.Find(x => x.id == destinationID);
- if (source == null || destination == null)
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- message = "We have a problem. Parent id was not found!",
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
- });
- }
- MapData map = new MapData();
- map.oldData = source;
- DistributedByLevel one = new DistributedByLevel();
- one.mapData = new List<MapData>();
- one.mapData.Add(map);
- one.level = 1;
- List<DistributedByLevel> listOne = new List<DistributedByLevel>();
- listOne.Add(one);
- List<DistributedByLevel> dataCopy = GetAllDataSource(1, listOne);
- Boolean res = CopyAllDataSource(destinationID, dataCopy, 1, new List<DistributedByLevel>());
- if (res)
- {
- List<String> ids = new List<string>();
- ids.Add(source.parent_id);
- ids.Add(destination.id);
- return Json(new
- {
- ids = ids,
- code = UtilsController.Constant.SUCCESS,
- message = "Copying successful",
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- message = "We have a problem!",
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.EXCEPTION,
- message = "We have a problem. Exception!",
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home"
- });
- }
- }
- private List<DistributedByLevel> GetAllDataSource(int level, List<DistributedByLevel> result)
- {
- DistributedByLevel now = result.Find(x => x.level == level);
- DistributedByLevel newDis = new DistributedByLevel();
- newDis.level = level + 1;
- newDis.mapData = new List<MapData>();
- int check = 1;
- for (int i = 0; i < now.mapData.Count; i++)
- {
- GetRequest request = new GetRequest();
- request.ID = now.mapData[i].oldData.id;
- request.isGetContet = UtilsController.Constant.GET_CONTENT;
- String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- RowStructures rowsGet = new RowStructures(configuration, rs);
- for (int a = 0; a < rowsGet.data.Count; a++)
- {
- MapData map = new MapData();
- map.oldData = rowsGet.data[a];
- newDis.mapData.Add(map);
- }
- }
- else
- {
- check *= 0;
- }
- }
- if (check == 1)
- {
- result.Add(newDis);
- return GetAllDataSource(level + 1, result);
- }
- else
- {
- return result;
- }
- }
- private Boolean CopyAllDataSource(String destinationID, List<DistributedByLevel> source, int count, List<DistributedByLevel> result)
- {
- if (source.Count == count - 1)
- {
- return true;
- }
- else
- {
- DistributedByLevel child = source.Find(x => x.level == count);
- DistributedByLevel parent = result.Find(x => x.level == count - 1);
- for (int i = 0; i < child.mapData.Count; i++)
- {
- MapData childMap = child.mapData[i];
- MapData parentMap = count > 1 ? parent.mapData.Find(x => x.oldData.id == childMap.oldData.parent_id) : null;
- childMap.newData = (RowStructure)childMap.oldData.Clone();
- // push event to the server
- ActionRequest userRequest = new ActionRequest();
- userRequest.PARENT_ID = count > 1 ? parentMap.newData.id : destinationID;
- userRequest.CODE = childMap.newData.code;
- userRequest.NAME_GLOBAL = childMap.newData.name_global;
- userRequest.NAME_LOCAL = childMap.newData.name_local;
- userRequest.DESCRIPTION_GLOBAL = childMap.newData.description_global;
- userRequest.DESCRIPTION_LOCAL = childMap.newData.description_local;
- userRequest.INTRODUCTION_GLOBAL = childMap.newData.introduction_global;
- userRequest.INTRODUCTION_LOCAL = childMap.newData.introduction_local;
- userRequest.ICON = childMap.newData.realIcon;
- userRequest.LOGO = childMap.newData.realLogo;
- userRequest.CONTENT = childMap.newData.content;
- userRequest.CONTENT_TYPE = UtilsController.Constant.TEXT_TYPE;
- userRequest.IS_SHOW = UtilsController.Constant.ALL_TYPE;
- userRequest.PROVINCE_ID = UtilsController.Constant.ALL_CATEGORIES;
- userRequest.TOPIC_ID = UtilsController.Constant.ALL_CATEGORIES;
- userRequest.FROM_DATE = childMap.newData.from_date;
- userRequest.TO_DATE = childMap.newData.to_date;
- userRequest.TYPE = UtilsController.Constant.ADMIN_TYPE;
- userRequest.NOTE = "";
- String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.INSERT_DATA));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- childMap.newData.id = res.newsId;
- childMap.newData.parent_id = count > 1 ? parentMap.newData.id : destinationID;
- child.mapData.Where(S => S.oldData.id == childMap.oldData.id).Select(S =>
- {
- S.newData = childMap.newData;
- return S;
- }).ToList();
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("rows");
- rows.data.Add(childMap.newData);
- HttpContext.Session.SetComplexData("rows", rows);
- }
- else
- {
- return false;
- }
- }
- child.level = count;
- result.Add(child);
- return CopyAllDataSource(destinationID, source, count + 1, result);
- }
- }
- // PROCEDURES
- public IActionResult Approves(String page, String status)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- string serviceName = GetParameter(UtilsController.Constant.SERVICE_NAME);
- HttpContext.Session.SetComplexData("serviceName", serviceName);
- EventViewModel model = new EventViewModel();
- //model.categories = new RowStructures();
- //model.categories.data = new List<RowStructure>();
- //model.columns = new RowStructures();
- //model.columns.data = new List<RowStructure>();
- model.page = page == null ? "1" : page;
- model.status = status != null ? status : UtilsController.Constant.WAIT_APPROVAL;
- model.events = new RowStructures();
- model.events.data = new List<RowStructure>();
- //RowStructures categories = HttpContext.Session.GetComplexData<RowStructures>("categories");
- //RowStructures columns = HttpContext.Session.GetComplexData<RowStructures>("columns");
- //if (categories == null)
- //{
- // // get all categories
- // GetRequest request = new GetRequest();
- // request.ID = BaseController.PARENT_ID;
- // String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- // AppResponse res = new AppResponse(rs);
- // if (res.status == UtilsController.Constant.SUCCESS)
- // {
- // categories = new RowStructures(configuration, rs);
- // }
- // HttpContext.Session.SetComplexData("categories", categories);
- //}
- //model.categories = categories;
- //if (columns == null)
- //{
- // columns = new RowStructures();
- // columns.data = new List<RowStructure>();
- // for (int i = 0; i < model.categories.data.Count; i++)
- // {
- // // get all columns
- // GetRequest columnsReq = new GetRequest();
- // columnsReq.ID = model.categories.data[i].id;
- // String rsColumn = SendPost(columnsReq, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- // AppResponse resColumn = new AppResponse(rsColumn);
- // if (resColumn.status == UtilsController.Constant.SUCCESS)
- // {
- // RowStructures dataGet = new RowStructures(configuration, rsColumn);
- // dataGet.data.ForEach(x => columns.data.Add(x));
- // }
- // }
- // HttpContext.Session.SetComplexData("columns", columns);
- //}
- //model.columns = columns;
- //for (int i = 0; i < model.columns.data.Count; i++)
- //{
- // // get all approved events
- // GetRequest requestEvent = new GetRequest();
- // //request.users = account.username;
- // //request.msisdn = account.username;
- // requestEvent.ID = model.columns.data[i].id;
- // requestEvent.type = status == UtilsController.Constant.USER_TYPE ? UtilsController.Constant.ADMIN_TYPE : UtilsController.Constant.ALL_TYPE;
- // requestEvent.rowsOnPage = UtilsController.Constant.ROWS_ON_PAGE;
- // requestEvent.seqPage = page == null ? "1" : page;
- // requestEvent.isGetContet = UtilsController.Constant.NOT_GET_CONTENT;
- // requestEvent.isShow = status != null ? status : UtilsController.Constant.WAIT_APPROVAL;
- // String rsEvent = SendPost(requestEvent, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- // AppResponse resEvent = new AppResponse(rsEvent);
- // if (resEvent.status == UtilsController.Constant.SUCCESS)
- // {
- // model.totalPage = resEvent.totalPage;
- // RowStructures events = new RowStructures(configuration, rsEvent);
- // events.data.ForEach(x => model.events.data.Add(x));
- // }
- //}
- //model.events.data = model.events.data.FindAll(x => x.is_show != UtilsController.Constant.ALL_TYPE);
- // get all approved events
- GetRequest requestEvent = new GetRequest();
- //request.users = account.username;
- //request.msisdn = account.username;
- requestEvent.ID = BaseController.PARENT_ID;
- requestEvent.type = status == UtilsController.Constant.USER_TYPE ? UtilsController.Constant.ADMIN_TYPE : UtilsController.Constant.ALL_TYPE;
- requestEvent.rowsOnPage = UtilsController.Constant.ROWS_ON_PAGE;
- requestEvent.seqPage = page == null ? "1" : page;
- requestEvent.isGetContet = UtilsController.Constant.NOT_GET_CONTENT;
- requestEvent.isShow = status != null ? status : UtilsController.Constant.WAIT_APPROVAL;
- requestEvent.isGetChildById = "1";
- String rsEvent = SendPost(requestEvent, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- AppResponse resEvent = new AppResponse(rsEvent);
- if (resEvent.status == UtilsController.Constant.SUCCESS)
- {
- model.totalPage = resEvent.totalPage;
- RowStructures events = new RowStructures(configuration, rsEvent);
- events.data.ForEach(x => model.events.data.Add(x));
- }
- HttpContext.Session.SetComplexData("events", model.events);
- return View("~/Views/Tree/Event/Approves.cshtml", model);
- //return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Event/Approves?page=" + page + "&status=" + status);
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home");
- }
- }
- public IActionResult Aprroving(String id)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login");
- }
- if (id == null)
- {
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
- }
- string serviceName = GetParameter(UtilsController.Constant.SERVICE_NAME);
- HttpContext.Session.SetComplexData("serviceName", serviceName);
- EventViewModel model = new EventViewModel();
- model.categories = new RowStructures();
- model.categories.data = new List<RowStructure>();
- model.columns = new RowStructures();
- model.columns.data = new List<RowStructure>();
- //RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("events");
- //model.now = rows.data.Find(x => x.id == id);
- //model.parent = rows.data.Find(x => x.id == model.now.parent_id);
- //RowStructures categories = HttpContext.Session.GetComplexData<RowStructures>("categories");
- //RowStructures columns = HttpContext.Session.GetComplexData<RowStructures>("columns");
- //if (categories == null)
- //{
- // // get all categories
- // GetRequest request = new GetRequest();
- // request.ID = BaseController.PARENT_ID;
- // String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- // AppResponse res = new AppResponse(rs);
- // if (res.status == UtilsController.Constant.SUCCESS)
- // {
- // categories = new RowStructures(configuration, rs);
- // }
- // HttpContext.Session.SetComplexData("categories", categories);
- //}
- //model.categories = categories;
- //if (columns == null)
- //{
- // columns = new RowStructures();
- // columns.data = new List<RowStructure>();
- // for (int i = 0; i < model.categories.data.Count; i++)
- // {
- // // get all columns
- // GetRequest columnsReq = new GetRequest();
- // columnsReq.ID = BaseController.PARENT_ID;
- // String rsColumn = SendPost(columnsReq, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- // AppResponse resColumn = new AppResponse(rsColumn);
- // if (resColumn.status == UtilsController.Constant.SUCCESS)
- // {
- // RowStructures dataGet = new RowStructures(configuration, rsColumn);
- // dataGet.data.ForEach(x => columns.data.Add(x));
- // }
- // }
- // HttpContext.Session.SetComplexData("columns", columns);
- //}
- //model.columns = columns;
- //if (model.now != null)
- //{
- // get details
- GetRequest request1 = new GetRequest();
- request1.ID = id;
- request1.isGetContet = UtilsController.Constant.GET_CONTENT;
- String rs1 = SendPost(request1, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_ID));
- AppResponse res1 = new AppResponse(rs1);
- if (res1.status == UtilsController.Constant.SUCCESS)
- {
- RowStructures rowsGet = new RowStructures(configuration, rs1);
- model.now = rowsGet.data[0];
- }
- // get all parents
- GetRequest request = new GetRequest();
- request.ID = model.now.id;
- request.isGetChildById = "2"; // get all parents
- String rs = SendPost(request, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.GET_BY_PARENT_ID));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- model.categories = new RowStructures(configuration, rs);
- }
- //}
- HttpContext.Session.SetComplexData("approving", model.now);
- return PartialView("~/Views/Tree/Event/Approving.cshtml", model);
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Redirect(GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error");
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult ApprovingAction(String action, String note)
- {
- try
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- code = UtilsController.Constant.AUTHEN_FAIL,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Home/Login"
- });
- }
- String page = HttpContext.Session.GetComplexData<String>("page");
- RowStructure data = HttpContext.Session.GetComplexData<RowStructure>("approving");
- data.note = note;
- // push event to the server
- ActionRequest userRequest = new ActionRequest();
- userRequest.ID = data.id;
- userRequest.NOTE = "";
- userRequest.PARENT_ID = data.parent_id;
- userRequest.CODE = data.code;
- userRequest.NAME_GLOBAL = data.name_global;
- userRequest.NAME_LOCAL = data.name_local;
- userRequest.DESCRIPTION_GLOBAL = data.description_global;
- userRequest.DESCRIPTION_LOCAL = data.description_local;
- userRequest.INTRODUCTION_GLOBAL = data.introduction_global;
- userRequest.INTRODUCTION_LOCAL = data.introduction_local;
- userRequest.ICON = data.realIcon;
- userRequest.LOGO = data.realLogo;
- userRequest.CONTENT = data.content;
- userRequest.CONTENT_TYPE = UtilsController.Constant.TEXT_TYPE;
- //userRequest.IS_SHOW = data.is_show;
- userRequest.PROVINCE_ID = data.province_id;
- userRequest.TOPIC_ID = data.topic_id;
- userRequest.FROM_DATE = data.from_date;
- userRequest.TO_DATE = data.to_date;
- userRequest.TYPE = UtilsController.Constant.EDITING;
- userRequest.IS_SHOW = action == UtilsController.Constant.SAVE ? data.is_show :
- action == UtilsController.Constant.PUBLISH ? UtilsController.Constant.APPROVED :
- UtilsController.Constant.REJECTED;
- String rs = SendPost(userRequest, GetParameter(UtilsController.Constant.SERVICE_ID), GetParameter(UtilsController.Constant.UPDATE_DATA));
- AppResponse res = new AppResponse(rs);
- if (res.status == UtilsController.Constant.SUCCESS)
- {
- RowStructures rows = HttpContext.Session.GetComplexData<RowStructures>("events");
- rows.data.Where(S => S.id == data.id).Select(S =>
- {
- S.note = data.note;
- return S;
- }).ToList();
- HttpContext.Session.SetComplexData("events", rows);
- return Json(new
- {
- code = UtilsController.Constant.SUCCESS,
- message = "Approve successful",
- });
- }
- else
- {
- return Json(new
- {
- code = UtilsController.Constant.FAILURE,
- message = "We have a problem!",
- });
- }
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Json(new
- {
- code = UtilsController.Constant.EXCEPTION,
- href = GetParameter(UtilsController.Constant.SUB_DOMAIN) + "/Shared/Error"
- });
- }
- }
- }
- }
|