AppendixController.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. using DevExpress.Web.Mvc;
  2. using GreenTree.Nachtragsmanagement.Core;
  3. using GreenTree.Nachtragsmanagement.Core.Authentication;
  4. using GreenTree.Nachtragsmanagement.Services.Appendix;
  5. using GreenTree.Nachtragsmanagement.Services.Deviation;
  6. using GreenTree.Nachtragsmanagement.Services.Logging;
  7. using GreenTree.Nachtragsmanagement.Services.Site;
  8. using GreenTree.Nachtragsmanagement.Web.Framework.Authorization;
  9. using GreenTree.Nachtragsmanagement.Web.Models.Appendix;
  10. using GreenTree.Nachtragsmanagement.Web.Models.Deviation;
  11. using GreenTree.Nachtragsmanagement.Web.Models.Global;
  12. using Newtonsoft.Json;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Web;
  17. using System.Web.Mvc;
  18. namespace GreenTree.Nachtragsmanagement.Web.Controllers
  19. {
  20. public class AppendixController : Controller
  21. {
  22. private readonly IDeviationService _deviationSerivce;
  23. private readonly IAppendixService _appendixService;
  24. private readonly ISiteService _siteService;
  25. private readonly IUserHelper _userHelper;
  26. private readonly ILogger _logger;
  27. public AppendixController(
  28. IDeviationService deviationService,
  29. IAppendixService appendixService,
  30. ISiteService siteService,
  31. IUserHelper userHelper,
  32. ILogger logger)
  33. {
  34. _deviationSerivce = deviationService;
  35. _appendixService = appendixService;
  36. _siteService = siteService;
  37. _userHelper = userHelper;
  38. _logger = logger;
  39. ViewData["AllCategories"] = _appendixService.GetAllCategories();
  40. ViewData["AllStates"] = _appendixService.GetAllStates();
  41. }
  42. #region Appendices
  43. /// <summary>
  44. /// Basic appendix view function
  45. /// </summary>
  46. [FunctionAuthorize(true, "Appendix-Appendices")]
  47. public ActionResult ViewAppendices()
  48. {
  49. var currentUser = _userHelper.FromCookies();
  50. var appendices = _appendixService.GetAllUserAssignedAppendices(currentUser);
  51. var appendixModels = appendices
  52. .Select(u => AppendixDataModel.FromAppendix(u, false))
  53. .ToList();
  54. return View("~/Views/Appendices/View.cshtml", appendixModels);
  55. }
  56. /// <summary>
  57. /// Get JSON data of specific appendix
  58. /// </summary>
  59. /// <param name="id">Appendix id.</param>
  60. public ActionResult GetAppendix(int id = -1)
  61. {
  62. var appendix = _appendixService.GetAppendixById(id);
  63. if (appendix == null)
  64. return new JsonResult
  65. {
  66. Data = "notFound",
  67. JsonRequestBehavior = JsonRequestBehavior.AllowGet
  68. };
  69. var appendixModel = AppendixDataModel.FromAppendix(appendix, false);
  70. return new JsonResult
  71. {
  72. Data = JsonConvert.SerializeObject(appendixModel),
  73. JsonRequestBehavior = JsonRequestBehavior.AllowGet
  74. };
  75. }
  76. /// <summary>
  77. /// Callback result for appendix grid
  78. /// </summary>
  79. public ActionResult PartialAppendices(int scrollHeight = -1)
  80. {
  81. var currentUser = _userHelper.FromCookies();
  82. var appendices = _appendixService.GetAllUserAssignedAppendices(currentUser);
  83. var appendixModels = appendices
  84. .Select(u => AppendixDataModel.FromAppendix(u, false))
  85. .ToList();
  86. ViewData["ScrollHeight"] = scrollHeight;
  87. return PartialView("~/Views/Appendices/_AppendixGridPartial.cshtml", appendixModels);
  88. }
  89. /// <summary>
  90. /// Export result for appendix grid
  91. /// </summary>
  92. [HttpPost]
  93. public ActionResult ExportPartialAppendices(GridViewExportFormat exportformat)
  94. {
  95. if (exportformat == null || String.IsNullOrEmpty(exportformat.Format))
  96. return new EmptyResult();
  97. var currentUser = _userHelper.FromCookies();
  98. var appendices = _appendixService.GetAllUserAssignedAppendices(currentUser);
  99. var appendixModels = appendices
  100. .Select(u => AppendixDataModel.FromAppendix(u, false))
  101. .ToList();
  102. var viewContext = new ViewContext();
  103. var viewPage = new ViewPage();
  104. var htmlHelper = new HtmlHelper(viewContext, viewPage);
  105. var gridViewSettings = Extensions.GridViewSettingsHelper.AppendixGridViewSettings(htmlHelper);
  106. switch (exportformat.Format.ToLower())
  107. {
  108. case "xlsx":
  109. return GridViewExtension.ExportToXlsx(gridViewSettings, appendixModels);
  110. case "xls":
  111. return GridViewExtension.ExportToXls(gridViewSettings, appendixModels);
  112. case "pdf":
  113. return GridViewExtension.ExportToPdf(gridViewSettings, appendixModels);
  114. default:
  115. return new EmptyResult();
  116. }
  117. }
  118. /// <summary>
  119. /// Partial edit for editing of existing or for new appendix
  120. /// </summary>
  121. /// <param name="id">Id for existing appendix, otherweise -1.</param>
  122. public ActionResult EditAppendix(int id = -1)
  123. {
  124. var appendix = _appendixService.GetAppendixById(id);
  125. var appendixModel = AppendixDataModel.FromAppendix(appendix, true);
  126. var defaultState = _appendixService.GetDefaultState();
  127. if (defaultState != null)
  128. ViewData["DefaultState"] = defaultState.Id;
  129. return PartialView("~/Views/Appendices/_AppendixEditPartial.cshtml", appendixModel);
  130. }
  131. /// <summary>
  132. /// Partial edit for creating a new deviation for a site
  133. /// </summary>
  134. /// <param name="siteId">Id of the site which the deviation should be appended to.</param>
  135. public ActionResult AppendAppendixToSite(int siteId)
  136. {
  137. var site = _siteService.GetSiteById(siteId);
  138. var lastCustomNumber = 0;
  139. if (site.Appendices.Any())
  140. lastCustomNumber = site.Appendices
  141. .Max(d => StaticHelper.TryParseInt(d.CustomNumber));
  142. var appendixModel = new AppendixDataModel
  143. {
  144. Id = -1,
  145. SiteId = siteId,
  146. CustomNumber = (lastCustomNumber + 1).ToString(),
  147. Percentage = (decimal)0.5
  148. };
  149. var defaultState = _appendixService.GetDefaultState();
  150. if (defaultState != null)
  151. ViewData["DefaultState"] = defaultState.Id;
  152. return PartialView("~/Views/Appendices/_AppendixEditPartial.cshtml", appendixModel);
  153. }
  154. /// <summary>
  155. /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
  156. /// </summary>
  157. /// <param name="appendixModel">Appendix model to be saved.</param>
  158. [HttpPost, ValidateInput(false)]
  159. public ActionResult EditAppendix(AppendixDataModel appendixModel)
  160. {
  161. try
  162. {
  163. appendixModel.CategoryValueEntities =
  164. appendixModel.CategoryEntities
  165. .Select(r => JsonConvert.DeserializeObject<CategoryValueDataModel>(r))
  166. .ToList();
  167. for (int i = 0; i < appendixModel.CategoryValueEntities.Count; i++)
  168. appendixModel.CategoryValueEntities.ElementAt(i).Json = appendixModel.CategoryEntities.ElementAt(i);
  169. appendixModel.PercentageValue = appendixModel.OfferingValue * appendixModel.Percentage;
  170. if (!ModelState.IsValid)
  171. return PartialView("~/Views/Appendices/_AppendixEditPartial.cshtml", appendixModel);
  172. var categoryValues = appendixModel.CategoryValueEntities
  173. .Select(r => r.ToCategoryValue())
  174. .ToList();
  175. if (appendixModel.Id == -1)
  176. {
  177. var appendix = appendixModel.ToAppendix();
  178. appendix.SetCategoryValues(categoryValues);
  179. _appendixService.InsertAppendix(appendix);
  180. _logger.Entity(appendix, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookies());
  181. }
  182. else
  183. {
  184. var appendix = _appendixService.GetAppendixById(appendixModel.Id);
  185. appendix.CustomNumber = appendixModel.CustomNumber;
  186. appendix.Description = appendixModel.Description;
  187. appendix.Percentage = appendixModel.Percentage;
  188. appendix.OfferingNumber = appendixModel.OfferingNumber;
  189. appendix.OfferingDate = appendixModel.OfferingDate;
  190. appendix.NegotiationDate = appendixModel.NegotiationDate;
  191. appendix.NegotiationValue = appendixModel.NegotiationValue;
  192. appendix.ProtocolExists = appendixModel.ProtocolExists;
  193. appendix.StateId = appendixModel.StateId;
  194. appendix.OrderNumber = appendixModel.OrderNumber;
  195. appendix.OrderDate = appendixModel.OrderDate;
  196. appendix.OrderInvoiceCreated = appendixModel.OrderInvoiceCreated;
  197. appendix.Comment = appendixModel.Comment;
  198. appendix.SiteId = appendixModel.SiteId;
  199. appendix.SetCategoryValues(categoryValues);
  200. _appendixService.UpdateAppendix(appendix);
  201. _logger.Entity(appendix, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookies());
  202. }
  203. return new JsonResult
  204. {
  205. Data = "success"
  206. };
  207. }
  208. catch (Exception ex)
  209. {
  210. _logger.Error("Fehler bei Speicherung eines Nachtrags.", ex, _userHelper.FromCookies());
  211. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  212. }
  213. }
  214. /// <summary>
  215. /// Simple JSON result for deleting a specific appendix
  216. /// </summary>
  217. /// <param name="id">Appendix id.</param>
  218. [HttpPost]
  219. public ActionResult DeleteAppendix(int id)
  220. {
  221. try
  222. {
  223. var appendix = _appendixService.GetAppendixById(id);
  224. if (appendix != null)
  225. _appendixService.DeleteAppendix(appendix);
  226. _logger.Entity(appendix, Core.Domain.Logging.LogEntityActivity.Delete, _userHelper.FromCookies());
  227. return new JsonResult
  228. {
  229. Data = "success"
  230. };
  231. }
  232. catch (Exception ex)
  233. {
  234. _logger.Error("Fehler bei Löschung eines Nachtrags.", ex, _userHelper.FromCookies());
  235. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  236. }
  237. }
  238. #endregion
  239. #region Invoices
  240. /// <summary>
  241. /// Get JSON data of specific invoice
  242. /// </summary>
  243. /// <param name="id">Invoice id.</param>
  244. public ActionResult GetInvoice(int id = -1)
  245. {
  246. var invoice = _appendixService.GetInvoiceById(id);
  247. if (invoice == null)
  248. return new JsonResult
  249. {
  250. Data = "notFound",
  251. JsonRequestBehavior = JsonRequestBehavior.AllowGet
  252. };
  253. var invoiceModel = InvoiceDataModel.FromInvoice(invoice, false);
  254. return new JsonResult
  255. {
  256. Data = JsonConvert.SerializeObject(invoiceModel),
  257. JsonRequestBehavior = JsonRequestBehavior.AllowGet
  258. };
  259. }
  260. /// <summary>
  261. /// Callback result for Invoice list
  262. /// </summary>
  263. public ActionResult PartialInvoices(int appendixId = -1)
  264. {
  265. if (appendixId == -1)
  266. return PartialView("~/Views/Appendices/_InvoiceListPartial.cshtml", new AppendixDataModel());
  267. var appendix = _appendixService.GetAppendixById(appendixId);
  268. if (appendix == null)
  269. return PartialView("~/Views/Appendices/_InvoiceListPartial.cshtml", new AppendixDataModel());
  270. var appendixDataModel = AppendixDataModel.FromAppendix(appendix, false);
  271. return PartialView("~/Views/Appendices/_InvoiceListPartial.cshtml", appendixDataModel);
  272. }
  273. /// <summary>
  274. /// Partial edit for editing of existing or for new invoice
  275. /// </summary>
  276. /// <param name="id">Id for existing invoice, otherweise -1.</param>
  277. /// <param name="appendixId">Id of corresponding Appendix</param>
  278. public ActionResult EditInvoice(int appendixId, int id = -1)
  279. {
  280. var invoice = _appendixService.GetInvoiceById(id);
  281. var invoiceModel = InvoiceDataModel.FromInvoice(invoice, true);
  282. if (id == -1)
  283. invoiceModel.AppendixId = appendixId;
  284. return PartialView("~/Views/Appendices/_InvoiceEditPartial.cshtml", invoiceModel);
  285. }
  286. /// <summary>
  287. /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
  288. /// </summary>
  289. /// <param name="invoiceModel">Invoice model to be saved.</param>
  290. [HttpPost, ValidateInput(false)]
  291. public ActionResult EditInvoice(InvoiceDataModel invoiceModel)
  292. {
  293. try
  294. {
  295. if (!ModelState.IsValid)
  296. return PartialView("~/Views/Appendices/_InvoiceEditPartial.cshtml", invoiceModel);
  297. if (invoiceModel.Id == -1)
  298. {
  299. var invoice = invoiceModel.ToInvoice();
  300. _appendixService.InsertInvoice(invoice);
  301. _logger.Entity(invoice, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookies());
  302. }
  303. else
  304. {
  305. var invoice = _appendixService.GetInvoiceById(invoiceModel.Id);
  306. invoice.CustomNumber = invoiceModel.CustomNumber.Value;
  307. invoice.Date = invoiceModel.DateTime.Value;
  308. invoice.Value = invoiceModel.Value.Value;
  309. _appendixService.UpdateInvoice(invoice);
  310. _logger.Entity(invoice, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookies());
  311. }
  312. return new JsonResult
  313. {
  314. Data = "success"
  315. };
  316. }
  317. catch (Exception ex)
  318. {
  319. _logger.Error("Fehler bei Speicherung einer Rechnung.", ex, _userHelper.FromCookies());
  320. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  321. }
  322. }
  323. /// <summary>
  324. /// Simple JSON result for deleting a specific invoice
  325. /// </summary>
  326. /// <param name="id">Invoice id.</param>
  327. [HttpPost]
  328. public ActionResult DeleteInvoice(int id)
  329. {
  330. try
  331. {
  332. var invoice = _appendixService.GetInvoiceById(id);
  333. if (invoice != null)
  334. _appendixService.DeleteInvoice(invoice);
  335. _logger.Entity(invoice, Core.Domain.Logging.LogEntityActivity.Delete, _userHelper.FromCookies());
  336. return new JsonResult
  337. {
  338. Data = "success"
  339. };
  340. }
  341. catch (Exception ex)
  342. {
  343. _logger.Error("Fehler bei Löschung einer Rechnung.", ex, _userHelper.FromCookies());
  344. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  345. }
  346. }
  347. #endregion
  348. #region Claims
  349. /// <summary>
  350. /// Basic claim view function
  351. /// </summary>
  352. [FunctionAuthorize(true, "Appendix-Claims")]
  353. public ActionResult ViewClaims()
  354. {
  355. return View("~/Views/Appendices/Claims.cshtml");
  356. }
  357. /// <summary>
  358. /// Get JSON data of specific claim
  359. /// </summary>
  360. /// <param name="claimType">Claim type.</param>
  361. /// <param name="id">Claim id.</param>
  362. public ActionResult GetClaim(string claimType, int id = -1)
  363. {
  364. switch (claimType.ToLower())
  365. {
  366. case "state":
  367. var state = _appendixService.GetStateById(id);
  368. if (state == null)
  369. return new JsonResult { Data = "notFound", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
  370. else
  371. return new JsonResult
  372. {
  373. Data = JsonConvert.SerializeObject(state),
  374. JsonRequestBehavior = JsonRequestBehavior.AllowGet
  375. };
  376. case "category":
  377. var category = _appendixService.GetCategoryById(id);
  378. if (category == null)
  379. return new JsonResult { Data = "notFound", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
  380. else
  381. return new JsonResult
  382. {
  383. Data = JsonConvert.SerializeObject(category),
  384. JsonRequestBehavior = JsonRequestBehavior.AllowGet
  385. };
  386. default:
  387. return new JsonResult { Data = "unknownClaimType", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
  388. }
  389. }
  390. /// <summary>
  391. /// Callback result for claim grid
  392. /// </summary>
  393. /// <param name="claimType">Claim type.</param>
  394. public ActionResult PartialClaims(string claimType)
  395. {
  396. switch (claimType.ToLower())
  397. {
  398. case "state":
  399. return PartialView("~/Views/Appendices/_StateListPartial.cshtml", ViewData["AllStates"]);
  400. case "category":
  401. return PartialView("~/Views/Appendices/_CategoryListPartial.cshtml", ViewData["AllCategories"]);
  402. default:
  403. return new EmptyResult();
  404. }
  405. }
  406. /// <summary>
  407. /// Partial edit for editing of existing or for new claim
  408. /// </summary>
  409. /// <param name="claimType">Claim type.</param>
  410. /// <param name="id">Id for existing claim, otherweise -1.</param>
  411. public ActionResult EditClaim(string claimType = "", int id = -1)
  412. {
  413. switch (claimType.ToLower())
  414. {
  415. case "state":
  416. var state = _appendixService.GetStateById(id);
  417. var stateModel = StateDataModel.FromState(state, true);
  418. return PartialView("~/Views/Appendices/_StateEditPartial.cshtml", stateModel);
  419. case "category":
  420. var category = _appendixService.GetCategoryById(id);
  421. var categoryModel = CategoryDataModel.FromCategory(category, true);
  422. return PartialView("~/Views/Appendices/_CategoryEditPartial.cshtml", categoryModel);
  423. default:
  424. return new EmptyResult();
  425. }
  426. }
  427. /// <summary>
  428. /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
  429. /// </summary>
  430. /// <param name="stateModel">State model to be saved.</param>
  431. [HttpPost, ValidateInput(false)]
  432. public ActionResult EditState(StateDataModel stateModel)
  433. {
  434. try
  435. {
  436. if (!ModelState.IsValid)
  437. return PartialView("~/Views/Appendices/_StateEditPartial.cshtml", stateModel);
  438. var allStates = _appendixService.GetAllStates();
  439. if (stateModel.IsDefault)
  440. {
  441. foreach (var state in allStates)
  442. {
  443. state.IsDefault = false;
  444. _appendixService.UpdateState(state);
  445. }
  446. }
  447. if (stateModel.Id == -1)
  448. {
  449. var claim = stateModel.ToState();
  450. _appendixService.InsertState(claim);
  451. _logger.Entity(claim, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookies());
  452. }
  453. else
  454. {
  455. var state = _appendixService.GetStateById(stateModel.Id);
  456. state.Description = stateModel.Description;
  457. state.HexColor = stateModel.HexColor;
  458. state.IsDefault = stateModel.IsDefault;
  459. _appendixService.UpdateState(state);
  460. _logger.Entity(state, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookies());
  461. }
  462. return new JsonResult
  463. {
  464. Data = "success"
  465. };
  466. }
  467. catch (Exception ex)
  468. {
  469. _logger.Error("Fehler bei Speicherung eines NT-Status.", ex, _userHelper.FromCookies());
  470. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  471. }
  472. }
  473. /// <summary>
  474. /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
  475. /// </summary>
  476. /// <param name="categoryModel">Category model to be saved.</param>
  477. [HttpPost, ValidateInput(false)]
  478. public ActionResult EditCategory(CategoryDataModel categoryModel)
  479. {
  480. try
  481. {
  482. if (!ModelState.IsValid)
  483. return PartialView("~/Views/Appendices/_CategoryEditPartial.cshtml", categoryModel);
  484. if (categoryModel.Id == -1)
  485. {
  486. var claim = categoryModel.ToCategory();
  487. _appendixService.InsertCategory(claim);
  488. _logger.Entity(claim, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookies());
  489. }
  490. else
  491. {
  492. var category = _appendixService.GetCategoryById(categoryModel.Id);
  493. category.Description = categoryModel.Description;
  494. _appendixService.UpdateCategory(category);
  495. _logger.Entity(category, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookies());
  496. }
  497. return new JsonResult
  498. {
  499. Data = "success"
  500. };
  501. }
  502. catch (Exception ex)
  503. {
  504. _logger.Error("Fehler bei Löschung einer NT-Kategorie.", ex, _userHelper.FromCookies());
  505. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  506. }
  507. }
  508. /// <summary>
  509. /// Simple JSON result for deleting a specific claim
  510. /// </summary>
  511. /// <param name="claimType">Claim type.</param>
  512. /// <param name="id">Claim id.</param>
  513. /// <param name="replaceId">Id of claim which deviations get in place of deleting claim.</param>
  514. [HttpPost]
  515. public ActionResult DeleteClaim(string claimType, int id, int replaceId)
  516. {
  517. switch (claimType.ToLower())
  518. {
  519. case "state":
  520. try
  521. {
  522. var state = _appendixService.GetStateById(id);
  523. var replaceState = _appendixService.GetStateById(replaceId);
  524. var stateAppendices = _appendixService.GetAppendicesByState(id);
  525. foreach (var appendix in stateAppendices)
  526. {
  527. appendix.StateId = replaceId;
  528. appendix.State = replaceState;
  529. _appendixService.UpdateAppendix(appendix);
  530. }
  531. if (state != null)
  532. _appendixService.DeleteState(state);
  533. _logger.Entity(state, Core.Domain.Logging.LogEntityActivity.Delete, _userHelper.FromCookies());
  534. }
  535. catch (Exception ex)
  536. {
  537. _logger.Error("Fehler bei Löschung eines NT-Status.", ex, _userHelper.FromCookies());
  538. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  539. }
  540. break;
  541. case "category":
  542. try
  543. {
  544. var category = _appendixService.GetCategoryById(id);
  545. var replaceCategory = _appendixService.GetCategoryById(replaceId);
  546. var allAppendices = _appendixService.GetAllAppendices();
  547. foreach (var appendix in allAppendices)
  548. {
  549. foreach (var categoryValue in appendix.CategoryValues)
  550. {
  551. if (categoryValue.CategoryId == id)
  552. {
  553. categoryValue.Category = replaceCategory;
  554. categoryValue.CategoryId = replaceCategory.Id;
  555. }
  556. }
  557. _appendixService.UpdateAppendix(appendix);
  558. }
  559. if (category != null)
  560. _appendixService.DeleteCategory(category);
  561. _logger.Entity(category, Core.Domain.Logging.LogEntityActivity.Delete, _userHelper.FromCookies());
  562. }
  563. catch (Exception ex)
  564. {
  565. _logger.Error("Fehler bei Löschung einer NT-Kategorie.", ex, _userHelper.FromCookies());
  566. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  567. }
  568. break;
  569. default:
  570. return new EmptyResult();
  571. }
  572. return new JsonResult
  573. {
  574. Data = "success"
  575. };
  576. }
  577. #endregion
  578. }
  579. }