AppendixController.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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.IsFinish)
  448. {
  449. foreach (var state in allStates)
  450. {
  451. state.IsFinish = false;
  452. _appendixService.UpdateState(state);
  453. }
  454. }
  455. if (stateModel.Id == -1)
  456. {
  457. var claim = stateModel.ToState();
  458. _appendixService.InsertState(claim);
  459. _logger.Entity(claim, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookies());
  460. }
  461. else
  462. {
  463. var state = _appendixService.GetStateById(stateModel.Id);
  464. state.Description = stateModel.Description;
  465. state.HexColor = stateModel.HexColor;
  466. state.IsDefault = stateModel.IsDefault;
  467. state.IsFinish = stateModel.IsFinish;
  468. _appendixService.UpdateState(state);
  469. _logger.Entity(state, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookies());
  470. }
  471. return new JsonResult
  472. {
  473. Data = "success"
  474. };
  475. }
  476. catch (Exception ex)
  477. {
  478. _logger.Error("Fehler bei Speicherung eines NT-Status.", ex, _userHelper.FromCookies());
  479. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  480. }
  481. }
  482. /// <summary>
  483. /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
  484. /// </summary>
  485. /// <param name="categoryModel">Category model to be saved.</param>
  486. [HttpPost, ValidateInput(false)]
  487. public ActionResult EditCategory(CategoryDataModel categoryModel)
  488. {
  489. try
  490. {
  491. if (!ModelState.IsValid)
  492. return PartialView("~/Views/Appendices/_CategoryEditPartial.cshtml", categoryModel);
  493. if (categoryModel.Id == -1)
  494. {
  495. var claim = categoryModel.ToCategory();
  496. _appendixService.InsertCategory(claim);
  497. _logger.Entity(claim, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookies());
  498. }
  499. else
  500. {
  501. var category = _appendixService.GetCategoryById(categoryModel.Id);
  502. category.Description = categoryModel.Description;
  503. _appendixService.UpdateCategory(category);
  504. _logger.Entity(category, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookies());
  505. }
  506. return new JsonResult
  507. {
  508. Data = "success"
  509. };
  510. }
  511. catch (Exception ex)
  512. {
  513. _logger.Error("Fehler bei Löschung einer NT-Kategorie.", ex, _userHelper.FromCookies());
  514. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  515. }
  516. }
  517. /// <summary>
  518. /// Simple JSON result for deleting a specific claim
  519. /// </summary>
  520. /// <param name="claimType">Claim type.</param>
  521. /// <param name="id">Claim id.</param>
  522. /// <param name="replaceId">Id of claim which deviations get in place of deleting claim.</param>
  523. [HttpPost]
  524. public ActionResult DeleteClaim(string claimType, int id, int replaceId)
  525. {
  526. switch (claimType.ToLower())
  527. {
  528. case "state":
  529. try
  530. {
  531. var state = _appendixService.GetStateById(id);
  532. var replaceState = _appendixService.GetStateById(replaceId);
  533. var stateAppendices = _appendixService.GetAppendicesByState(id);
  534. foreach (var appendix in stateAppendices)
  535. {
  536. appendix.StateId = replaceId;
  537. appendix.State = replaceState;
  538. _appendixService.UpdateAppendix(appendix);
  539. }
  540. if (state != null)
  541. _appendixService.DeleteState(state);
  542. _logger.Entity(state, Core.Domain.Logging.LogEntityActivity.Delete, _userHelper.FromCookies());
  543. }
  544. catch (Exception ex)
  545. {
  546. _logger.Error("Fehler bei Löschung eines NT-Status.", ex, _userHelper.FromCookies());
  547. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  548. }
  549. break;
  550. case "category":
  551. try
  552. {
  553. var category = _appendixService.GetCategoryById(id);
  554. var replaceCategory = _appendixService.GetCategoryById(replaceId);
  555. var allAppendices = _appendixService.GetAllAppendices();
  556. foreach (var appendix in allAppendices)
  557. {
  558. foreach (var categoryValue in appendix.CategoryValues)
  559. {
  560. if (categoryValue.CategoryId == id)
  561. {
  562. categoryValue.Category = replaceCategory;
  563. categoryValue.CategoryId = replaceCategory.Id;
  564. }
  565. }
  566. _appendixService.UpdateAppendix(appendix);
  567. }
  568. if (category != null)
  569. _appendixService.DeleteCategory(category);
  570. _logger.Entity(category, Core.Domain.Logging.LogEntityActivity.Delete, _userHelper.FromCookies());
  571. }
  572. catch (Exception ex)
  573. {
  574. _logger.Error("Fehler bei Löschung einer NT-Kategorie.", ex, _userHelper.FromCookies());
  575. return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
  576. }
  577. break;
  578. default:
  579. return new EmptyResult();
  580. }
  581. return new JsonResult
  582. {
  583. Data = "success"
  584. };
  585. }
  586. #endregion
  587. }
  588. }