AppendixController.cs 26 KB

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