Esempio n. 1
0
        public ActionResult ImportStep2(PolicyCityImportStep1VM preImportCheckResultVM)
        {
            if (preImportCheckResultVM.ImportStep2VM.IsValidData == false)
            {
                //Check JSON for valid messages
                if (preImportCheckResultVM.ImportStep2VM.ReturnMessages[0] != null)
                {
                    List <string> returnMessages = new List <string>();

                    var settings = new JsonSerializerSettings
                    {
                        StringEscapeHandling = StringEscapeHandling.EscapeHtml,
                    };

                    List <string> returnMessagesJSON = JsonConvert.DeserializeObject <List <string> >(preImportCheckResultVM.ImportStep2VM.ReturnMessages[0], settings);

                    foreach (string message in returnMessagesJSON)
                    {
                        string validMessage = Regex.Replace(message, @"[^À-ÿ\w\s&:._()\-]", "");

                        if (!string.IsNullOrEmpty(validMessage))
                        {
                            returnMessages.Add(validMessage);
                        }
                    }

                    preImportCheckResultVM.ImportStep2VM.ReturnMessages = returnMessages;
                }

                TempData["ErrorMessages"] = preImportCheckResultVM;
                return(RedirectToAction("ExportErrors"));
            }

            //PreImport Check Results (check has passed)
            PolicyCityImportStep2VM preImportCheckResult = new PolicyCityImportStep2VM();

            preImportCheckResult = preImportCheckResultVM.ImportStep2VM;

            //Do the Import, return results
            PolicyCityImportStep3VM cdrPostImportResult = new PolicyCityImportStep3VM();

            cdrPostImportResult = policyCityGroupItemRepository.Import(
                preImportCheckResult.FileBytes,
                preImportCheckResultVM.PolicyGroupId
                );

            cdrPostImportResult.PolicyGroupId = preImportCheckResultVM.PolicyGroupId;
            TempData["CdrPostImportResult"]   = cdrPostImportResult;

            //Pass Results to Next Page
            return(RedirectToAction("ImportStep3"));
        }
Esempio n. 2
0
        public ActionResult ImportStep3()
        {
            //Display Results of Import
            PolicyCityImportStep3VM cdrPostImportResult = new PolicyCityImportStep3VM();

            cdrPostImportResult = (PolicyCityImportStep3VM)TempData["CdrPostImportResult"];

            PolicyGroup policyGroup = new PolicyGroup();

            policyGroup = policyGroupRepository.GetGroup(cdrPostImportResult.PolicyGroupId);
            cdrPostImportResult.PolicyGroup = policyGroup;

            return(View(cdrPostImportResult));
        }
Esempio n. 3
0
        public PolicyCityImportStep3VM Import(byte[] FileBytes, int policyGroupId)
        {
            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
            string fileToText            = fileToText = enc.GetString(FileBytes);

            PolicyCityImportStep3VM cdrPostImportResult = new PolicyCityImportStep3VM();
            List <string>           returnMessages      = new List <string>();

            // Create the xml document container, this will be used to store the data after the checks
            XmlDocument    doc = new XmlDocument();
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

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

            doc.AppendChild(root);

            int i = 0;

            //Split the CSV into lines
            string[] lines = fileToText.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            //loop through CSV lines
            foreach (string line in lines)
            {
                i++;

                if (i > 1) //ignore first line with titles
                {
                    string[] cells = line.Split(';');

                    //extract the data items from the file

                    string CityCode            = cells[0]; //Required: (eg.Preferred)
                    string PolicyCityStatusId  = cells[1]; //Required: (eg.DL)
                    string enabledFlag         = cells[2]; //(True / False)(1, 0)
                    string enabledDate         = cells[3]; //(YYYY / MM / DD)
                    string expiryDate          = cells[4]; //(YYYY / MM / DD)
                    string travelDateValidFrom = cells[5]; //(YYYY / MM / DD)
                    string travelDateValidTo   = cells[6]; //(YYYY / MM / DD)

                    //Build the XML Element for items

                    XmlElement xmlPAVItem = doc.CreateElement("PAVIG");



                    XmlElement xmlCityCode = doc.CreateElement("CityCode");
                    xmlCityCode.InnerText = CityCode;
                    xmlPAVItem.AppendChild(xmlCityCode);

                    PolicyCityStatusRepository policyCityStatusRepository = new PolicyCityStatusRepository();
                    PolicyCityStatus           policyCity = policyCityStatusRepository.GetPolicyCityStatusByDescrition(PolicyCityStatusId);
                    int PolicyCityStatusDescriptionId     = policyCity.PolicyCityStatusId;


                    XmlElement xmlPolicyCityStatusId = doc.CreateElement("PolicyCityStatusId");
                    xmlPolicyCityStatusId.InnerText = PolicyCityStatusDescriptionId.ToString();
                    xmlPAVItem.AppendChild(xmlPolicyCityStatusId);

                    XmlElement xmlEnabledDate = doc.CreateElement("EnabledDate");
                    xmlEnabledDate.InnerText = enabledDate;
                    xmlPAVItem.AppendChild(xmlEnabledDate);

                    XmlElement xmlExpiryDate = doc.CreateElement("ExpiryDate");
                    xmlExpiryDate.InnerText = expiryDate;
                    xmlPAVItem.AppendChild(xmlExpiryDate);

                    XmlElement xmlTravelDateValidFrom = doc.CreateElement("TravelDateValidFrom");
                    xmlTravelDateValidFrom.InnerText = travelDateValidFrom;
                    xmlPAVItem.AppendChild(xmlTravelDateValidFrom);

                    XmlElement xmlTravelDateValidTo = doc.CreateElement("TravelDateValidTo");
                    xmlTravelDateValidTo.InnerText = travelDateValidTo;
                    xmlPAVItem.AppendChild(xmlTravelDateValidTo);

                    if (enabledFlag == "TRUE" || string.IsNullOrEmpty(enabledFlag))
                    {
                        enabledFlag = "1";
                    }
                    if (enabledFlag == "FALSE")
                    {
                        enabledFlag = "0";
                    }

                    XmlElement xmlEnabledFlag = doc.CreateElement("EnabledFlag");
                    xmlEnabledFlag.InnerText = enabledFlag;
                    xmlPAVItem.AppendChild(xmlEnabledFlag);
                    //Attach the XML Element for an item to the Document
                    root.AppendChild(xmlPAVItem);
                }
            }

            //DB Check
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            try
            {
                var output = (from n in dbHierarchyDC.spDesktopDataAdmin_UpdatePolicyCityGroupItems_v1(
                                  policyGroupId,
                                  System.Xml.Linq.XElement.Parse(doc.OuterXml),
                                  adminUserGuid)
                              select n).ToList();

                int deletedItemCount = 0;
                int addedItemCount   = 0;

                foreach (spDesktopDataAdmin_UpdatePolicyCityGroupItems_v1Result message in output)
                {
                    returnMessages.Add(message.MessageText.ToString());
                }

                cdrPostImportResult.ReturnMessages   = returnMessages;
                cdrPostImportResult.AddedItemCount   = addedItemCount;
                cdrPostImportResult.DeletedItemCount = deletedItemCount;
            }
            catch (Exception ex)
            {
                returnMessages.Add("<strong class=\"error\">The import of the selected data file has failed Please try again or contact your administrator</strong>");
                cdrPostImportResult.ReturnMessages   = returnMessages;
                cdrPostImportResult.AddedItemCount   = 0;
                cdrPostImportResult.DeletedItemCount = 0;
            }

            return(cdrPostImportResult);
        }