Esempio n. 1
0
        // GET: /EditSequence
        public ActionResult EditSequence(int policyOtherGroupHeaderServiceTypeId, int productId, int subProductId, int?page)
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Check Exists
            if (policyOtherGroupHeaderServiceTypeId <= 0 || productId <= 0)
            {
                ViewData["Message"] = "You have not provided a Product or a PolicyOtherGroupHeaderServiceTypeId";
                return(View("Error"));
            }

            PolicyOtherGroupHeaderSequenceVM policyOtherGroupHeaderSequenceVM = new PolicyOtherGroupHeaderSequenceVM();

            policyOtherGroupHeaderSequenceVM.PolicyOtherGroupHeaderServiceTypeId = policyOtherGroupHeaderServiceTypeId;
            policyOtherGroupHeaderSequenceVM.ProductId    = productId;
            policyOtherGroupHeaderSequenceVM.SubProductId = subProductId;

            //Get Items
            PolicyOtherGroupHeaderRepository policyOtherGroupHeaderRepository = new PolicyOtherGroupHeaderRepository();

            policyOtherGroupHeaderSequenceVM.PolicyOtherGroupHeaderSequences = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeaderSequences(
                policyOtherGroupHeaderSequenceVM.PolicyOtherGroupHeaderServiceTypeId,
                policyOtherGroupHeaderSequenceVM.ProductId,
                policyOtherGroupHeaderSequenceVM.SubProductId,
                page ?? 1
                );

            //Service Types
            PolicyOtherGroupHeaderServiceTypeRepository policyOtherGroupHeaderServiceTypeRepository = new PolicyOtherGroupHeaderServiceTypeRepository();
            PolicyOtherGroupHeaderServiceType           policyOtherGroupHeaderServiceType           = policyOtherGroupHeaderServiceTypeRepository.GetPolicyOtherGroupHeaderServiceType(
                policyOtherGroupHeaderSequenceVM.PolicyOtherGroupHeaderServiceTypeId
                );

            policyOtherGroupHeaderSequenceVM.PolicyOtherGroupHeaderServiceType = policyOtherGroupHeaderServiceType;

            //Products
            ProductRepository productRepository = new ProductRepository();
            Product           product           = productRepository.GetProduct(policyOtherGroupHeaderSequenceVM.ProductId);

            policyOtherGroupHeaderSequenceVM.Product = product;

            //Sub Products
            if (policyOtherGroupHeaderSequenceVM.SubProductId > 0)
            {
                SubProductRepository subProductRepository = new SubProductRepository();
                SubProduct           subProduct           = subProductRepository.GetSubProduct(policyOtherGroupHeaderSequenceVM.SubProductId);
                policyOtherGroupHeaderSequenceVM.SubProduct = subProduct;
            }

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

            return(View(policyOtherGroupHeaderSequenceVM));
        }
Esempio n. 2
0
        public ActionResult EditSequence(int page, FormCollection collection)
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            string[] sequences = collection["Sequence"].Split(new char[] { ',' });

            int sequence = (page - 1 * 5) - 2;

            if (sequence < 0)
            {
                sequence = 1;
            }

            XmlDocument    doc = new XmlDocument();         // Create the XML Declaration, and append it to XML document
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

            doc.AppendChild(dec);
            XmlElement root = doc.CreateElement("SequenceXML");

            doc.AppendChild(root);

            foreach (string s in sequences)
            {
                string[] primaryKey = s.Split(new char[] { '_' });

                int policyOtherGroupHeaderId = Convert.ToInt32(primaryKey[0]);
                int versionNumber            = Convert.ToInt32(primaryKey[1]);

                XmlElement xmlItem = doc.CreateElement("Item");
                root.AppendChild(xmlItem);

                XmlElement xmlSequence = doc.CreateElement("Sequence");
                xmlSequence.InnerText = sequence.ToString();
                xmlItem.AppendChild(xmlSequence);

                XmlElement xmlPolicyOtherGroupHeaderId = doc.CreateElement("PolicyOtherGroupHeaderId");
                xmlPolicyOtherGroupHeaderId.InnerText = policyOtherGroupHeaderId.ToString();
                xmlItem.AppendChild(xmlPolicyOtherGroupHeaderId);

                XmlElement xmlVersionNumber = doc.CreateElement("VersionNumber");
                xmlVersionNumber.InnerText = versionNumber.ToString();
                xmlItem.AppendChild(xmlVersionNumber);

                sequence = sequence + 1;
            }

            try
            {
                PolicyOtherGroupHeaderRepository policyOtherGroupHeaderRepository = new PolicyOtherGroupHeaderRepository();
                policyOtherGroupHeaderRepository.UpdatePolicyOtherGroupHeaderSequences(System.Xml.Linq.XElement.Parse(doc.OuterXml));
            }
            catch (SqlException ex)
            {
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PolicyOtherGroupHeader.mvc/EditSequence?page=" + page + "&id";
                    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"));
        }