public ActionResult Delete(int id, string languageCode)
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            OptionalFieldLanguage optionalFieldLanguage = new OptionalFieldLanguage();

            optionalFieldLanguage = optionalFieldLanguageRepository.GetItem(id, languageCode);

            //Check Exists
            if (optionalFieldLanguage == null)
            {
                ViewData["ActionMethod"] = "ViewGet";
                return(View("RecordDoesNotExistError"));
            }

            OptionalFieldLanguageVM optionalFieldLanguageVM = new OptionalFieldLanguageVM();

            optionalFieldLanguageVM.OptionalFieldLanguage = optionalFieldLanguage;

            // Need the name for breadcrumbs
            OptionalFieldRepository optionalFieldRespository = new OptionalFieldRepository();
            OptionalField           optionalField            = optionalFieldRespository.GetItem(id);

            ViewData["OptionalFieldName"] = optionalField.OptionalFieldName;

            return(View(optionalFieldLanguageVM));
        }
        // GET: Create A Single OptionalFieldLanguage
        public ActionResult Create(int id)
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            OptionalFieldLanguageVM optionalFieldLanguageVM = new OptionalFieldLanguageVM();

            //Need the name for breadcrumbs
            OptionalFieldRepository optionalFieldRespository = new OptionalFieldRepository();
            OptionalField           optionalField            = optionalFieldRespository.GetItem(id);

            if (optionalField != null)
            {
                ViewData["OptionalFieldName"] = optionalField.OptionalFieldName;
            }

            //Set Default Option Size
            OptionalFieldLanguage optionalFieldLanguage = new OptionalFieldLanguage();

            optionalFieldLanguage.OptionalFieldId         = id;
            optionalFieldLanguage.OptionalFieldSize       = 0;
            optionalFieldLanguageVM.OptionalFieldLanguage = optionalFieldLanguage;

            //Languages
            optionalFieldLanguageVM.OptionalFieldLanguages = new SelectList(optionalFieldLanguageRepository.GetAllAvailableLanguages(id), "LanguageCode", "LanguageName");

            return(View(optionalFieldLanguageVM));
        }
        // GET: View A Single OptionalFieldLanguage
        public ActionResult View(int id, string languageCode)
        {
            OptionalFieldLanguage optionalFieldLanguage = optionalFieldLanguageRepository.GetItem(id, languageCode);

            //Check Exists
            if (optionalFieldLanguage == null)
            {
                ViewData["ActionMethod"] = "ViewGet";
                return(View("RecordDoesNotExistError"));
            }

            OptionalFieldLanguageVM optionalFieldLanguageVM = new OptionalFieldLanguageVM();

            optionalFieldLanguageVM.OptionalFieldLanguage = optionalFieldLanguage;

            //Need the name for breadcrumbs
            OptionalFieldRepository optionalFieldRespository = new OptionalFieldRepository();
            OptionalField           optionalField            = optionalFieldRespository.GetItem(id);

            if (optionalField != null)
            {
                ViewData["OptionalFieldName"] = optionalField.OptionalFieldName;
            }

            //Languages
            optionalFieldLanguageVM.OptionalFieldLanguages = new SelectList(optionalFieldLanguageRepository.GetAllAvailableLanguages(id), "LanguageCode", "LanguageName");

            return(View(optionalFieldLanguageVM));
        }
        // GET: View A Single OptionalFieldLookupValue
        public ActionResult View(int id)
        {
            OptionalFieldLookupValue optionalFieldLookupValue = optionalFieldLookupValueRepository.GetItem(id);

            //Check Exists
            if (optionalFieldLookupValue == null)
            {
                ViewData["ActionMethod"] = "ViewGet";
                return(View("RecordDoesNotExistError"));
            }

            OptionalFieldLookupValueVM optionalFieldLookupValueVM = new OptionalFieldLookupValueVM();

            optionalFieldLookupValueVM.OptionalFieldLookupValue = optionalFieldLookupValue;

            //Language
            OptionalFieldLookupValueLanguage optionalFieldLookupValueLanguage = new OptionalFieldLookupValueLanguage();

            optionalFieldLookupValueLanguage = optionalFieldLookupValueLanguageRepository.GetItem(optionalFieldLookupValue.OptionalFieldLookupValueId);
            if (optionalFieldLookupValueLanguage != null)
            {
                optionalFieldLookupValueVM.OptionalFieldLookupValueLanguage = optionalFieldLookupValueLanguage;
            }

            //Need the name for breadcrumbs
            OptionalFieldRepository optionalFieldRespository = new OptionalFieldRepository();
            OptionalField           optionalField            = optionalFieldRespository.GetItem(optionalFieldLookupValue.OptionalFieldId);

            if (optionalField != null)
            {
                ViewData["OptionalFieldName"] = optionalField.OptionalFieldName;
            }

            return(View(optionalFieldLookupValueVM));
        }
        // GET: Edit A Single OptionalFieldLookupValue
        public ActionResult Edit(int id)
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            OptionalFieldLookupValue optionalFieldLookupValue = optionalFieldLookupValueRepository.GetItem(id);

            //Check Exists
            if (optionalFieldLookupValue == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            OptionalFieldLookupValueVM optionalFieldLookupValueVM = new OptionalFieldLookupValueVM();

            //Language
            OptionalFieldLookupValueLanguage optionalFieldLookupValueLanguage = new OptionalFieldLookupValueLanguage();

            optionalFieldLookupValueLanguage = optionalFieldLookupValueLanguageRepository.GetItem(optionalFieldLookupValue.OptionalFieldLookupValueId);
            if (optionalFieldLookupValueLanguage != null)
            {
                optionalFieldLookupValueVM.OptionalFieldLookupValueLanguage = optionalFieldLookupValueLanguage;
            }

            //Get the Languages
            LanguageRepository languageRepository = new LanguageRepository();

            optionalFieldLookupValueVM.OptionalFieldLookupValueLanguages = new SelectList(
                languageRepository.GetAllLanguages().ToList(),
                "LanguageCode",
                "LanguageName",
                optionalFieldLookupValueLanguage.LanguageCode
                );

            //Need the name for breadcrumbs
            OptionalFieldRepository optionalFieldRespository = new OptionalFieldRepository();
            OptionalField           optionalField            = optionalFieldRespository.GetItem(optionalFieldLookupValue.OptionalFieldId);

            if (optionalField != null)
            {
                ViewData["OptionalFieldName"] = optionalField.OptionalFieldName;
            }

            optionalFieldLookupValueVM.OptionalFieldLookupValue = optionalFieldLookupValue;

            return(View(optionalFieldLookupValueVM));
        }
        //GET: A list of OptionalFieldLanguages
        public ActionResult List(int id, string filter, int?page, string sortField, int?sortOrder)
        {
            //Check Access Rights to Domain
            ViewData["Access"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Access"] = "WriteAccess";
            }

            //SortField + SortOrder settings
            if (sortField != "OptionalFieldLabel")
            {
                sortField = "LanguageName";
            }
            ViewData["CurrentSortField"] = sortField;

            if (sortOrder == 1)
            {
                ViewData["NewSortOrder"]     = 0;
                ViewData["CurrentSortOrder"] = 1;
            }
            else
            {
                ViewData["NewSortOrder"]     = 1;
                ViewData["CurrentSortOrder"] = 0;
            }

            OptionalField           optionalField            = new OptionalField();
            OptionalFieldRepository optionalFieldRespository = new OptionalFieldRepository();

            optionalField = optionalFieldRespository.GetItem(id);

            if (optionalField != null)
            {
                ViewData["OptionalFieldId"]   = optionalField.OptionalFieldId;
                ViewData["OptionalFieldName"] = optionalField.OptionalFieldName;
            }

            var items = optionalFieldLanguageRepository.PageOptionalFieldLanguages(id, filter ?? "", page ?? 1, sortField, sortOrder ?? 0);

            return(View(items));
        }
        // GET: /EditSequence
        public ActionResult EditSequence(int groupid, int productId, int?page)
        {
            //Get Group
            OptionalFieldGroup optionalFieldGroup = new OptionalFieldGroup();

            optionalFieldGroup = optionalFieldGroupRepository.GetGroup(groupid);

            //Check Exists
            if (optionalFieldGroup == null)
            {
                ViewData["ActionMethod"] = "ListGet";
                return(View("RecordDoesNotExistError"));
            }

            //Check Access Rights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToOptionalFieldGroup(groupid))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }
            OptionalFieldItemSequenceRepository optionalFieldItemSequenceRepository = new OptionalFieldItemSequenceRepository();
            OptionalFieldRepository             optionalFieldRepository             = new OptionalFieldRepository();

            //Only show products where more than one item is present
            OptionalFieldItemSequencesVM optionalFieldItemSequencesVM = new OptionalFieldItemSequencesVM();

            optionalFieldItemSequencesVM.OptionalFieldItemSequences = optionalFieldItemSequenceRepository.GetOptionalFieldItemSequences(groupid, productId, page ?? 1);
            optionalFieldItemSequencesVM.OptionalFieldGroup         = optionalFieldGroup;
            //optionalFieldItemSequencesVM.OptionalField = optionalFieldRepository.GetItem(id);
            //optionalFieldItemSequencesVM.OptionalFieldId = id;

            ViewData["Page"] = page ?? 1;


            return(View(optionalFieldItemSequencesVM));
        }