| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- using GreenTree.Nachtragsmanagement.Services.Appendix;
- using GreenTree.Nachtragsmanagement.Services.Deviation;
- using GreenTree.Nachtragsmanagement.Web.Framework.Authorization;
- using GreenTree.Nachtragsmanagement.Web.Models.Appendix;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace GreenTree.Nachtragsmanagement.Web.Controllers
- {
- public class AppendixController : Controller
- {
- private readonly IDeviationService _deviationSerivce;
- private readonly IAppendixService _appendixService;
- public AppendixController(
- IDeviationService deviationService,
- IAppendixService appendixService)
- {
- _deviationSerivce = deviationService;
- _appendixService = appendixService;
- ViewData["AllDeviations"] = _deviationSerivce.GetAllDeviations();
- ViewData["AllCategories"] = _appendixService.GetAllCategories();
- }
- #region Appendices
- /// <summary>
- /// Basic appendix view function
- /// </summary>
- [FunctionAuthorize(true, "Appendix-Appendices")]
- public ActionResult ViewAppendices()
- {
- var appendices = _appendixService.GetAllAppendices();
- 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()
- {
- var appendices = _appendixService.GetAllAppendices();
- var appendixModels = appendices
- .Select(u => AppendixDataModel.FromAppendix(u, false))
- .ToList();
- return PartialView("~/Views/Appendices/_AppendixGridPartial.cshtml", appendixModels);
- }
- /// <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);
- return PartialView("~/Views/Appendices/_AppendixEditPartial.cshtml", appendixModel);
- }
- /// <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)
- {
- if (!ModelState.IsValid)
- return PartialView("~/Views/Appendices/_AppendixEditPartial.cshtml", appendixModel);
- if (appendixModel.Id == -1)
- {
- var appendix = appendixModel.ToAppendix();
- _appendixService.InsertAppendix(appendix);
- }
- else
- {
- var appendix = _appendixService.GetAppendixById(appendixModel.Id);
- appendix.CustomNumber = appendixModel.CustomNumber;
- appendix.Description = appendixModel.Description;
- appendix.Probability = appendixModel.Probability;
- appendix.OfferingNumber = appendixModel.OfferingNumber;
- appendix.OfferingDate = appendixModel.OfferingDate;
- appendix.NegotiationDate = appendixModel.NegotiationDate;
- appendix.NegotiationValue = appendixModel.NegotiationValue;
- appendix.ProtocolExists = appendixModel.ProtocolExists;
- appendix.OrderNumber = appendixModel.OrderNumber;
- appendix.OrderDate = appendixModel.OrderDate;
- appendix.Comment = appendixModel.Comment;
- appendix.SiteId = appendixModel.SiteId;
- _appendixService.UpdateAppendix(appendix);
- }
- return new JsonResult
- {
- Data = "success"
- };
- }
- /// <summary>
- /// Simple JSON result for deleting a specific appendix
- /// </summary>
- /// <param name="id">Appendix id.</param>
- [HttpPost]
- public ActionResult DeleteAppendix(int id)
- {
- var appendix = _appendixService.GetAppendixById(id);
- if (appendix != null)
- _appendixService.DeleteAppendix(appendix);
- return new JsonResult
- {
- Data = "success"
- };
- }
- #endregion
- #region Categories
- /// <summary>
- /// Basic category view function
- /// </summary>
- [FunctionAuthorize(true, "Appendix-Categories")]
- public ActionResult ViewCategories()
- {
- var categories = _appendixService.GetAllCategories();
- var categoryModels = categories
- .Select(u => CategoryDataModel.FromCategory(u, false))
- .ToList();
- return View("~/Views/Appendix/Categories.cshtml", categoryModels);
- }
- /// <summary>
- /// Get JSON data of specific category
- /// </summary>
- /// <param name="id">Category id.</param>
- public ActionResult GetCategory(int id = -1)
- {
- var category = _appendixService.GetCategoryById(id);
- if (category == null)
- return new JsonResult
- {
- Data = "notFound",
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- var categoryModel = CategoryDataModel.FromCategory(category, false);
- return new JsonResult
- {
- Data = JsonConvert.SerializeObject(categoryModel),
- JsonRequestBehavior = JsonRequestBehavior.AllowGet
- };
- }
- /// <summary>
- /// Callback result for category grid
- /// </summary>
- public ActionResult PartialCategories()
- {
- var categories = _appendixService.GetAllCategories();
- var categoryModels = categories
- .Select(u => CategoryDataModel.FromCategory(u, false))
- .ToList();
- return PartialView("~/Views/Admin/Categories/_CategoryListPartial.cshtml", categoryModels);
- }
- /// <summary>
- /// Partial edit for editing of existing or for new category
- /// </summary>
- /// <param name="id">Id for existing category, otherweise -1.</param>
- public ActionResult EditCategory(int id = -1)
- {
- var category = _appendixService.GetCategoryById(id);
- var categoryModel = CategoryDataModel.FromCategory(category, true);
- return PartialView("~/Views/Admin/Categories/_CategoryEditPartial.cshtml", categoryModel);
- }
- /// <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)
- {
- if (!ModelState.IsValid)
- return PartialView("~/Views/Deviations/_CategoryEditPartial.cshtml", categoryModel);
- if (categoryModel.Id == -1)
- {
- var claim = categoryModel.ToCategory();
- _appendixService.InsertCategory(claim);
- }
- else
- {
- var disturbance = _appendixService.GetCategoryById(categoryModel.Id);
- disturbance.Description = categoryModel.Description;
- _appendixService.UpdateCategory(disturbance);
- }
- return new JsonResult
- {
- Data = "success"
- };
- }
- /// <summary>
- /// Simple JSON result for deleting a specific category
- /// </summary>
- /// <param name="id">Category id.</param>
- [HttpPost]
- public ActionResult DeleteCategory(int id)
- {
- var category = _appendixService.GetCategoryById(id);
- if (category != null)
- _appendixService.DeleteCategory(category);
- return new JsonResult
- {
- Data = "success"
- };
- }
- #endregion
- }
- }
|