//Add Data From Linked Tables for Display public void EditForDisplay(TravelPort travelPort) { CountryRepository countryRepository = new CountryRepository(); Country country = new Country(); country = countryRepository.GetCountry(travelPort.CountryCode); if (country != null) { travelPort.CountryName = country.CountryName; } CityRepository cityRepository = new CityRepository(); City city = new City(); city = cityRepository.GetCity(travelPort.CityCode); if (city != null) { travelPort.CityName = city.Name; } TravelPortTypeRepository travelPortTypeRepository = new TravelPortTypeRepository(); TravelPortType travelPortType = new TravelPortType(); travelPortType = travelPortTypeRepository.GetTravelPortType(travelPort.TravelPortTypeId); if (travelPortType != null) { travelPort.TravelPortTypeDescription = travelPortType.TravelPortTypeDescription; } travelPort.LatitudeDecimal = Convert.ToDecimal(travelPort.Latitude); travelPort.LongitudeDecimal = Convert.ToDecimal(travelPort.Longitude); }
public ActionResult Create() { //Create Item TravelPort travelPort = new TravelPort(); //AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //StateProvince SelectList SelectList stateProvinceList = new SelectList(stateProvinceRepository.GetStateProvincesByCountryCode(travelPort.CountryCode).ToList(), "StateProvinceCode", "Name"); ViewData["StateProvinceList"] = stateProvinceList; //TravelPort SelectList SelectList travelPortTypeList = new SelectList(travelPortTypeRepository.GetAllTravelPortTypes().ToList(), "TravelPortTypeId", "TravelPortTypeDescription"); ViewData["TravelPortTypeList"] = travelPortTypeList; return(View(travelPort)); }
//Add Data From Linked Tables for Display public void EditForDisplay(TravelPortLanguage travelPortLanguage) { //Add TravelPortTypeDescription TravelPortTypeRepository travelPortTypeRepository = new TravelPortTypeRepository(); TravelPortType travelPortType = new TravelPortType(); travelPortType = travelPortTypeRepository.GetTravelPortType(travelPortLanguage.TravelPortTypeId); if (travelPortType != null) { travelPortLanguage.TravelPortTypeDescription = travelPortType.TravelPortTypeDescription; } //Add LanguageName if (travelPortLanguage.LanguageCode != null) { LanguageRepository languageRepository = new LanguageRepository(); Language language = new Language(); language = languageRepository.GetLanguage(travelPortLanguage.LanguageCode); if (language != null) { travelPortLanguage.LanguageName = language.LanguageName; } } //Add TravelPortCodeTravelPortName (name of original) TravelPortRepository travelPortRepository = new TravelPortRepository(); TravelPort travelPort = new TravelPort(); travelPort = travelPortRepository.GetTravelPort(travelPortLanguage.TravelPortCode); if (travelPort != null) { travelPortLanguage.TravelPortCodeTravelPortName = travelPort.TravelportName; } }
public ActionResult Delete(string id) { TravelPortVM travelPortVM = new TravelPortVM(); travelPortVM.AllowDelete = true; TravelPort travelPort = new TravelPort(); travelPort = travelPortRepository.GetTravelPort(id); //Check Exists if (travelPort == null) { ViewData["ActionMethod"] = "ViewGet"; return(View("RecordDoesNotExistError")); } travelPortVM.TravelPort = travelPort; //Attached Items List <TravelPortReference> travelPortReferences = travelPortRepository.GetTravelPortReferences(travelPort.TravelPortCode); if (travelPortReferences.Count > 0) { travelPortVM.AllowDelete = false; travelPortVM.TravelPortReferences = travelPortReferences; } travelPortRepository.EditForDisplay(travelPort); return(View(travelPortVM)); }
//Delete in DB public void Delete(TravelPort travelPort) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_DeleteTravelPort_v1( travelPort.TravelPortCode, adminUserGuid, travelPort.VersionNumber ); }
// GET: /List public ActionResult List(string id, int?page, string sortField, int?sortOrder) { //Check Exists TravelPort travelPort = new TravelPort(); travelPort = travelPortRepository.GetTravelPort(id); if (travelPort == null) { ViewData["ActionMethod"] = "ListGet"; return(View("RecordDoesNotExistError")); } //Set Access Rights HierarchyRepository hierarchyRepository = new HierarchyRepository(); ViewData["Access"] = ""; if (hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Access"] = "WriteAccess"; } //SortField if (sortField != "TravelPortTypeDescription" && sortField != "LanguageName" && sortField != "TravelPortCode") { sortField = "TravelPortName"; } ViewData["CurrentSortField"] = sortField; //SortOrder if (sortOrder == 1) { ViewData["NewSortOrder"] = 0; ViewData["CurrentSortOrder"] = 1; } else { ViewData["NewSortOrder"] = 1; ViewData["CurrentSortOrder"] = 0; } //Parent Information ViewData["TravelPortCode"] = travelPort.TravelPortCode; ViewData["TravelPortName"] = travelPort.TravelportName; //return items var cwtPaginatedList = travelPortLanguageRepository.PageTravelPortTranslations(id, page ?? 1, sortField, sortOrder ?? 0); return(View(cwtPaginatedList)); }
// GET: /View public ActionResult ViewItem(string id) { //Check Exists TravelPort travelPort = new TravelPort(); travelPort = travelPortRepository.GetTravelPort(id); if (travelPort == null) { ViewData["ActionMethod"] = "ViewGet"; return(View("RecordDoesNotExistError")); } travelPortRepository.EditForDisplay(travelPort); return(View(travelPort)); }
//Add to DB public void Add(TravelPort travelPort) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_InsertTravelPort_v1( travelPort.TravelPortCode, travelPort.TravelportName, travelPort.TravelPortTypeId, travelPort.CityCode, travelPort.MetropolitanArea, travelPort.CountryCode, travelPort.StateProvinceCode, Convert.ToDouble(travelPort.LatitudeDecimal), Convert.ToDouble(travelPort.LongitudeDecimal), adminUserGuid ); }
public JsonResult IsValidTravelPortCode(string travelPortCode) { TravelPort travelport = new TravelPort(); travelport = validationRepository.IsValidTravelPortCode(travelPortCode); if (travelport == null) { return(Json(null)); } else { return(Json(new { travelport = new[] { new Dictionary <string, object> { { "TravelPortCode", travelport.TravelPortCode } } } })); } }
// GET: /Create public ActionResult Create(string id) { //Get Parent TravelPort travelPort = new TravelPort(); travelPort = travelPortRepository.GetTravelPort(id); //Check Exists if (travelPort == null) { ViewData["ActionMethod"] = "CreateGet"; return(View("RecordDoesNotExistError")); } //AccessRights HierarchyRepository hierarchyRepository = new HierarchyRepository(); if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //New TravelPortLanguage TravelPortLanguage travelPortLanguage = new TravelPortLanguage(); travelPortLanguage.TravelPortCode = id; travelPortLanguageRepository.EditForDisplay(travelPortLanguage); //Populate List of Languages LanguageRepository languageRepository = new LanguageRepository(); SelectList languages = new SelectList(languageRepository.GetAllLanguages().ToList(), "LanguageCode", "LanguageName"); ViewData["LanguageList"] = languages; //Populate List of Languages TravelPortTypeRepository travelPortTypeRepository = new TravelPortTypeRepository(); SelectList travelPortTypes = new SelectList(travelPortTypeRepository.GetAllTravelPortTypes().ToList(), "TravelPortTypeId", "TravelPortTypeDescription"); ViewData["TravelPortTypeList"] = travelPortTypes; //Show Create Form return(View(travelPortLanguage)); }
public ActionResult Edit(TravelPort travelPort) { //Check Access Rights to Domain if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Update Model from Form try { UpdateModel(travelPort); } 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 { travelPortRepository.Update(travelPort); } 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")); }
public ActionResult Delete(TravelPortVM travelPortVM) { //Get Item TravelPort travelPort = new TravelPort(); travelPort = travelPortRepository.GetTravelPort(travelPortVM.TravelPort.TravelPortCode); //Check Exists if (travelPortVM.TravelPort == null) { ViewData["ActionMethod"] = "DeletePost"; return(View("RecordDoesNotExistError")); } //Check Access Rights to Domain if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Delete Item try { travelPortRepository.Delete(travelPort); } catch (SqlException ex) { //Versioning Error - go to standard versionError page if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/TravelPort.mvc/Delete/" + travelPort.TravelPortCode; return(View("VersionError")); } //Generic Error 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")); }
// GET: /Edit public ActionResult Edit(string id) { //Get Item TravelPort travelPort = new TravelPort(); travelPort = travelPortRepository.GetTravelPort(id); //Check Exists if (travelPort == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } //AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } travelPortRepository.EditForDisplay(travelPort); //StateProvince SelectList SelectList stateProvinceList = new SelectList(stateProvinceRepository.GetStateProvincesByCountryCode(travelPort.CountryCode).ToList(), "StateProvinceCode", "Name", travelPort.StateProvinceCode); ViewData["StateProvinceList"] = stateProvinceList; //TravelPort SelectList SelectList travelPortTypeList = new SelectList(travelPortTypeRepository.GetAllTravelPortTypes().ToList(), "TravelPortTypeId", "TravelPortTypeDescription", travelPort.TravelPortTypeId); ViewData["TravelPortTypeList"] = travelPortTypeList; return(View(travelPort)); }
//Add Data From Linked Tables for Display public void EditForDisplay(PolicyLocation policyLocation) { if (policyLocation.TravelPortCode != null) { TravelPortRepository travelPortRepository = new TravelPortRepository(); TravelPort travelPort = new TravelPort(); travelPort = travelPortRepository.GetTravelPort(policyLocation.TravelPortCode); if (travelPort != null) { policyLocation.TravelPortName = travelPort.TravelportName; policyLocation.LocationCode = travelPort.TravelPortCode; policyLocation.LocationName = travelPort.TravelportName; } } if (policyLocation.TravelPortTypeId != null) { int travelPortTypeId = (int)policyLocation.TravelPortTypeId; TravelPortTypeRepository travelPortTypeRepository = new TravelPortTypeRepository(); TravelPortType travelPortType = new TravelPortType(); travelPortType = travelPortTypeRepository.GetTravelPortType(travelPortTypeId); if (travelPortType != null) { policyLocation.TravelPortType = travelPortType.TravelPortTypeDescription; } } HierarchyRepository hierarchyRepository = new HierarchyRepository(); string globalRegionCode = policyLocation.GlobalRegionCode; if (globalRegionCode != null) { GlobalRegion globalRegion = new GlobalRegion(); globalRegion = hierarchyRepository.GetGlobalRegion(globalRegionCode); policyLocation.LocationCode = globalRegion.GlobalRegionCode; policyLocation.LocationName = globalRegion.GlobalRegionName; } string globalSubRegionCode = policyLocation.GlobalSubRegionCode; if (globalSubRegionCode != null) { GlobalSubRegion globalSubRegion = new GlobalSubRegion(); globalSubRegion = hierarchyRepository.GetGlobalSubRegion(globalSubRegionCode); policyLocation.LocationCode = globalSubRegion.GlobalSubRegionCode; policyLocation.LocationName = globalSubRegion.GlobalSubRegionName; } string countryCode = policyLocation.CountryCode; if (countryCode != null) { Country country = new Country(); country = hierarchyRepository.GetCountry(countryCode); policyLocation.LocationCode = country.CountryCode; policyLocation.LocationName = country.CountryName; } string cityCode = policyLocation.CityCode; if (cityCode != null) { CityRepository cityRepository = new CityRepository(); City city = new City(); city = cityRepository.GetCity(cityCode); policyLocation.LocationCode = city.CityCode; policyLocation.LocationName = city.Name; } if (policyLocation.GlobalFlag) { policyLocation.LocationName = "Global"; policyLocation.LocationCode = "Global"; } }