public MitchellClaimType(string CN, string CFN, string CLN, StatusCode stt, DateTime LDate, LossInfoType LI, long aaID, VehicleListType vehi) { ClaimNumber = CN; ClaimFirstName = CFN; ClaimLastName = CLN; Status = stt; LossDate = LDate; LossInfo = LI; AssignedAdjusterID = aaID; Vehicles = vehi; }
//Helper Function - Not in web service public void loadfromXML(XmlDocument xdoc) { //Read the information from the xml xdoc XML Document //Assumption: All submitted files must be in this formatting var tClaimNumber = xdoc.DocumentElement.ChildNodes[0].InnerText; var tClaimFirstName = xdoc.DocumentElement.ChildNodes[1].InnerText; var tClaimLastName = xdoc.DocumentElement.ChildNodes[2].InnerText; var tStatus = (StatusCode)Enum.Parse(typeof(StatusCode), xdoc.DocumentElement.ChildNodes[3].InnerText); var tLossDate = DateTime.Parse(xdoc.DocumentElement.ChildNodes[4].InnerText); var aaID = long.Parse(xdoc.DocumentElement.ChildNodes[6].InnerText); var li = xdoc.DocumentElement.ChildNodes[5]; var ColCode = (CauseOfLossCode)Enum.Parse(typeof(CauseOfLossCode), li.ChildNodes[0].InnerText, false); var date = DateTime.Parse(li.ChildNodes[1].InnerText); var des = li.ChildNodes[2].InnerText; var tLossInfo = new LossInfoType(ColCode, date, des); var vehi = xdoc.DocumentElement.ChildNodes[7]; //Reading Vehicles attributes of the claim xml file VehicleListType VehicleList = new VehicleListType(); foreach (XmlNode veNode in vehi) { var ModelYear = int.Parse(veNode.ChildNodes.Item(1).InnerText); var MakeDescription = veNode.ChildNodes.Item(2).InnerText; var ModelDescription = veNode.ChildNodes.Item(3).InnerText; var EngineDescription = veNode.ChildNodes.Item(4).InnerText; var ExteriorColor = veNode.ChildNodes.Item(5).InnerText; var Vin = veNode.ChildNodes.Item(0).InnerText; var LicPlate = veNode.ChildNodes.Item(6).InnerText; var LicPlateState = veNode.ChildNodes.Item(7).InnerText; var LicPlateExpDate = DateTime.Parse(veNode.ChildNodes.Item(8).InnerText); var DamageDescription = veNode.ChildNodes.Item(9).InnerText; var Mileage = int.Parse(veNode.ChildNodes.Item(10).InnerText); var tVehicle = new VehicleInfoType(ModelYear, MakeDescription, ModelDescription, EngineDescription, ExteriorColor, Vin, LicPlate, LicPlateState, LicPlateExpDate, DamageDescription, Mileage); VehicleList.add(tVehicle); } //Create an MitchellClaimType object based on the information getting from XML file MitchellClaimType addClaim = new MitchellClaimType(tClaimNumber, tClaimFirstName, tClaimLastName, tStatus, tLossDate, tLossInfo, aaID, VehicleList); //In this demo, this will add the new submitted claim into the database //In real program, this will fetch this object into the database - SQL Server or anything else backing_store[claimCount] = addClaim; claimCount++; }
public int DBCreateLossInfo(LossInfoType newLossInfo) { int newLossInfoID = 0; try { using (NpgsqlConnection connection = new NpgsqlConnection(connectionString)) { connection.Open(); string query = " INSERT INTO LossInfo (CauseOfLoss, ReportedDate, LossDescription) " + " VALUES (:CauseOfLoss, :ReportedDate, :LossDescription) RETURNING LossInfoID; "; using (NpgsqlCommand command = new NpgsqlCommand(query, connection)) { int causeOfLossID = 0; switch (newLossInfo.CauseOfLoss) { case "Collision": causeOfLossID = 1; break; case "Explosion": causeOfLossID = 2; break; case "Fire": causeOfLossID = 3; break; case "Hail": causeOfLossID = 4; break; case "Mechanical Breakdown": causeOfLossID = 5; break; case "Other": causeOfLossID = 6; break; } command.Parameters.Add(new NpgsqlParameter("CauseOfLoss", NpgsqlDbType.Integer)); command.Parameters.Add(new NpgsqlParameter("ReportedDate", NpgsqlDbType.Timestamp)); command.Parameters.Add(new NpgsqlParameter("LossDescription", NpgsqlDbType.Varchar)); command.Parameters[0].Value = causeOfLossID; command.Parameters[1].Value = newLossInfo.ReportedDate; command.Parameters[2].Value = (newLossInfo.LossDescription == "") ? ("") : (newLossInfo.LossDescription); newLossInfoID = Int32.Parse(command.ExecuteScalar().ToString().Trim()); } } } catch (Exception ex) { // Error handling Console.WriteLine("Error in DBCreateLossInfo: " + ex.Message); } finally { } return(newLossInfoID); }