Exemplo n.º 1
0
        public ActionResult Delete(int id)
        {
            //Get Item From Database
            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(id);

            //Check Exists
            if (policyOtherGroupHeader == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                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"));
            }

            PolicyOtherGroupHeaderVM policyOtherGroupHeaderVM = new PolicyOtherGroupHeaderVM();

            policyOtherGroupHeaderVM.PolicyOtherGroupHeader = policyOtherGroupHeader;

            //Service Types
            PolicyOtherGroupHeaderServiceTypeRepository policyOtherGroupHeaderServiceTypeRepository = new PolicyOtherGroupHeaderServiceTypeRepository();
            SelectList policyOtherGroupHeaderServiceTypes = new SelectList(
                policyOtherGroupHeaderServiceTypeRepository.GetAllPolicyOtherGroupHeaderServiceTypes().ToList(),
                "PolicyOtherGroupHeaderServiceTypeId",
                "PolicyOtherGroupHeaderServiceTypeDescription",
                policyOtherGroupHeader.PolicyOtherGroupHeaderServiceTypeId
                );

            policyOtherGroupHeaderVM.PolicyOtherGroupHeaderServiceTypes = policyOtherGroupHeaderServiceTypes;

            //Languages
            LanguageRepository languageRepository = new LanguageRepository();
            SelectList         languages          = new SelectList(languageRepository.GetAllLanguages().ToList(), "LanguageCode", "LanguageName", "en-gb");

            policyOtherGroupHeaderVM.Languages = languages;

            //Products
            ProductRepository productRepository = new ProductRepository();
            SelectList        products          = new SelectList(productRepository.GetPolicyOtherGroupHeaderProducts().ToList(), "ProductId", "ProductName", policyOtherGroupHeader.ProductId);

            policyOtherGroupHeaderVM.Products = products;

            //Sub Products
            SubProductRepository subProductRepository = new SubProductRepository();
            SelectList           subProducts          = new SelectList(subProductRepository.GetPolicyOtherGroupHeaderSubProducts().ToList(), "SubProductId", "SubProductName", policyOtherGroupHeader.SubProductId);

            policyOtherGroupHeaderVM.SubProducts = subProducts;

            return(View(policyOtherGroupHeaderVM));
        }
Exemplo n.º 2
0
        public ActionResult Delete(PolicyOtherGroupHeaderVM policyOtherGroupHeaderVM)
        {
            //Check Valid Item passed in Form
            if (policyOtherGroupHeaderVM.PolicyOtherGroupHeader == null)
            {
                ViewData["ActionMethod"] = "DeletePost";
                return(View("RecordDoesNotExistError"));
            }

            //Get Item From Database
            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(policyOtherGroupHeaderVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId);

            //Check Exists
            if (policyOtherGroupHeader == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                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 Form Item
            try
            {
                policyOtherGroupHeaderRepository.Delete(policyOtherGroupHeaderVM.PolicyOtherGroupHeader);
            }
            catch (SqlException ex)
            {
                //Versioning Error - go to standard versionError page
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PolicyOtherGroupHeader.mvc/Delete/" + policyOtherGroupHeaderVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId;
                    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"));
        }
Exemplo n.º 3
0
        //
        // GET: /PolicyOtherGroupHeader/Create
        public ActionResult Create()
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            PolicyOtherGroupHeaderVM policyOtherGroupHeaderVM = new PolicyOtherGroupHeaderVM();

            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeaderVM.PolicyOtherGroupHeader = policyOtherGroupHeader;

            //Service Types
            PolicyOtherGroupHeaderServiceTypeRepository policyOtherGroupHeaderServiceTypeRepository = new PolicyOtherGroupHeaderServiceTypeRepository();
            SelectList policyOtherGroupHeaderServiceTypes = new SelectList(
                policyOtherGroupHeaderServiceTypeRepository.GetAllPolicyOtherGroupHeaderServiceTypes().ToList(),
                "PolicyOtherGroupHeaderServiceTypeId",
                "PolicyOtherGroupHeaderServiceTypeDescription"
                );

            policyOtherGroupHeaderVM.PolicyOtherGroupHeaderServiceTypes = policyOtherGroupHeaderServiceTypes;

            //Languages
            LanguageRepository languageRepository = new LanguageRepository();
            SelectList         languages          = new SelectList(languageRepository.GetAllLanguages().ToList(), "LanguageCode", "LanguageName", "en-gb");

            policyOtherGroupHeaderVM.Languages = languages;

            //Products
            ProductRepository productRepository = new ProductRepository();
            SelectList        products          = new SelectList(productRepository.GetPolicyOtherGroupHeaderProducts().ToList(), "ProductId", "ProductName");

            policyOtherGroupHeaderVM.Products = products;

            //Sub Products
            SubProductRepository subProductRepository = new SubProductRepository();
            SelectList           subProducts          = new SelectList(subProductRepository.GetPolicyOtherGroupHeaderSubProducts().ToList(), "SubProductId", "SubProductName");

            policyOtherGroupHeaderVM.SubProducts = subProducts;

            return(View(policyOtherGroupHeaderVM));
        }
Exemplo n.º 4
0
        public ActionResult Edit(PolicyOtherGroupHeaderVM policyOtherGroupHeaderVM, FormCollection formCollection)
        {
            //Get Item
            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(policyOtherGroupHeaderVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId);

            //Check Exists
            if (policyOtherGroupHeader == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                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"));
            }

            //Remove Table Name if no longer valid
            if (formCollection["PolicyOtherGroupHeader_TableName"] == null)
            {
                policyOtherGroupHeader.TableName = null;
            }

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel <PolicyOtherGroupHeader>(policyOtherGroupHeader, "PolicyOtherGroupHeader");
            }
            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
            {
                policyOtherGroupHeaderRepository.Edit(policyOtherGroupHeader);
            }
            catch (SqlException ex)
            {
                //Non-Unique Name
                if (ex.Message == "NonUniqueName")
                {
                    return(View("NonUniqueNameError"));
                }
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PolicyOtherGroupHeader.mvc/Edit/" + policyOtherGroupHeader.PolicyOtherGroupHeaderId;
                    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"));
        }
Exemplo n.º 5
0
        public ActionResult Create(PolicyOtherGroupHeaderVM policyOtherGroupHeaderVM, FormCollection formCollection)
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //We need to extract group from groupVM
            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeader = policyOtherGroupHeaderVM.PolicyOtherGroupHeader;
            if (policyOtherGroupHeader == null)
            {
                ViewData["Message"] = "ValidationError : missing item";;
                return(View("Error"));
            }

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel <PolicyOtherGroupHeader>(policyOtherGroupHeader, "PolicyOtherGroupHeader");
            }
            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
            {
                policyOtherGroupHeaderRepository.Add(policyOtherGroupHeader);
            }
            catch (SqlException ex)
            {
                //Non-Unique Name
                if (ex.Message == "NonUniqueName")
                {
                    return(View("NonUniqueNameError"));
                }

                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"));
            }

            ViewData["NewSortOrder"] = 0;
            return(RedirectToAction("List"));
        }