| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037 |
- using DevExpress.Web.Mvc;
- using DevExpress.XtraPrinting;
- using DevExpress.XtraReports.UI;
- using GreenTree.Nachtragsmanagement.Core;
- using GreenTree.Nachtragsmanagement.Core.Authentication;
- using GreenTree.Nachtragsmanagement.Core.Domain.Appendix;
- using GreenTree.Nachtragsmanagement.Services.Appendix;
- using GreenTree.Nachtragsmanagement.Services.Configuration;
- using GreenTree.Nachtragsmanagement.Services.Deviation;
- using GreenTree.Nachtragsmanagement.Services.Logging;
- using GreenTree.Nachtragsmanagement.Services.Site;
- using GreenTree.Nachtragsmanagement.Web.Extensions;
- using GreenTree.Nachtragsmanagement.Web.Framework.Authorization;
- using GreenTree.Nachtragsmanagement.Web.Models.Appendix;
- using GreenTree.Nachtragsmanagement.Web.Models.Deviation;
- using GreenTree.Nachtragsmanagement.Web.Models.Global;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Net.Mime;
- using System.Web;
- using System.Web.Mvc;
- using static GreenTree.Nachtragsmanagement.Web.Extensions.MVCxGridViewGeneratorHelper;
- namespace GreenTree.Nachtragsmanagement.Web.Controllers
- {
- public class AppendixController : Controller
- {
- private readonly IDeviationService _deviationSerivce;
- private readonly IAppendixService _appendixService;
- private readonly ISiteService _siteService;
- private readonly IUserHelper _userHelper;
- private readonly ILogger _logger;
- private readonly IConfigurationService _configurationService;
- public AppendixController(
- IDeviationService deviationService,
- IAppendixService appendixService,
- ISiteService siteService,
- IUserHelper userHelper,
- ILogger logger,
- IConfigurationService configurationService)
- {
- _deviationSerivce = deviationService;
- _appendixService = appendixService;
- _siteService = siteService;
- _userHelper = userHelper;
- _logger = logger;
- _configurationService = configurationService;
- ViewData["AllCategories"] = _appendixService.GetAllCategories();
- ViewData["AllStates"] = _appendixService.GetAllStates();
- }
- #region Appendices
- /// <summary>
- /// Basic appendix view function
- /// </summary>
- [FunctionAuthorize(true, "Appendix-Appendices")]
- public ActionResult ViewAppendices()
- {
- var currentUser = _userHelper.FromCookiesOrSession();
- var appendices = _appendixService.GetAllUserAssignedAppendices(currentUser);
- var appendixModels = appendices
- .Select(u => AppendixDataModel.FromAppendix(u, false))
- .ToList();
- return View("~/Views/Appendices/View.cshtml", appendixModels);
- }
- /// <summary>
- /// Get JSON data of specific appendix
- /// </summary>
- /// <param name="id">Appendix id.</param>
- public ActionResult GetAppendix(int id = -1)
- {
- var appendix = _appendixService.GetAppendixById(id);
- if (appendix == null)
- return new JsonResult
- {
- Data = "notFound",
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- var appendixModel = AppendixDataModel.FromAppendix(appendix, false);
- return new JsonResult
- {
- Data = JsonConvert.SerializeObject(appendixModel),
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- }
- /// <summary>
- /// Callback result for appendix grid
- /// </summary>
- public ActionResult PartialAppendices(int scrollHeight = -1)
- {
- var currentUser = _userHelper.FromCookiesOrSession();
- var appendices = _appendixService.GetAllUserAssignedAppendices(currentUser);
- var appendixModels = appendices
- .Select(u => AppendixDataModel.FromAppendix(u, false))
- .OrderBy(u => u.CustomNumber)
- .ToList();
- ViewData["ScrollHeight"] = scrollHeight;
- return PartialView("~/Views/Appendices/_AppendixGridPartial.cshtml", appendixModels);
- }
- /// <summary>
- /// Export result for appendix grid
- /// </summary>
- [HttpPost]
- public ActionResult ExportPartialAppendices(string displayMode, string exportformat)
- {
- if (String.IsNullOrEmpty(displayMode))
- return new EmptyResult();
- var currentUser = _userHelper.FromCookiesOrSession();
- var appendices = _appendixService.GetAllUserAssignedAppendices(currentUser);
- var appendixModels = appendices
- .Select(u => AppendixDataModel.FromAppendix(u, false))
- .ToList();
- var viewContext = new ViewContext();
- var viewPage = new ViewPage();
- var htmlHelper = new System.Web.Mvc.HtmlHelper(viewContext, viewPage);
- MVCxGridViewState gridViewState = (MVCxGridViewState)Session["AppendixGridViewState"];
- var settings = GridViewSettingsHelper.AppendixGridViewSettings(htmlHelper);
- if (gridViewState != null)
- {
- var generator = new MVCReportGeneratonHelper();
- generator.CustomizeFormattingRules += new CustomizeFormattingRulesEventHandler(generator_CustomizeFormattingRules);
- generator.CustomizeColumnsCollection += new CustomizeColumnsCollectionEventHandler(generator_CustomizeColumnsCollection);
- generator.CustomizeGroupColumnSummary += new CustomizeColumnGroupSummaryEventHandler(generator_CustomizeGroupColumnSummary);
- generator.CustomizeTotalColumnSummary += new CustomizeColumnTotalSummaryEventHandler(generator_CustomizeTotalColumnSummary);
- generator.PageSummaryGetResult += new SummaryGetResultHandler(generator_PageSummaryGetResult);
- generator.TotalSummaryGetResult += new SummaryGetResultHandler(generator_TotalSummaryGetResult);
- var report = generator.GenerateMVCReport(gridViewState, appendixModels, "Nachtragsliste");
- if (displayMode == "popup")
- {
- return PartialView("~/Views/Shared/_PrintPopupPartial.cshtml",
- new PrintGridModel(report, "devGridViewAppendix",
- new { Controller = "Appendix", Action = "ExportPartialAppendices",
- displayMode = "callback", exportformat = String.Empty },
- new { Controller = "Appendix", Action = "ExportPartialAppendices",
- displayMode = "export", exportformat = String.Empty }));
- }
- else if (displayMode == "callback")
- {
- return PartialView("~/Views/Shared/_PrintDocumentViewerPartial.cshtml",
- new PrintGridModel(report, "devGridViewAppendix",
- new { Controller = "Appendix", Action = "ExportPartialAppendices",
- displayMode = "callback", exportformat = String.Empty },
- new { Controller = "Appendix", Action = "ExportPartialAppendices",
- displayMode = "export", exportformat = String.Empty }));
- }
- else if (displayMode == "export")
- {
- switch (exportformat.ToLower())
- {
- case "xlsx":
- settings.TotalSummary["OfferingValue"].DisplayFormat = "{0:c2}";
- settings.TotalSummary["Percentage"].DisplayFormat = "{0:p2}";
- settings.TotalSummary["PercentageValue"].DisplayFormat = "{0:c2}";
- settings.TotalSummary["NegotiationValue"].DisplayFormat = "{0:c2}";
- settings.TotalSummary["RelationOfferingToNegotiation"].DisplayFormat = "{0:p2}";
- settings.TotalSummary["RelationOfferingToDeviations"].DisplayFormat = "{0:n2}";
- settings.TotalSummary["Description"].DisplayFormat = "Anzahl = {0:n0}";
- return GridViewExtension.ExportToXlsx(settings, appendixModels);
- case "xls":
- settings.TotalSummary["OfferingValue"].DisplayFormat = "{0:c2}";
- settings.TotalSummary["Percentage"].DisplayFormat = "{0:p2}";
- settings.TotalSummary["PercentageValue"].DisplayFormat = "{0:c2}";
- settings.TotalSummary["NegotiationValue"].DisplayFormat = "{0:c2}";
- settings.TotalSummary["RelationOfferingToNegotiation"].DisplayFormat = "{0:p2}";
- settings.TotalSummary["RelationOfferingToDeviations"].DisplayFormat = "{0:n2}";
- settings.TotalSummary["Description"].DisplayFormat = "Anzahl = {0:n0}";
- return GridViewExtension.ExportToXls(settings, appendixModels);
- case "pdf":
- report.Name = "Nachtragsliste";
- return DocumentViewerExtension.ExportTo(report);
- }
- }
- return new EmptyResult();
- }
- else
- return new EmptyResult();
- }
- private decimal accumulatedCustomSummaryOfferingValue = 0;
- private decimal accumulatedCustomSummaryPercentage = 0;
- private decimal accumulatedCustomSummaryPercentageValue = 0;
- private decimal accumulatedCustomSummaryNegotiationValue = 0;
- private decimal accumulatedRelationOfferingToNegotiationSum = 0;
- private int accumulatedRelationOfferingToNegotiationCount = 0;
- private decimal accumulatedRelationOfferingToDeviationsSum = 0;
- private int accumulatedRelationOfferingToDeviationsCount = 0;
- private decimal accumulatedCustomSummaryCount = 0;
- /// <summary>
- /// Set custom summary result for page
- /// </summary>
- /// <param name="source"></param>
- /// <param name="e"></param>
- private void generator_PageSummaryGetResult(object source, SummaryGetResultEventArgs e)
- {
- var label = (XRLabel)source;
- if (label.Tag.ToString() == "Description")
- {
- accumulatedCustomSummaryCount += e.CalculatedValues.Count;
- e.Result = accumulatedCustomSummaryCount;
- }
- if (label.Tag.ToString() == "OfferingValue")
- {
- accumulatedCustomSummaryOfferingValue += e.CalculatedValues.OfType<decimal>().Sum();
- e.Result = accumulatedCustomSummaryOfferingValue;
- }
- if (label.Tag.ToString() == "Percentage")
- {
- accumulatedCustomSummaryPercentage += e.CalculatedValues.OfType<decimal>().Sum();
- e.Result = accumulatedCustomSummaryPercentage /
- (accumulatedCustomSummaryCount == 0 ? 1 : accumulatedCustomSummaryCount);
- }
- if (label.Tag.ToString() == "PercentageValue")
- {
- accumulatedCustomSummaryPercentageValue += e.CalculatedValues.OfType<decimal>().Sum();
- e.Result = accumulatedCustomSummaryPercentageValue;
- }
- if (label.Tag.ToString() == "NegotiationValue")
- {
- accumulatedCustomSummaryNegotiationValue += e.CalculatedValues.OfType<decimal>().Sum();
- e.Result = accumulatedCustomSummaryNegotiationValue;
- }
- if (label.Tag.ToString() == "RelationOfferingToNegotiation")
- {
- var nonNull = e.CalculatedValues
- .OfType<decimal?>()
- .Where(d => d.HasValue)
- .ToList();
- accumulatedRelationOfferingToNegotiationSum += nonNull.Sum(d => d.Value);
- accumulatedRelationOfferingToNegotiationCount += nonNull.Count;
- e.Result = accumulatedRelationOfferingToNegotiationSum /
- (accumulatedRelationOfferingToNegotiationCount == 0 ? 1 : accumulatedRelationOfferingToNegotiationCount);
- }
- if (label.Tag.ToString() == "RelationOfferingToDeviations")
- {
- var nonNull = e.CalculatedValues
- .OfType<decimal?>()
- .Where(d => d.HasValue)
- .ToList();
- accumulatedRelationOfferingToDeviationsSum += nonNull.Sum(d => d.Value);
- accumulatedRelationOfferingToDeviationsCount += nonNull.Count;
- e.Result = accumulatedRelationOfferingToDeviationsSum /
- (accumulatedRelationOfferingToDeviationsCount == 0 ? 1 : accumulatedRelationOfferingToDeviationsCount);
- }
- e.Handled = true;
- }
- /// <summary>
- /// Set custom summary result for full report
- /// </summary>
- /// <param name="source"></param>
- /// <param name="e"></param>
- private void generator_TotalSummaryGetResult(object source, SummaryGetResultEventArgs e)
- {
- var label = (XRLabel)source;
- if (label.Tag.ToString() == "PercentageValue")
- {
- e.Result = accumulatedCustomSummaryPercentageValue;
- e.Handled = true;
- }
- if (label.Tag.ToString() == "NegotiationValue")
- {
- e.Result = accumulatedCustomSummaryNegotiationValue;
- e.Handled = true;
- }
- if (label.Tag.ToString() == "RelationOfferingToNegotiation")
- {
- e.Result = accumulatedRelationOfferingToNegotiationSum /
- (accumulatedRelationOfferingToNegotiationCount == 0 ? 1 : accumulatedRelationOfferingToNegotiationCount);
- e.Handled = true;
- }
- if (label.Tag.ToString() == "RelationOfferingToDeviations")
- {
- e.Result = accumulatedRelationOfferingToDeviationsSum /
- (accumulatedRelationOfferingToDeviationsCount == 0 ? 1 : accumulatedRelationOfferingToDeviationsCount);
- e.Handled = true;
- }
- }
- /// <summary>
- /// Customize formatting
- /// </summary>
- /// <param name="source"></param>
- /// <param name="e"></param>
- private void generator_CustomizeFormattingRules(object source, CustomFormattingRulesEventArgs e)
- {
- var allStates = ViewData["AllStates"] as List<State>;
- foreach (var state in allStates)
- {
- var stateBackColor = new FormattingRule
- {
- Condition = String.Format("[StateDescription] == \'{0}\'", state.Description),
- Name = String.Format("StateBackColor-{0}", state.Id)
- };
- stateBackColor.Formatting.BackColor = ColorTranslator.FromHtml(state.HexColor);
- e.Rules.Add(stateBackColor);
- }
- }
- /// <summary>
- /// Customize created columns
- /// </summary>
- private void generator_CustomizeColumnsCollection(object source, ColumnsCreationEventArgs e)
- {
- foreach (var column in e.ColumnsInfo)
- {
- if (column.FieldName == "CustomNumber") { column.ColumnWidth = 30; }
- //if (column.FieldName == "SiteDescription") { column.ColumnWidth = 60; }
- if (column.FieldName == "SiteDescription") { column.IsVisible = false; column.IsDetail = true; }
- if (column.FieldName == "SiteCustomNumber") { column.IsVisible = false; column.IsDetail = true; }
- if (column.FieldName == "UserDescription") { column.IsVisible = false; column.IsDetail = true; }
- if (column.FieldName == "OfferingValue") { column.ColumnWidth = 80; }
- if (column.FieldName == "NegotiationValue") { column.ColumnWidth = 60; }
- if (column.FieldName == "DeviationDescription") { column.ColumnWidth = 40; }
- if (column.FieldName == "RelationOfferingToNegotiation") { column.ColumnWidth = 50; }
- if (column.FieldName == "RelationOfferingToDeviations") { column.ColumnWidth = 50; }
- if (column.FieldName == "StateDescription") { column.ColumnWidth = 70; }
- if (column.FieldName == "CategoryValuesDescription") { column.IsVisible = false; column.IsDetail = true; }
- if (column.FieldName == "OrderNumber") { column.IsVisible = false; column.IsDetail = true; }
- if (column.FieldName == "OrderDate") { column.IsVisible = false; column.IsDetail = true; }
- if (column.FieldName == "OrderInvoiceCreatedDescription") { column.ColumnWidth = 45; }
- if (column.FieldName == "Comment") { column.IsVisible = false; column.IsDetail = true; }
- }
- }
- /// <summary>
- /// Customize column summary
- /// </summary>
- private void generator_CustomizeGroupColumnSummary(object source, ColumnSummaryCreationEventArgs e)
- {
- if (e.FieldName == "OfferingValue") { e.Summary.FormatString = "Angeb. ∑ = {0:c2}"; }
- if (e.FieldName == "Percentage") { e.Summary.FormatString = "Bew. Ø = {0:p2}"; }
- if (e.FieldName == "PercentageValue") { e.Summary.FormatString = "Ang. Bew. ∑ = {0:c2}"; }
- if (e.FieldName == "NegotiationValue") { e.Summary.FormatString = "Verhand. ∑ = {0:c2}"; }
- if (e.FieldName == "RelationOfferingToNegotiation") { e.Summary.FormatString = "Verh. Quo. Ø = {0:p2}"; }
- if (e.FieldName == "RelationOfferingToDeviations") { e.Summary.FormatString = "Fak. Ang. zu VA Ø = {0:n2}"; }
- if (e.FieldName == "Description") { e.Summary.FormatString = "Alle = {0:n0}"; }
- }
- /// <summary>
- /// Customize column summary
- /// </summary>
- private void generator_CustomizeTotalColumnSummary(object source, ColumnSummaryCreationEventArgs e)
- {
- if (e.FieldName == "OfferingValue") { e.Summary.FormatString = "{0:c2}"; }
- if (e.FieldName == "Percentage") { e.Summary.FormatString = "{0:p2}"; }
- if (e.FieldName == "PercentageValue") { e.Summary.FormatString = "{0:c2}"; }
- if (e.FieldName == "NegotiationValue") { e.Summary.FormatString = "{0:c2}"; }
- if (e.FieldName == "RelationOfferingToNegotiation") { e.Summary.FormatString = "{0:p2}"; }
- if (e.FieldName == "RelationOfferingToDeviations") { e.Summary.FormatString = "{0:n2}"; }
- if (e.FieldName == "Description") { e.Summary.FormatString = "Alle = {0:n0}"; }
- }
- /// <summary>
- /// Partial edit for editing of existing or for new appendix
- /// </summary>
- /// <param name="id">Id for existing appendix, otherweise -1.</param>
- public ActionResult EditAppendix(int id = -1)
- {
- var appendix = _appendixService.GetAppendixById(id);
- var appendixModel = AppendixDataModel.FromAppendix(appendix, true);
- var defaultState = _appendixService.GetDefaultState();
- if (defaultState != null)
- ViewData["DefaultState"] = defaultState.Id;
- return PartialView("~/Views/Appendices/_AppendixEditPartial.cshtml", appendixModel);
- }
- /// <summary>
- /// Partial edit for viewing an existing appendix
- /// </summary>
- /// <param name="id">Id for existing appendix, otherweise -1.</param>
- public ActionResult ViewAppendix(int id = -1)
- {
- if (id == -1)
- return new EmptyResult();
- var appendix = _appendixService.GetAppendixById(id);
- var appendixModel = AppendixDataModel.FromAppendix(appendix, true);
- var deviationModels = appendix.Deviations
- .Select(d => DeviationDataModel.FromDeviation(d, false, _configurationService));
- ViewData["AppendixDeviations"] = deviationModels;
- return PartialView("~/Views/Appendices/_AppendixViewPartial.cshtml", appendixModel);
- }
- /// <summary>
- /// Partial edit for creating a new deviation for a site
- /// </summary>
- /// <param name="siteId">Id of the site which the deviation should be appended to.</param>
- public ActionResult AppendAppendixToSite(int siteId)
- {
- var site = _siteService.GetSiteById(siteId);
- var lastCustomNumber = 0;
- if (site.Appendices.Any())
- lastCustomNumber = site.Appendices
- .Max(d => StaticHelper.TryParseInt(d.CustomNumber));
- var appendixModel = new AppendixDataModel
- {
- Id = -1,
- SiteId = siteId,
- CustomNumber = (lastCustomNumber + 1).ToString(),
- Percentage = (decimal)0.5
- };
- var defaultState = _appendixService.GetDefaultState();
- if (defaultState != null)
- ViewData["DefaultState"] = defaultState.Id;
- return PartialView("~/Views/Appendices/_AppendixEditPartial.cshtml", appendixModel);
- }
- /// <summary>
- /// Gets if an appendix OrderInvoiceCreated field and provides an edit form
- /// </summary>
- /// <param name="id">The entity id.</param>
- public ActionResult EditOrderInvoiceCreated(int id)
- {
- var appendix = _appendixService.GetAppendixById(id);
- if (appendix == null)
- return new EmptyResult();
- var model = new OrderInvoiceCreatedDataModel
- {
- AppendixId = appendix.Id,
- OrderInvoiceCreated = appendix.OrderInvoiceCreated
- };
- return PartialView("~/Views/Appendices/_EditOrderInvoiceCreatedPartial.cshtml", model);
- }
- /// <summary>
- /// Sets the OrderInvoiceCreated status for a given appendix
- /// </summary>
- [HttpPost, ValidateInput(false)]
- public ActionResult EditOrderInvoiceCreated(OrderInvoiceCreatedDataModel model)
- {
- if (model == null)
- return new EmptyResult();
- var appendix = _appendixService.GetAppendixById(model.AppendixId);
- if (appendix == null)
- return new EmptyResult();
- appendix.OrderInvoiceCreated = model.OrderInvoiceCreated;
- _appendixService.UpdateAppendix(appendix);
- return new JsonResult
- {
- Data = "success"
- };
- }
- /// <summary>
- /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
- /// </summary>
- /// <param name="appendixModel">Appendix model to be saved.</param>
- [HttpPost, ValidateInput(false)]
- public ActionResult EditAppendix(AppendixDataModel appendixModel)
- {
- try
- {
- appendixModel.CategoryValueEntities =
- appendixModel.CategoryEntities
- .Select(r => JsonConvert.DeserializeObject<CategoryValueDataModel>(r))
- .ToList();
- for (int i = 0; i < appendixModel.CategoryValueEntities.Count; i++)
- appendixModel.CategoryValueEntities.ElementAt(i).Json = appendixModel.CategoryEntities.ElementAt(i);
- appendixModel.PercentageValue = appendixModel.OfferingValue * appendixModel.Percentage;
- if (!ModelState.IsValid)
- return PartialView("~/Views/Appendices/_AppendixEditPartial.cshtml", appendixModel);
- var categoryValues = appendixModel.CategoryValueEntities
- .Select(r => r.ToCategoryValue())
- .ToList();
- if (appendixModel.Id == -1)
- {
- var appendix = appendixModel.ToAppendix();
- appendix.SetCategoryValues(categoryValues);
- _appendixService.InsertAppendix(appendix);
- _logger.Entity(appendix, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookiesOrSession());
- }
- else
- {
- var appendix = _appendixService.GetAppendixById(appendixModel.Id);
- appendix.CustomNumber = appendixModel.CustomNumber;
- appendix.Description = appendixModel.Description;
- appendix.Percentage = appendixModel.Percentage;
- appendix.Value = appendixModel.OfferingValue;
- appendix.OfferingNumber = appendixModel.OfferingNumber;
- appendix.OfferingDate = appendixModel.OfferingDate;
- appendix.NegotiationDate = appendixModel.NegotiationDate;
- appendix.NegotiationValue = appendixModel.NegotiationValue;
- appendix.ProtocolExists = appendixModel.ProtocolExists;
- appendix.StateId = appendixModel.StateId;
- appendix.OrderNumber = appendixModel.OrderNumber;
- appendix.OrderDate = appendixModel.OrderDate;
- appendix.OrderInvoiceCreated = appendixModel.OrderInvoiceCreated;
- appendix.Comment = appendixModel.Comment;
- appendix.SiteId = appendixModel.SiteId;
- appendix.SetCategoryValues(categoryValues);
- _appendixService.UpdateAppendix(appendix);
- _logger.Entity(appendix, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookiesOrSession());
- }
- return new JsonResult
- {
- Data = "success"
- };
- }
- catch (Exception ex)
- {
- _logger.Error("Fehler bei Speicherung eines Nachtrags.", ex, _userHelper.FromCookiesOrSession());
- return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
- }
- }
- /// <summary>
- /// Simple JSON result for deleting a specific appendix
- /// </summary>
- /// <param name="id">Appendix id.</param>
- [HttpPost]
- public ActionResult DeleteAppendix(int id)
- {
- try
- {
- var appendix = _appendixService.GetAppendixById(id);
- if (appendix != null)
- _appendixService.DeleteAppendix(appendix);
- _logger.Entity(appendix, Core.Domain.Logging.LogEntityActivity.Delete, _userHelper.FromCookiesOrSession());
- return new JsonResult
- {
- Data = "success"
- };
- }
- catch (Exception ex)
- {
- _logger.Error("Fehler bei Löschung eines Nachtrags.", ex, _userHelper.FromCookiesOrSession());
- return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
- }
- }
- #endregion
- #region Invoices
- /// <summary>
- /// Get JSON data of specific invoice
- /// </summary>
- /// <param name="id">Invoice id.</param>
- public ActionResult GetInvoice(int id = -1)
- {
- var invoice = _appendixService.GetInvoiceById(id);
- if (invoice == null)
- return new JsonResult
- {
- Data = "notFound",
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- var invoiceModel = InvoiceDataModel.FromInvoice(invoice, false);
- return new JsonResult
- {
- Data = JsonConvert.SerializeObject(invoiceModel),
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- }
- /// <summary>
- /// Callback result for Invoice list
- /// </summary>
- public ActionResult PartialInvoices(int appendixId = -1)
- {
- if (appendixId == -1)
- return PartialView("~/Views/Appendices/_InvoiceListPartial.cshtml", new AppendixDataModel());
- var appendix = _appendixService.GetAppendixById(appendixId);
- if (appendix == null)
- return PartialView("~/Views/Appendices/_InvoiceListPartial.cshtml", new AppendixDataModel());
- var appendixDataModel = AppendixDataModel.FromAppendix(appendix, false);
- return PartialView("~/Views/Appendices/_InvoiceListPartial.cshtml", appendixDataModel);
- }
- /// <summary>
- /// Partial edit for editing of existing or for new invoice
- /// </summary>
- /// <param name="id">Id for existing invoice, otherweise -1.</param>
- /// <param name="appendixId">Id of corresponding Appendix</param>
- public ActionResult EditInvoice(int appendixId, int id = -1)
- {
- var invoice = _appendixService.GetInvoiceById(id);
- var invoiceModel = InvoiceDataModel.FromInvoice(invoice, true);
- if (id == -1)
- invoiceModel.AppendixId = appendixId;
- return PartialView("~/Views/Appendices/_InvoiceEditPartial.cshtml", invoiceModel);
- }
- /// <summary>
- /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
- /// </summary>
- /// <param name="invoiceModel">Invoice model to be saved.</param>
- [HttpPost, ValidateInput(false)]
- public ActionResult EditInvoice(InvoiceDataModel invoiceModel)
- {
- try
- {
- if (!ModelState.IsValid)
- return PartialView("~/Views/Appendices/_InvoiceEditPartial.cshtml", invoiceModel);
- if (invoiceModel.Id == -1)
- {
- var invoice = invoiceModel.ToInvoice();
- _appendixService.InsertInvoice(invoice);
- _logger.Entity(invoice, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookiesOrSession());
- }
- else
- {
- var invoice = _appendixService.GetInvoiceById(invoiceModel.Id);
- invoice.CustomNumber = invoiceModel.CustomNumber.Value;
- invoice.Date = invoiceModel.DateTime.Value;
- invoice.Value = invoiceModel.Value.Value;
- _appendixService.UpdateInvoice(invoice);
- _logger.Entity(invoice, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookiesOrSession());
- }
- return new JsonResult
- {
- Data = "success"
- };
- }
- catch (Exception ex)
- {
- _logger.Error("Fehler bei Speicherung einer Rechnung.", ex, _userHelper.FromCookiesOrSession());
- return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
- }
- }
- /// <summary>
- /// Simple JSON result for deleting a specific invoice
- /// </summary>
- /// <param name="id">Invoice id.</param>
- [HttpPost]
- public ActionResult DeleteInvoice(int id)
- {
- try
- {
- var invoice = _appendixService.GetInvoiceById(id);
- if (invoice != null)
- _appendixService.DeleteInvoice(invoice);
- _logger.Entity(invoice, Core.Domain.Logging.LogEntityActivity.Delete, _userHelper.FromCookiesOrSession());
- return new JsonResult
- {
- Data = "success"
- };
- }
- catch (Exception ex)
- {
- _logger.Error("Fehler bei Löschung einer Rechnung.", ex, _userHelper.FromCookiesOrSession());
- return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
- }
- }
- #endregion
- #region Claims
- /// <summary>
- /// Basic claim view function
- /// </summary>
- [FunctionAuthorize(true, "Appendix-Claims")]
- public ActionResult ViewClaims()
- {
- return View("~/Views/Appendices/Claims.cshtml");
- }
- /// <summary>
- /// Get JSON data of specific claim
- /// </summary>
- /// <param name="claimType">Claim type.</param>
- /// <param name="id">Claim id.</param>
- public ActionResult GetClaim(string claimType, int id = -1)
- {
- switch (claimType.ToLower())
- {
- case "state":
- var state = _appendixService.GetStateById(id);
- if (state == null)
- return new JsonResult { Data = "notFound", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
- else
- return new JsonResult
- {
- Data = JsonConvert.SerializeObject(state),
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- case "category":
- var category = _appendixService.GetCategoryById(id);
- if (category == null)
- return new JsonResult { Data = "notFound", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
- else
- return new JsonResult
- {
- Data = JsonConvert.SerializeObject(category),
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- default:
- return new JsonResult { Data = "unknownClaimType", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
- }
- }
- /// <summary>
- /// Callback result for claim grid
- /// </summary>
- /// <param name="claimType">Claim type.</param>
- public ActionResult PartialClaims(string claimType)
- {
- switch (claimType.ToLower())
- {
- case "state":
- return PartialView("~/Views/Appendices/_StateListPartial.cshtml", ViewData["AllStates"]);
- case "category":
- return PartialView("~/Views/Appendices/_CategoryListPartial.cshtml", ViewData["AllCategories"]);
- default:
- return new EmptyResult();
- }
- }
- /// <summary>
- /// Partial edit for editing of existing or for new claim
- /// </summary>
- /// <param name="claimType">Claim type.</param>
- /// <param name="id">Id for existing claim, otherweise -1.</param>
- public ActionResult EditClaim(string claimType = "", int id = -1)
- {
- switch (claimType.ToLower())
- {
- case "state":
- var state = _appendixService.GetStateById(id);
- var stateModel = StateDataModel.FromState(state, true);
- return PartialView("~/Views/Appendices/_StateEditPartial.cshtml", stateModel);
- case "category":
- var category = _appendixService.GetCategoryById(id);
- var categoryModel = CategoryDataModel.FromCategory(category, true);
- return PartialView("~/Views/Appendices/_CategoryEditPartial.cshtml", categoryModel);
- default:
- return new EmptyResult();
- }
- }
- /// <summary>
- /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
- /// </summary>
- /// <param name="stateModel">State model to be saved.</param>
- [HttpPost, ValidateInput(false)]
- public ActionResult EditState(StateDataModel stateModel)
- {
- try
- {
- if (!ModelState.IsValid)
- return PartialView("~/Views/Appendices/_StateEditPartial.cshtml", stateModel);
- var allStates = _appendixService.GetAllStates();
- if (stateModel.IsDefault)
- {
- foreach (var state in allStates)
- {
- state.IsDefault = false;
- _appendixService.UpdateState(state);
- }
- }
- if (stateModel.IsFinish)
- {
- foreach (var state in allStates)
- {
- state.IsFinish = false;
- _appendixService.UpdateState(state);
- }
- }
- if (stateModel.Id == -1)
- {
- var claim = stateModel.ToState();
- _appendixService.InsertState(claim);
- _logger.Entity(claim, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookiesOrSession());
- }
- else
- {
- var state = _appendixService.GetStateById(stateModel.Id);
- state.Description = stateModel.Description;
- state.HexColor = stateModel.HexColor;
- state.IsZeroValue = stateModel.IsZeroValue;
- state.IsDefault = stateModel.IsDefault;
- state.IsFinish = stateModel.IsFinish;
- state.InitialPercentage = stateModel.InitialPercentage;
- _appendixService.UpdateState(state);
- _logger.Entity(state, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookiesOrSession());
- }
- return new JsonResult
- {
- Data = "success"
- };
- }
- catch (Exception ex)
- {
- _logger.Error("Fehler bei Speicherung eines NT-Status.", ex, _userHelper.FromCookiesOrSession());
- return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
- }
- }
- /// <summary>
- /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
- /// </summary>
- /// <param name="categoryModel">Category model to be saved.</param>
- [HttpPost, ValidateInput(false)]
- public ActionResult EditCategory(CategoryDataModel categoryModel)
- {
- try
- {
- if (!ModelState.IsValid)
- return PartialView("~/Views/Appendices/_CategoryEditPartial.cshtml", categoryModel);
- if (categoryModel.Id == -1)
- {
- var claim = categoryModel.ToCategory();
- _appendixService.InsertCategory(claim);
- _logger.Entity(claim, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookiesOrSession());
- }
- else
- {
- var category = _appendixService.GetCategoryById(categoryModel.Id);
- category.Description = categoryModel.Description;
- _appendixService.UpdateCategory(category);
- _logger.Entity(category, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookiesOrSession());
- }
- return new JsonResult
- {
- Data = "success"
- };
- }
- catch (Exception ex)
- {
- _logger.Error("Fehler bei Löschung einer NT-Kategorie.", ex, _userHelper.FromCookiesOrSession());
- return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
- }
- }
- /// <summary>
- /// Simple JSON result for deleting a specific claim
- /// </summary>
- /// <param name="claimType">Claim type.</param>
- /// <param name="id">Claim id.</param>
- /// <param name="replaceId">Id of claim which deviations get in place of deleting claim.</param>
- [HttpPost]
- public ActionResult DeleteClaim(string claimType, int id, int replaceId)
- {
- switch (claimType.ToLower())
- {
- case "state":
- try
- {
- var state = _appendixService.GetStateById(id);
- var replaceState = _appendixService.GetStateById(replaceId);
- var stateAppendices = _appendixService.GetAppendicesByState(id);
- foreach (var appendix in stateAppendices)
- {
- appendix.StateId = replaceId;
- appendix.State = replaceState;
- _appendixService.UpdateAppendix(appendix);
- }
- if (state != null)
- _appendixService.DeleteState(state);
- _logger.Entity(state, Core.Domain.Logging.LogEntityActivity.Delete, _userHelper.FromCookiesOrSession());
- }
- catch (Exception ex)
- {
- _logger.Error("Fehler bei Löschung eines NT-Status.", ex, _userHelper.FromCookiesOrSession());
- return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
- }
- break;
- case "category":
- try
- {
- var category = _appendixService.GetCategoryById(id);
- var replaceCategory = _appendixService.GetCategoryById(replaceId);
- var allAppendices = _appendixService.GetAllAppendices();
- foreach (var appendix in allAppendices)
- {
- foreach (var categoryValue in appendix.CategoryValues)
- {
- if (categoryValue.CategoryId == id)
- {
- categoryValue.Category = replaceCategory;
- categoryValue.CategoryId = replaceCategory.Id;
- }
- }
- _appendixService.UpdateAppendix(appendix);
- }
- if (category != null)
- _appendixService.DeleteCategory(category);
- _logger.Entity(category, Core.Domain.Logging.LogEntityActivity.Delete, _userHelper.FromCookiesOrSession());
- }
- catch (Exception ex)
- {
- _logger.Error("Fehler bei Löschung einer NT-Kategorie.", ex, _userHelper.FromCookiesOrSession());
- return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
- }
- break;
- default:
- return new EmptyResult();
- }
- return new JsonResult
- {
- Data = "success"
- };
- }
- #endregion
- }
- }
|