Ejemplo n.º 1
0
 // <summary>
 /// SaveNewClaim to save the claim input in the backing store as xml
 /// Returns: true/false to indicate whether the claim added or not 
 /// </summary>
 private bool SaveNewClaim(MitchellClaimType newClaim)
 {
     // Set xml namespace
     XNamespace cla = "http://www.mitchell.com/examples/claim";
     bool added = true;
     try
     {
         // Load the backing store
         XDocument claimStore = XDocument.Load(strXMLClaimStore);
         // Create a new MitchellClaim xml element
         XElement newClaimXml = new XElement(cla + "MitchellClaim",
                                        new XElement(cla + "ClaimNumber", newClaim.ClaimNumber),
                                        new XElement(cla + "ClaimantFirstName", newClaim.ClaimantFirstName),
                                        new XElement(cla + "ClaimantLastName", newClaim.ClaimantLastName),
                                        new XElement(cla + "Status", newClaim.Status),
                                        new XElement(cla + "LossDate", newClaim.LossDate),
                                        new XElement(cla + "LossInfo",
                                            new XElement(cla + "CauseOfLoss", newClaim.LossInfo.CauseOfLoss),
                                            new XElement(cla + "ReportedDate", newClaim.LossInfo.ReportedDate),
                                            new XElement(cla + "LossDescription", newClaim.LossInfo.LossDescription)),
                                        new XElement(cla + "AssignedAdjusterID", newClaim.AssignedAdjusterID),
                                        new XElement(cla + "Vehicles",
                                            new XElement(cla + "VehicleDetails",
                                                new XElement(cla + "ModelYear", newClaim.Vehicles[0].ModelYear),
                                                new XElement(cla + "MakeDescription", newClaim.Vehicles[0].MakeDescription),
                                                new XElement(cla + "ModelDescription", newClaim.Vehicles[0].ModelDescription),
                                                new XElement(cla + "EngineDescription", newClaim.Vehicles[0].EngineDescription),
                                                new XElement(cla + "ExteriorColor", newClaim.Vehicles[0].ExteriorColor),
                                                new XElement(cla + "Vin", newClaim.Vehicles[0].Vin),
                                                new XElement(cla + "LicPlate", newClaim.Vehicles[0].LicPlate),
                                                new XElement(cla + "LicPlateState", newClaim.Vehicles[0].LicPlateState),
                                                new XElement(cla + "LicPlateExpDate", newClaim.Vehicles[0].LicPlateExpDate),
                                                new XElement(cla + "DamageDescription", newClaim.Vehicles[0].DamageDescription),
                                                new XElement(cla + "Mileage", newClaim.Vehicles[0].Mileage)))
                                    );
         // Add the new MitchellClaim element to the backing store
         claimStore.Element(cla + "Claims").Add(newClaimXml);
         // Save the backing store
         claimStore.Save(strXMLClaimStore);
     }
     catch
     {
         added = false;
     }
     return added;
 }
Ejemplo n.º 2
0
 // <summary>
 /// ReadClaimWithoutRoot to read/parse the new claim provided by the user
 /// Returns: MitchellClaimType 
 /// </summary>
 private MitchellClaimType ReadClaimWithoutRoot(XDocument claimDocument)
 {
     // find claim in xml file
     MitchellClaimType claimResult = new MitchellClaimType();
     try
     {
         // Set namespace
         XNamespace cla = "http://www.mitchell.com/examples/claim";
         claimResult = claimDocument//.Element("Claims")
                 .Descendants(cla + "MitchellClaim")
                     .Select(claim => new MitchellClaimType
                     {
                         ClaimNumber = claim.Element(cla + "ClaimNumber").Value,
                         ClaimantFirstName = claim.Element(cla + "ClaimantFirstName").Value,
                         ClaimantLastName = claim.Element(cla + "ClaimantLastName").Value,
                         Status = (StatusCode)Enum.Parse(typeof(StatusCode), claim.Element(cla + "Status").Value),
                         LossDate = Convert.ToDateTime(claim.Element(cla + "LossDate").Value),
                         LossInfo = (LossInfoType)claim.Descendants(cla + "LossInfo").Select(lossInfo => new LossInfoType
                         {
                             CauseOfLoss = (CauseOfLossCode)Enum.Parse(typeof(CauseOfLossCode), lossInfo.Element(cla + "CauseOfLoss").Value),
                             ReportedDate = Convert.ToDateTime(lossInfo.Element(cla + "ReportedDate").Value),
                             LossDescription = lossInfo.Element(cla + "LossDescription").Value
                         }).First(),
                         AssignedAdjusterID = Convert.ToInt64(claim.Element(cla + "AssignedAdjusterID").Value)
                         ,
                         Vehicles = claim.Element(cla + "Vehicles").Descendants(cla + "VehicleDetails")
                           .Select(vehicle => new VehicleInfoType
                           {
                               ModelYear = Convert.ToInt16(vehicle.Element(cla + "ModelYear").Value),
                               MakeDescription = vehicle.Element(cla + "MakeDescription").Value,
                               ModelDescription = vehicle.Element(cla + "ModelDescription").Value,
                               EngineDescription = vehicle.Element(cla + "EngineDescription").Value,
                               ExteriorColor = vehicle.Element(cla + "ExteriorColor").Value,
                               Vin = vehicle.Element(cla + "Vin").Value,
                               LicPlate = vehicle.Element(cla + "LicPlate").Value,
                               LicPlateState = vehicle.Element(cla + "LicPlateState").Value,
                               LicPlateExpDate = Convert.ToDateTime(vehicle.Element(cla + "LicPlateExpDate").Value),
                               DamageDescription = vehicle.Element(cla + "DamageDescription").Value,
                               Mileage = Convert.ToInt16(vehicle.Element(cla + "Mileage").Value)
                           }).ToList<VehicleInfoType>()
                     }).First();
         return claimResult;
     }
     catch
     {
         claimResult = null;
         return null;
     }
 }