//Add Data From Linked Tables for Display public void EditItemForDisplay(ReasonCodeAlternativeDescription reasonCodeAlternativeDescription) { //Add LanguageName if (reasonCodeAlternativeDescription.LanguageCode != null) { LanguageRepository languageRepository = new LanguageRepository(); Language language = new Language(); language = languageRepository.GetLanguage(reasonCodeAlternativeDescription.LanguageCode); if (language != null) { reasonCodeAlternativeDescription.LanguageName = language.LanguageName; } } //Add PolicyGroupName ReasonCodeItemRepository reasonCodeItemRepository = new ReasonCodeItemRepository(); ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(reasonCodeAlternativeDescription.ReasonCodeItemId); if (reasonCodeItem != null) { reasonCodeItemRepository.EditItemForDisplay(reasonCodeItem); reasonCodeAlternativeDescription.ReasonCodeItemDisplayOrder = reasonCodeItem.DisplayOrder; } }
// GET: /Create public ActionResult Create(int id) { //Check Parent Exists ReasonCodeGroup reasonCodeGroup = new ReasonCodeGroup(); reasonCodeGroup = reasonCodeGroupRepository.GetGroup(id); //Check Exists if (reasonCodeGroup == null) { ViewData["ActionMethod"] = "CreatePost"; return(View("RecordDoesNotExistError")); } //Check Access RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReasonCodeGroup(id)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } ReasonCodeProductTypeRepository reasonCodeProductTypeRepository = new ReasonCodeProductTypeRepository(); SelectList reasonCodeList = new SelectList(reasonCodeProductTypeRepository.GetAllReasonCodeProductTypes().ToList(), "ReasonCodeValue", "ReasonCodeValue"); ViewData["ReasonCodes"] = reasonCodeList; ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem.ReasonCodeGroupName = reasonCodeGroup.ReasonCodeGroupName; reasonCodeItem.ReasonCodeGroupId = id; reasonCodeItem.TravelerFacingFlag = true; return(View(reasonCodeItem)); }
public ActionResult Delete(int id) { //Get Item ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(id); //Check Exists if (reasonCodeItem == null) { ViewData["ActionMethod"] = "DeleteGet"; return(View("RecordDoesNotExistError")); } //Check AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReasonCodeGroup(reasonCodeItem.ReasonCodeGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Parent Information reasonCodeItemRepository.EditItemForDisplay(reasonCodeItem); ViewData["ReasonCodeItem"] = reasonCodeItem.ReasonCode + "/" + reasonCodeItem.ReasonCodeTypeDescription + "/" + reasonCodeItem.ProductName; ViewData["ReasonCodeItemId"] = reasonCodeItem.ReasonCodeItemId; ViewData["ReasonCodeGroupId"] = reasonCodeItem.ReasonCodeGroupId; ViewData["ReasonCodeGroupName"] = reasonCodeGroupRepository.GetGroup(reasonCodeItem.ReasonCodeGroupId).ReasonCodeGroupName; reasonCodeItemRepository.EditItemForDisplay(reasonCodeItem); return(View(reasonCodeItem)); }
//GET: View public ActionResult View(int id, string languageCode) { //Get Item ReasonCodeAlternativeDescription reasonCodeAlternativeDescription = new ReasonCodeAlternativeDescription(); reasonCodeAlternativeDescription = reasonCodeAlternativeDescriptionRepository.GetItem(id, languageCode); //Check Exists if (reasonCodeAlternativeDescription == null) { ViewData["ActionMethod"] = "ViewGet"; return(View("RecordDoesNotExistError")); } //Parent Information ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(id); reasonCodeItemRepository.EditItemForDisplay(reasonCodeItem); ViewData["ReasonCodeItem"] = reasonCodeItem.ReasonCode + "/" + reasonCodeItem.ReasonCodeTypeDescription + "/" + reasonCodeItem.ProductName; ViewData["ReasonCodeItemId"] = reasonCodeItem.ReasonCodeItemId; ViewData["ReasonCodeGroupId"] = reasonCodeItem.ReasonCodeGroupId; ViewData["ReasonCodeGroupName"] = reasonCodeGroupRepository.GetGroup(reasonCodeItem.ReasonCodeGroupId).ReasonCodeGroupName; ViewData["ReasonCodeDescription"] = reasonCodeItem.ReasonCodeDescription; reasonCodeAlternativeDescriptionRepository.EditItemForDisplay(reasonCodeAlternativeDescription); return(View(reasonCodeAlternativeDescription)); }
public ActionResult List(string reasonCode, int productId, int reasonCodeTypeId, int?page, string sortField, int?sortOrder) { //Get ReasonCodeProductType ReasonCodeProductType reasonCodeProductType = new ReasonCodeProductType(); reasonCodeProductType = reasonCodeProductTypeRepository.GetReasonCodeProductType(reasonCode, productId, reasonCodeTypeId); //Check Exists if (reasonCodeProductType == null) { ViewData["ActionMethod"] = "ListGet"; return(View("RecordDoesNotExistError")); } //Set Access Rights ViewData["Access"] = "WriteAccess"; //Parent Information ViewData["ReasonCode"] = reasonCode; ViewData["ReasonCodeTypeId"] = reasonCodeTypeId; ViewData["ProductId"] = productId; ProductRepository productRepository = new ProductRepository(); Product product = new Product(); product = productRepository.GetProduct(productId); ReasonCodeTypeRepository reasonCodeTypeRepository = new ReasonCodeTypeRepository(); ReasonCodeType reasonCodeType = new ReasonCodeType(); reasonCodeType = reasonCodeTypeRepository.GetItem(reasonCodeTypeId); ReasonCodeItemRepository reasonCodeItemRepository = new ReasonCodeItemRepository(); ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(1); ViewData["ReasonCodeItem"] = reasonCode + "/" + reasonCodeType.ReasonCodeTypeDescription + "/" + product.ProductName; //SortField+SortOrder settings if (sortField != "ReasonCodeProductTypeTravelerDescription") { sortField = "LanguageName"; } if (sortOrder == 1) { ViewData["NewSortOrder"] = 0; ViewData["CurrentSortOrder"] = 1; } else { ViewData["NewSortOrder"] = 1; ViewData["CurrentSortOrder"] = 0; sortOrder = 0; } //Get data var cwtPaginatedList = reasonCodeProductTypeTravelerDescriptionRepository.PageReasonCodeProductTypeTravelerDescriptions(reasonCode, productId, reasonCodeTypeId, page ?? 1, sortField, sortOrder ?? 0); return(View(cwtPaginatedList)); }
//Delete Item public void Delete(ReasonCodeItem reasonCodeItem) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_DeleteReasonCodeItem_v1( reasonCodeItem.ReasonCodeItemId, adminUserGuid, reasonCodeItem.VersionNumber); }
//GET:List public ActionResult List(int id, int?page, string sortField, int?sortOrder) { //Get ReasonCodeItem ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(id); //Check Exists if (reasonCodeItem == null) { ViewData["ActionMethod"] = "ListGet"; return(View("RecordDoesNotExistError")); } //Set Access Rights ViewData["Access"] = ""; RolesRepository rolesRepository = new RolesRepository(); if (rolesRepository.HasWriteAccessToReasonCodeGroup(reasonCodeItem.ReasonCodeGroupId)) { ViewData["Access"] = "WriteAccess"; } //Parent Information reasonCodeItemRepository.EditItemForDisplay(reasonCodeItem); ViewData["ReasonCodeItem"] = reasonCodeItem.ReasonCode + "/" + reasonCodeItem.ReasonCodeTypeDescription + "/" + reasonCodeItem.ProductName; ViewData["ReasonCodeItemId"] = reasonCodeItem.ReasonCodeItemId; ViewData["ReasonCodeGroupId"] = reasonCodeItem.ReasonCodeGroupId; ViewData["ReasonCodeGroupName"] = reasonCodeGroupRepository.GetGroup(reasonCodeItem.ReasonCodeGroupId).ReasonCodeGroupName; ViewData["DisplayOrder"] = reasonCodeItem.DisplayOrder; //SortField+SortOrder settings if (sortField != "ReasonCodeAlternativeDescription") { sortField = "LanguageName"; } ViewData["CurrentSortField"] = sortField; if (sortOrder == 1) { ViewData["NewSortOrder"] = 0; ViewData["CurrentSortOrder"] = 1; } else { ViewData["NewSortOrder"] = 1; ViewData["CurrentSortOrder"] = 0; } //Get data var paginatedView = reasonCodeAlternativeDescriptionRepository.GetAlternativeDescriptions(id, page ?? 1, sortField, sortOrder ?? 0); //Return View return(View(paginatedView)); }
public ActionResult Create(ReasonCodeItem reasonCodeItem) { //Get ReasonCodeGroup ReasonCodeGroup reasonCodeGroup = new ReasonCodeGroup(); reasonCodeGroup = reasonCodeGroupRepository.GetGroup(reasonCodeItem.ReasonCodeGroupId); //Check Exists if (reasonCodeGroup == null) { ViewData["ActionMethod"] = "CreatePost"; return(View("RecordDoesNotExistError")); } //Check Access RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReasonCodeGroup(reasonCodeItem.ReasonCodeGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } try { UpdateModel(reasonCodeItem); } catch { string n = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { n += error.ErrorMessage; } } ViewData["Message"] = "ValidationError : " + n; return(View("Error")); } //Database Update try { reasonCodeItemRepository.Add(reasonCodeItem); } catch (SqlException ex) { LogRepository logRepository = new LogRepository(); logRepository.LogError(ex.Message); ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } return(RedirectToAction("List", new { id = reasonCodeItem.ReasonCodeGroupId })); }
// GET: /Create public ActionResult Create(string reasonCode, int productId, int reasonCodeTypeId) { //Get Item ReasonCodeProductType reasonCodeProductType = new ReasonCodeProductType(); reasonCodeProductType = reasonCodeProductTypeRepository.GetReasonCodeProductType(reasonCode, productId, reasonCodeTypeId); //Check Exists if (reasonCodeProductType == null) { ViewData["ActionMethod"] = "CreateGet"; return(View("RecordDoesNotExistError")); } //ReasonCodeProductTypeTravelerDescription ReasonCodeProductTypeTravelerDescriptionRepository reasonCodeProductTypeTravelerDescriptionRepository = new ReasonCodeProductTypeTravelerDescriptionRepository(); ReasonCodeProductTypeTravelerDescription reasonCodeProductTypeTravelerDescription = new ReasonCodeProductTypeTravelerDescription(); //ReasonCodeProductTypeTravelerDescription Label ReasonCodeProductTypeTravelerDescription reasonCodeProductTypeTravelerDescriptionLabel = new ReasonCodeProductTypeTravelerDescription(); reasonCodeProductTypeTravelerDescriptionLabel = reasonCodeProductTypeTravelerDescriptionRepository.GetItem("en-GB", reasonCode, productId, reasonCodeTypeId); ViewData["ReasonCodeProductTypeDescription"] = (reasonCodeProductTypeTravelerDescriptionLabel != null) ? reasonCodeProductTypeTravelerDescriptionLabel.ReasonCodeProductTypeTravelerDescription1 : String.Empty; //ProductRepository ProductRepository productRepository = new ProductRepository(); Product product = new Product(); product = productRepository.GetProduct(productId); //ReasonCodeType ReasonCodeTypeRepository reasonCodeTypeRepository = new ReasonCodeTypeRepository(); ReasonCodeType reasonCodeType = new ReasonCodeType(); reasonCodeType = reasonCodeTypeRepository.GetItem(reasonCodeTypeId); //ReasonCodeItem ReasonCodeItemRepository reasonCodeItemRepository = new ReasonCodeItemRepository(); ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(1); ViewData["ReasonCodeItem"] = reasonCode + "/" + reasonCodeType.ReasonCodeTypeDescription + "/" + product.ProductName; //Language SelectList SelectList languageList = new SelectList(reasonCodeProductTypeTravelerDescriptionRepository.GetUnUsedLanguages(reasonCode, productId, reasonCodeTypeId).ToList(), "LanguageCode", "LanguageName"); ViewData["Languages"] = languageList; //Show Create Form return(View(reasonCodeProductTypeTravelerDescription)); }
//Add Item public void Add(ReasonCodeItem reasonCodeItem) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_InsertReasonCodeItem_v1( reasonCodeItem.ReasonCodeGroupId, reasonCodeItem.ReasonCode, reasonCodeItem.ProductId, reasonCodeItem.ReasonCodeTypeId, reasonCodeItem.TravelerFacingFlag, adminUserGuid ); }
// GET: /Edit public ActionResult Edit(int id) { //Get Item ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(id); //Check Exists if (reasonCodeItem == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } //Check AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReasonCodeGroup(reasonCodeItem.ReasonCodeGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } ReasonCodeProductTypeRepository reasonCodeProductTypeRepository = new ReasonCodeProductTypeRepository(); SelectList reasonCodeList = new SelectList(reasonCodeProductTypeRepository.GetAllReasonCodeProductTypes().ToList(), "ReasonCodeValue", "ReasonCodeValue"); ViewData["ReasonCodes"] = reasonCodeList; SelectList productList = new SelectList(reasonCodeProductTypeRepository.LookUpReasonCodeProducts(reasonCodeItem.ReasonCode).ToList(), "ProductId", "ProductName"); ViewData["Products"] = productList; SelectList reasonCodeTypeList = new SelectList(reasonCodeProductTypeRepository.LookUpAvailableReasonCodeProductReasonCodeTypes( reasonCodeItem.ReasonCodeItemId, reasonCodeItem.ReasonCodeGroupId, reasonCodeItem.ReasonCode, reasonCodeItem.ProductId).ToList(), "ReasonCodeTypeId", "ReasonCodeTypeDescription"); ViewData["ReasonCodeTypes"] = reasonCodeTypeList; //Parent Information reasonCodeItemRepository.EditItemForDisplay(reasonCodeItem); ViewData["ReasonCodeItem"] = reasonCodeItem.ReasonCode + "/" + reasonCodeItem.ReasonCodeTypeDescription + "/" + reasonCodeItem.ProductName; ViewData["ReasonCodeItemId"] = reasonCodeItem.ReasonCodeItemId; ViewData["ReasonCodeGroupId"] = reasonCodeItem.ReasonCodeGroupId; ViewData["ReasonCodeGroupName"] = reasonCodeGroupRepository.GetGroup(reasonCodeItem.ReasonCodeGroupId).ReasonCodeGroupName; reasonCodeItemRepository.EditItemForDisplay(reasonCodeItem); return(View(reasonCodeItem)); }
//Add Item public void Edit(ReasonCodeItem reasonCodeItem) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_UpdateReasonCodeItem_v1( reasonCodeItem.ReasonCodeItemId, reasonCodeItem.ReasonCode, reasonCodeItem.ProductId, reasonCodeItem.ReasonCodeTypeId, reasonCodeItem.TravelerFacingFlag, adminUserGuid, reasonCodeItem.VersionNumber ); }
public ActionResult Delete(int id, string languageCode, FormCollection collection) { //Get Item ReasonCodeAlternativeDescription reasonCodeAlternativeDescription = new ReasonCodeAlternativeDescription(); reasonCodeAlternativeDescription = reasonCodeAlternativeDescriptionRepository.GetItem(id, languageCode); //Check Exists if (reasonCodeAlternativeDescription == null) { ViewData["ActionMethod"] = "DeletePost"; return(View("RecordDoesNotExistError")); } //Check AccessRights ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(id); RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReasonCodeGroup(reasonCodeItem.ReasonCodeGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Delete try { reasonCodeAlternativeDescription.VersionNumber = Int32.Parse(collection["VersionNumber"]); reasonCodeAlternativeDescriptionRepository.Delete(reasonCodeAlternativeDescription); } catch (SqlException ex) { //Versioning Error - go to standard versionError page if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/ReasonCodeAlternativeDescription.mvc/Delete/" + reasonCodeAlternativeDescription.ReasonCodeItemId.ToString() + "/" + reasonCodeAlternativeDescription.LanguageCode; return(View("VersionError")); } LogRepository logRepository = new LogRepository(); logRepository.LogError(ex.Message); ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } //Return return(RedirectToAction("List", new { id = reasonCodeAlternativeDescription.ReasonCodeItemId })); }
// GET: /Create public ActionResult Create(int id) { //Get PolicyAirVendorGroupItem ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(id); //Check Exists if (reasonCodeItem == null) { ViewData["ActionMethod"] = "CreateGet"; return(View("RecordDoesNotExistError")); } //AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReasonCodeGroup(reasonCodeItem.ReasonCodeGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //New ReasonCodeAlternativeDescription ReasonCodeAlternativeDescription reasonCodeAlternativeDescription = new ReasonCodeAlternativeDescription(); reasonCodeAlternativeDescription.ReasonCodeItemId = id; //Language SelectList SelectList languageList = new SelectList(reasonCodeAlternativeDescriptionRepository.GetUnUsedLanguages(id).ToList(), "LanguageCode", "LanguageName"); ViewData["Languages"] = languageList; //ParentInformation reasonCodeItemRepository.EditItemForDisplay(reasonCodeItem); ViewData["ReasonCodeItem"] = reasonCodeItem.ReasonCode + "/" + reasonCodeItem.ReasonCodeTypeDescription + "/" + reasonCodeItem.ProductName; ViewData["ReasonCodeItemId"] = reasonCodeItem.ReasonCodeItemId; ViewData["ReasonCodeGroupId"] = reasonCodeItem.ReasonCodeGroupId; ViewData["ReasonCodeGroupName"] = reasonCodeGroupRepository.GetGroup(reasonCodeItem.ReasonCodeGroupId).ReasonCodeGroupName; ViewData["ReasonCodeDescription"] = reasonCodeItem.ReasonCodeDescription; //Show Create Form reasonCodeAlternativeDescriptionRepository.EditItemForDisplay(reasonCodeAlternativeDescription); return(View(reasonCodeAlternativeDescription)); }
//Add Data From Linked Tables for Display public void EditItemForDisplay(ReasonCodeTravelerDescription reasonCodeTravelerDescription) { //Add LanguageName if (reasonCodeTravelerDescription.LanguageCode != null) { LanguageRepository languageRepository = new LanguageRepository(); Language language = new Language(); language = languageRepository.GetLanguage(reasonCodeTravelerDescription.LanguageCode); if (language != null) { reasonCodeTravelerDescription.LanguageName = language.LanguageName; } } //Add PolicyGroupName ReasonCodeItemRepository reasonCodeItemRepository = new ReasonCodeItemRepository(); ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(reasonCodeTravelerDescription.ReasonCodeItemId); if (reasonCodeItem != null) { reasonCodeItemRepository.EditItemForDisplay(reasonCodeItem); reasonCodeTravelerDescription.ReasonCodeItemDisplayOrder = reasonCodeItem.DisplayOrder; //ReasonCodeProductTypeTravelerDescription ReasonCodeProductTypeTravelerDescriptionRepository reasonCodeProductTypeTravelerDescriptionRepository = new ReasonCodeProductTypeTravelerDescriptionRepository(); ReasonCodeProductTypeTravelerDescription reasonCodeProductTypeTravelerDescription = new ReasonCodeProductTypeTravelerDescription(); reasonCodeProductTypeTravelerDescription = reasonCodeProductTypeTravelerDescriptionRepository.GetItem( "en-GB", reasonCodeItem.ReasonCode, reasonCodeItem.ProductId, reasonCodeItem.ReasonCodeTypeId ); if (reasonCodeProductTypeTravelerDescription != null) { reasonCodeTravelerDescription.ReasonCodeProductTypeTravelerDescription = reasonCodeProductTypeTravelerDescription; } else { reasonCodeTravelerDescription.ReasonCodeProductTypeTravelerDescription = new ReasonCodeProductTypeTravelerDescription(); } } }
// GET: /Edit public ActionResult Edit(int id, string languageCode) { //Get Item ReasonCodeTravelerDescription reasonCodeTravelerDescription = new ReasonCodeTravelerDescription(); reasonCodeTravelerDescription = reasonCodeTravelerDescriptionRepository.GetItem(id, languageCode); //Check Exists if (reasonCodeTravelerDescription == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } //Check AccessRights ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(id); RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReasonCodeGroup(reasonCodeItem.ReasonCodeGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Language SelectList SelectList languageList = new SelectList(reasonCodeTravelerDescriptionRepository.GetUnUsedLanguages(id).ToList(), "LanguageCode", "LanguageName"); ViewData["Languages"] = languageList; //Parent Information reasonCodeItemRepository.EditItemForDisplay(reasonCodeItem); ViewData["ReasonCodeItem"] = reasonCodeItem.ReasonCode + "/" + reasonCodeItem.ReasonCodeTypeDescription + "/" + reasonCodeItem.ProductName; ViewData["ReasonCodeItemId"] = reasonCodeItem.ReasonCodeItemId; ViewData["ReasonCodeGroupId"] = reasonCodeItem.ReasonCodeGroupId; ViewData["ReasonCodeGroupName"] = reasonCodeGroupRepository.GetGroup(reasonCodeItem.ReasonCodeGroupId).ReasonCodeGroupName; reasonCodeTravelerDescriptionRepository.EditItemForDisplay(reasonCodeTravelerDescription); return(View(reasonCodeTravelerDescription)); }
//Add Data From Linked Tables for Display public void EditItemForDisplay(ReasonCodeItem reasonCodeItem) { ProductRepository productRepository = new ProductRepository(); Product product = new Product(); product = productRepository.GetProduct(reasonCodeItem.ProductId); if (product != null) { reasonCodeItem.ProductName = product.ProductName; } ReasonCodeTypeRepository reasonCodeTypeRepository = new ReasonCodeTypeRepository(); ReasonCodeType reasonCodeType = new ReasonCodeType(); reasonCodeType = reasonCodeTypeRepository.GetItem(reasonCodeItem.ReasonCodeTypeId); if (reasonCodeType != null) { reasonCodeItem.ReasonCodeTypeDescription = reasonCodeType.ReasonCodeTypeDescription; } ReasonCodeProductTypeDescriptionRepository reasonCodeProductTypeDescriptionRepository = new ReasonCodeProductTypeDescriptionRepository(); ReasonCodeProductTypeDescription reasonCodeProductTypeDescription = new ReasonCodeProductTypeDescription(); reasonCodeProductTypeDescription = reasonCodeProductTypeDescriptionRepository.GetItem( "en-GB", reasonCodeItem.ReasonCode, reasonCodeItem.ProductId, reasonCodeItem.ReasonCodeTypeId ); reasonCodeItem.ReasonCodeDescription = (reasonCodeProductTypeDescription != null) ? reasonCodeProductTypeDescription.ReasonCodeProductTypeDescription1 : String.Empty; ReasonCodeGroupRepository reasonCodeGroupRepository = new ReasonCodeGroupRepository(); ReasonCodeGroup reasonCodeGroup = new ReasonCodeGroup(); reasonCodeGroup = reasonCodeGroupRepository.GetGroup(reasonCodeItem.ReasonCodeGroupId); if (reasonCodeGroup != null) { reasonCodeItem.ReasonCodeGroupName = reasonCodeGroup.ReasonCodeGroupName; } }
// GET: /Edit public ActionResult Edit(string reasonCode, int productId, int reasonCodeTypeId, string languageCode) { //Get Item ReasonCodeProductTypeDescription reasonCodeProductTypeDescription = new ReasonCodeProductTypeDescription(); reasonCodeProductTypeDescription = reasonCodeProductTypeDescriptionRepository.GetItem(languageCode, reasonCode, productId, reasonCodeTypeId); //Check Exists if (reasonCodeProductTypeDescription == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } ProductRepository productRepository = new ProductRepository(); Product product = new Product(); product = productRepository.GetProduct(productId); ReasonCodeTypeRepository reasonCodeTypeRepository = new ReasonCodeTypeRepository(); ReasonCodeType reasonCodeType = new ReasonCodeType(); reasonCodeType = reasonCodeTypeRepository.GetItem(reasonCodeTypeId); ReasonCodeItemRepository reasonCodeItemRepository = new ReasonCodeItemRepository(); ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(1); ViewData["ReasonCodeItem"] = reasonCode + "/" + reasonCodeType.ReasonCodeTypeDescription + "/" + product.ProductName; //Language SelectList SelectList languageList = new SelectList(reasonCodeProductTypeDescriptionRepository.GetUnUsedLanguages(reasonCode, productId, reasonCodeTypeId).ToList(), "LanguageCode", "LanguageName"); ViewData["Languages"] = languageList; reasonCodeProductTypeDescriptionRepository.EditItemForDisplay(reasonCodeProductTypeDescription); return(View(reasonCodeProductTypeDescription)); }
public ActionResult Edit(int id, FormCollection collection) { //Get Item ReasonCodeItem reasonCodeItem = new ReasonCodeItem(); reasonCodeItem = reasonCodeItemRepository.GetItem(id); //Check Exists if (reasonCodeItem == null) { ViewData["ActionMethod"] = "EditPost"; return(View("RecordDoesNotExistError")); } //Check AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReasonCodeGroup(reasonCodeItem.ReasonCodeGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } try { UpdateModel(reasonCodeItem); } catch { string n = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { n += error.ErrorMessage; } } ViewData["Message"] = "ValidationError : " + n; return(View("Error")); } //Database Update try { reasonCodeItemRepository.Edit(reasonCodeItem); } catch (SqlException ex) { //Versioning Error if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/ReasonCodeItem.mvc/Edit/" + reasonCodeItem.ReasonCodeItemId.ToString(); return(View("VersionError")); } LogRepository logRepository = new LogRepository(); logRepository.LogError(ex.Message); ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } return(RedirectToAction("List", new { id = reasonCodeItem.ReasonCodeGroupId })); }