// GET: /Edit public ActionResult Edit(int id, string languageCode) { //Get Item PolicyCarTypeGroupItemLanguage policyCarTypeGroupItemLanguage = new PolicyCarTypeGroupItemLanguage(); policyCarTypeGroupItemLanguage = policyCarTypeGroupItemLanguageRepository.GetItem(id, languageCode); //Check Exists if (policyCarTypeGroupItemLanguage == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } //Check AccessRights PolicyCarTypeGroupItem policyCarTypeGroupItem = new PolicyCarTypeGroupItem(); policyCarTypeGroupItem = policyCarTypeGroupItemRepository.GetPolicyCarTypeGroupItem(id); RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToPolicyGroup(policyCarTypeGroupItem.PolicyGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Language SelectList SelectList languageList = new SelectList(policyCarTypeGroupItemLanguageRepository.GetUnUsedLanguages(id).ToList(), "LanguageCode", "LanguageName"); ViewData["Languages"] = languageList; policyCarTypeGroupItemLanguageRepository.EditItemForDisplay(policyCarTypeGroupItemLanguage); return(View(policyCarTypeGroupItemLanguage)); }
public ActionResult Delete(int id, string languageCode) { //Get Item PolicyCarTypeGroupItemLanguage policyCarTypeGroupItemLanguage = new PolicyCarTypeGroupItemLanguage(); policyCarTypeGroupItemLanguage = policyCarTypeGroupItemLanguageRepository.GetItem(id, languageCode); //Check Exists if (policyCarTypeGroupItemLanguage == null) { ViewData["ActionMethod"] = "DeleteGet"; return(View("RecordDoesNotExistError")); } //Check AccessRights PolicyCarTypeGroupItem policyCarTypeGroupItem = new PolicyCarTypeGroupItem(); policyCarTypeGroupItem = policyCarTypeGroupItemRepository.GetPolicyCarTypeGroupItem(id); RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToPolicyGroup(policyCarTypeGroupItem.PolicyGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Add Linked Information policyCarTypeGroupItemLanguageRepository.EditItemForDisplay(policyCarTypeGroupItemLanguage); //Return View return(View(policyCarTypeGroupItemLanguage)); }
//Add Data From Linked Tables for Display public void EditItemForDisplay(PolicyCarTypeGroupItemLanguage policyCarTypeGroupItemLanguage) { //Add LanguageName if (policyCarTypeGroupItemLanguage.LanguageCode != null) { LanguageRepository languageRepository = new LanguageRepository(); Language language = new Language(); language = languageRepository.GetLanguage(policyCarTypeGroupItemLanguage.LanguageCode); if (language != null) { policyCarTypeGroupItemLanguage.LanguageName = language.LanguageName; } } //Add PolicyGroupName PolicyCarTypeGroupItemRepository policyCarTypeGroupItemRepository = new PolicyCarTypeGroupItemRepository(); PolicyCarTypeGroupItem policyCarTypeGroupItem = new PolicyCarTypeGroupItem(); policyCarTypeGroupItem = policyCarTypeGroupItemRepository.GetPolicyCarTypeGroupItem(policyCarTypeGroupItemLanguage.PolicyCarTypeGroupItemId); if (policyCarTypeGroupItem != null) { policyCarTypeGroupItemRepository.EditItemForDisplay(policyCarTypeGroupItem); policyCarTypeGroupItemLanguage.PolicyGroupName = policyCarTypeGroupItem.PolicyGroupName; policyCarTypeGroupItemLanguage.PolicyGroupId = policyCarTypeGroupItem.PolicyGroupId; } }
public ActionResult Create(PolicyCarTypeGroupItemLanguage policyCarTypeGroupItemLanguage) { PolicyCarTypeGroupItem policyCarTypeGroupItem = new PolicyCarTypeGroupItem(); policyCarTypeGroupItem = policyCarTypeGroupItemRepository.GetPolicyCarTypeGroupItem(policyCarTypeGroupItemLanguage.PolicyCarTypeGroupItemId); //Check Exists if (policyCarTypeGroupItem == null) { ViewData["ActionMethod"] = "CreatePost"; return(View("RecordDoesNotExistError")); } RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToPolicyGroup(policyCarTypeGroupItem.PolicyGroupId)) { //AccessRights Error return(View("Error")); } //Update Model from Form try { UpdateModel(policyCarTypeGroupItemLanguage); } 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")); } try { policyCarTypeGroupItemLanguageRepository.Add(policyCarTypeGroupItemLanguage); } 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 = policyCarTypeGroupItem.PolicyCarTypeGroupItemId })); }
//Delete From DB public void Delete(PolicyCarTypeGroupItemLanguage policyCarTypeGroupItemLanguage) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_DeletePolicyCarTypeGroupItemCarTypeAdvice_v1( policyCarTypeGroupItemLanguage.PolicyCarTypeGroupItemId, policyCarTypeGroupItemLanguage.LanguageCode, adminUserGuid, policyCarTypeGroupItemLanguage.VersionNumber ); }
//Add to DB public void Add(PolicyCarTypeGroupItemLanguage policyCarTypeGroupItemLanguage) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_InsertPolicyCarTypeGroupItemCarTypeAdvice_v1( policyCarTypeGroupItemLanguage.PolicyCarTypeGroupItemId, policyCarTypeGroupItemLanguage.LanguageCode, policyCarTypeGroupItemLanguage.CarTypeAdvice, adminUserGuid ); }
//GET: View public ActionResult View(int id, string languageCode) { PolicyCarTypeGroupItemLanguage policyCarTypeGroupItemLanguage = new PolicyCarTypeGroupItemLanguage(); policyCarTypeGroupItemLanguage = policyCarTypeGroupItemLanguageRepository.GetItem(id, languageCode); if (policyCarTypeGroupItemLanguage == null) { ViewData["ActionMethod"] = "ViewGet"; return(View("RecordDoesNotExistError")); } policyCarTypeGroupItemLanguageRepository.EditItemForDisplay(policyCarTypeGroupItemLanguage); return(View(policyCarTypeGroupItemLanguage)); }
public ActionResult Delete(int id, string languageCode, FormCollection collection) { //Get Item PolicyCarTypeGroupItemLanguage policyCarTypeGroupItemLanguage = new PolicyCarTypeGroupItemLanguage(); policyCarTypeGroupItemLanguage = policyCarTypeGroupItemLanguageRepository.GetItem(id, languageCode); //Check Exists if (policyCarTypeGroupItemLanguage == null) { ViewData["ActionMethod"] = "DeletePost"; return(View("RecordDoesNotExistError")); } //Check AccessRights PolicyCarTypeGroupItem policyCarTypeGroupItem = new PolicyCarTypeGroupItem(); policyCarTypeGroupItem = policyCarTypeGroupItemRepository.GetPolicyCarTypeGroupItem(id); RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToPolicyGroup(policyCarTypeGroupItem.PolicyGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Delete Item try { policyCarTypeGroupItemLanguage.VersionNumber = Int32.Parse(collection["VersionNumber"]); policyCarTypeGroupItemLanguageRepository.Delete(policyCarTypeGroupItemLanguage); } catch (SqlException ex) { //Versioning Error - go to standard versionError page if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/CarTypeAdvice.mvc/Delete/" + policyCarTypeGroupItemLanguage.PolicyCarTypeGroupItemId.ToString() + "/" + policyCarTypeGroupItemLanguage.LanguageCode; 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", new { id = policyCarTypeGroupItemLanguage.PolicyCarTypeGroupItemId })); }
public ActionResult Edit(int id, string languageCode, string carAdvice) { //Get Item PolicyCarTypeGroupItemLanguage policyCarTypeGroupItemLanguage = new PolicyCarTypeGroupItemLanguage(); policyCarTypeGroupItemLanguage = policyCarTypeGroupItemLanguageRepository.GetItem(id, languageCode); //Check Exists if (policyCarTypeGroupItemLanguage == null) { ViewData["ActionMethod"] = "EditPost"; return(View("RecordDoesNotExistError")); } //Check AccessRights PolicyCarTypeGroupItem policyCarTypeGroupItem = new PolicyCarTypeGroupItem(); policyCarTypeGroupItem = policyCarTypeGroupItemRepository.GetPolicyCarTypeGroupItem(id); RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToPolicyGroup(policyCarTypeGroupItem.PolicyGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Update Item from Form try { UpdateModel(policyCarTypeGroupItemLanguage); } 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")); } //Update CountryAdvice try { policyCarTypeGroupItemLanguageRepository.Update(policyCarTypeGroupItemLanguage); } catch (SqlException ex) { //Versioning Error if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/CarTypeAdvice.mvc/Edit/" + policyCarTypeGroupItemLanguage.PolicyCarTypeGroupItemId.ToString(); 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(RedirectToAction("List", new { id = policyCarTypeGroupItemLanguage.PolicyCarTypeGroupItemId })); }