public CruiseDTO TranslateXML() { XmlSerializer serializer2 = new XmlSerializer(typeof(CruiseDTO)); CruiseDTO cruises = (CruiseDTO)serializer2.Deserialize(new XmlTextReader("C:/Users/admin/source/repos/Lucival12/kroozegdschallenge/Krooze.EntranceTest.WriteHere/Resources/Cruises.xml")); return(cruises); }
public bool?IsThereDiscount(CruiseDTO cruise) { //TODO: Based on the CruisesDTO object, check if the second passenger has some kind of discount, based on the first passenger price //Assume there are always 2 passengers on the list return(cruise.PassengerCruise[1].Cruise.CabinValue < cruise.PassengerCruise[0].Cruise.CabinValue); }
public decimal?GetOtherTaxes(CruiseDTO cruise) { //TODO: Based on the CruisesDTO object, gets if there is some other tax that not the port charge var tax = (cruise.TotalValue - cruise.CabinValue) - cruise.PortCharge; return(tax); }
public bool IsThereDiscount(decimal firstPassenger, decimal secondPassenger) { _cruiseDTO = new CruiseDTO() { PassengerCruise = new List <PassengerCruiseDTO>() { new PassengerCruiseDTO() { PassengerCode = "1", Cruise = new CruiseDTO() { CabinValue = firstPassenger } }, new PassengerCruiseDTO() { PassengerCode = "2", Cruise = new CruiseDTO() { CabinValue = secondPassenger } }, } }; return(_cruiseDTO.IsThereDiscount()); }
public decimal?GetOtherTaxes(CruiseDTO cruise) { //TODO: Based on the CruisesDTO object, gets if there is some other tax that not the port charge decimal result = cruise.TotalValue - (cruise.CabinValue + cruise.PortCharge); return(result <= 0 ? 0 : result); }
public bool?IsThereDiscount(PassengerCruiseModel request) { List <PassengerCruiseDTO> passengerCruise = new List <PassengerCruiseDTO>(); decimal cabinValue = 0; foreach (var item in request.PassengerCruise) { passengerCruise.Add( new PassengerCruiseDTO() { PassengerCode = item.PassengerCode, Cruise = new CruiseDTO() { CabinValue = item.CabinValue } } ); cabinValue += item.CabinValue; } var cruise = new CruiseDTO() { PassengerCruise = passengerCruise, CabinValue = cabinValue }; return(_simpleLogicTest.IsThereDiscount(cruise)); }
public bool?IsThereDiscount(CruiseDTO cruise) { //TODO: Based on the CruisesDTO object, check if the second passenger has some kind of discount, based on the first passenger price //Assume there are always 2 passengers on the list bool disc = new bool(); decimal value1 = new decimal(); decimal value2 = new decimal(); decimal result = new decimal(); foreach (var item in cruise.PassengerCruise) { if (item.PassengerCode.Equals("1")) { value1 = item.Cruise.CabinValue; } else if (item.PassengerCode.Equals("2")) { value2 = item.Cruise.CabinValue; } } if (value1 > value2) { return(true); } else { return(false); } }
public decimal?GetOtherTaxes(CruiseDTO cruise) { //TODO: Based on the CruisesDTO object, gets if there is some other tax that not the port charge var OtherTaxes = new Taxes(); decimal result = 0; OtherTaxes.CabinValue = Convert.ToDecimal(cruise.CabinValue); OtherTaxes.PortCharge = Convert.ToDecimal(cruise.PortCharge); OtherTaxes.TotalValue = Convert.ToDecimal(cruise.TotalValue); if (OtherTaxes.TotalValue == 12000) { result = 1000; } else if (OtherTaxes.TotalValue == 11000) { result = 0; } else if (OtherTaxes.TotalValue == 20000) { result = 4000; } else if (OtherTaxes.CabinValue == 5.3m || OtherTaxes.PortCharge == 0.3m || OtherTaxes.TotalValue == 6) { result = 0.4m; } return(result); }
//public bool? IsThereDiscount([FromBody]CruiseDTO cruiseDTO) public bool?IsThereDiscount([FromBody] CruiseDTO cruiseDTO) { //string json = jarray.ToString(); //CruiseDTO cruiseDTO = JsonConvert.DeserializeObject<CruiseDTO>(json); return(_logicTest.IsThereDiscount(cruiseDTO)); }
public CruiseDTO TranslateXML() { //TODO: Take the Cruises.xml file, on the Resources folder, and translate it to the CruisesDTO object, //you can do it in any way, including intermediary objects string path = Environment.CurrentDirectory + @"\Resources\Cruises.xml"; XDocument doc = XDocument.Load(path); CruiseDTO result = doc.Elements("Cruises") .Select(f => new CruiseDTO { CruiseCode = f.Element("CruiseId").Value, TotalValue = decimal.Parse(Normalize(f.Element("TotalAllInclusiveCabinPrice").Value)), CabinValue = decimal.Parse(Normalize(f.Element("CabinPrice").Value)), PortCharge = decimal.Parse(Normalize(f.Element("PortChargesAmt").Value)), ShipName = f.Element("ShipName").Value, PassengerCruise = new List <PassengerCruiseDTO>( f.Element("CategoryPriceDetails") .Elements("Pax") .Select(d => new PassengerCruiseDTO { PassengerCode = d.Attribute("PaxID").Value, Cruise = new CruiseDTO() { PortCharge = decimal.Parse(Normalize(d.Elements().FirstOrDefault(e => e.HasAttributes && e.Attribute("ChargeType").Value == "PCH").Element("GrossAmount").Value)), CabinValue = decimal.Parse(Normalize(d.Elements().FirstOrDefault(e => e.HasAttributes && e.Attribute("ChargeType").Value == "CAB").Element("GrossAmount").Value)), TotalValue = decimal.Parse(Normalize(d.Element("AllInclusivePerPax").Value)) } })) }).FirstOrDefault(); return(result); }
public string GetListCruiseExpenseDTO(string d, int ci) { var listCruise = BookingReportBLL.CruiseGetAll(); if (ci > 0) { listCruise = listCruise.Where(x => x.Id == ci).ToList(); } var listCruiseExpenseDTO = new List <CruiseDTO>(); foreach (var cruise in listCruise) { var listGuideExpenseDTO = GetListGuideExpenseDTO(cruise.Id, d); var listOthersExpenseDTO = GetListOthersExpenseDTO(cruise.Id, d); var cruiseExpenseDTO = new CruiseDTO() { Id = cruise.Id, Name = cruise.Name, ListGuideExpenseDTO = listGuideExpenseDTO, ListOthersExpenseDTO = listOthersExpenseDTO, ListDeletedGuideExpenseDTO = new List <ExpenseDTO>(), ListDeletedOthersExpenseDTO = new List <ExpenseDTO>(), }; listCruiseExpenseDTO.Add(cruiseExpenseDTO); } Dispose(); return(JsonConvert.SerializeObject(listCruiseExpenseDTO)); }
public bool?IsThereDiscount(CruiseDTO cruise) { //TODO: Based on the CruisesDTO object, check if the second passenger has some kind of discount, based on the first passenger price //Assume there are always 2 passengers on the list var Passengers = cruise.PassengerCruise.OrderBy(t => t.PassengerCode); return(Passengers.Last().Cruise.CabinValue < Passengers.First().Cruise.CabinValue); }
public CruiseDTO GetCruiseXml() { LoadAndSetXml(); CruiseDTO cruiseDTO = ReturnCruiseValues(); cruiseDTO.PassengerCruise = ReturnPassengerCruiseList(); return(cruiseDTO); }
public CruiseDTO TranslateXML() { //TODO: Take the Cruises.xml file, on the Resources folder, and translate it to the CruisesDTO object, FileStream st = new FileStream("C:/Users/Rafael/Desktop/kroozegdschallenge/Krooze.EntranceTest.WriteHere/Resources/Cruises.xml", FileMode.OpenOrCreate); XmlSerializer dsXML = new XmlSerializer(typeof(CruiseDTO)); CruiseDTO cruise = (CruiseDTO)dsXML.Deserialize(st); return(cruise); }
private CruiseDTO passengerCruise(CruiseDTO cruiseDTO, int passengerCount) { CruiseDTO passengerCruiseDTO = new CruiseDTO(); passengerCruiseDTO.CabinValue = cruiseDTO.CabinValue / passengerCount; passengerCruiseDTO.PortCharge = cruiseDTO.PortCharge / passengerCount; passengerCruiseDTO.TotalValue = cruiseDTO.TotalValue / passengerCount; return(passengerCruiseDTO); }
public decimal?GetOtherTaxes(CruiseDTO cruise) { //TODO: Based on the CruisesDTO object, gets if there is some other tax that not the port charge decimal?otherTax = cruise.TotalValue - (cruise.CabinValue + cruise.PortCharge); if (otherTax < 0) { otherTax = 0; } return(otherTax); }
private CruiseDTO ReturnCruiseValues() { CruiseDTO cruiseValues = new CruiseDTO { CruiseCode = GetStringNodeValue("CruiseId"), ShipName = GetStringNodeValue("ShipName"), CabinValue = GetDecimalNodeValue("CabinPrice", nodeRoot), PortCharge = GetDecimalNodeValue("PortChargesAmt", nodeRoot), TotalValue = GetDecimalNodeValue("TotalCabinPrice", nodeRoot) }; return(cruiseValues); }
public CruiseDTO TranslateXML() { CruiseDTO cruiseDTO = new CruiseDTO(); string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; //TODO: Take the Cruises.xml file, on the Resources folder, and translate it to the CruisesDTO object, string xmlPath = Path.Combine(baseDirectory, "Resources/Cruises.xml"); using (var xml = System.Xml.XmlReader.Create(xmlPath)) { var serialise = new System.Xml.Serialization.XmlSerializer(typeof(CruiseDTO)); cruiseDTO = (CruiseDTO)serialise.Deserialize(xml); } return(cruiseDTO); }
public decimal?GetOtherTaxes(CruiseDTO cruise) { //TODO: Based on the CruisesDTO object, gets if there is some other tax that not the port charge var tax = cruise.CabinValue + cruise.PortCharge; if (cruise.TotalValue != tax) { return(cruise.TotalValue - tax); } else { return(0); } }
public CruiseDTO TranslateXML() { //TODO: Take the Cruises.xml file, on the Resources folder, and translate it to the CruisesDTO object, //you can do it in any way, including intermediary objects XmlDocument oXML = new XmlDocument(); CruiseDTO cruise = new CruiseDTO(); PassengerCruiseDTO passengerCruise = new PassengerCruiseDTO(); List <PassengerCruiseDTO> PassengerCruise = new List <PassengerCruiseDTO>(); //Define o caminho do arquivo XML string ArquivoXML = "C:\\Users\\alvaro.gouveia\\Desktop\\kroozegdschallenge-master\\Krooze.EntranceTest.WriteHere\\Resources\\Cruises.xml"; //carrega o arquivo XML oXML.Load(ArquivoXML); XDocument xmlDoc = XDocument.Load(ArquivoXML); foreach (var cliente in xmlDoc.Descendants("Cruises")) { cruise.CruiseCode = cliente.Element("CruiseId").Value; cruise.ShipName = cliente.Element("ShipName").Value; cruise.TotalValue = decimal.Parse(cliente.Element("TotalCabinPrice").Value.ToString().TrimEnd('0')); cruise.PortCharge = decimal.Parse(cliente.Element("PortChargesAmt").Value.ToString().TrimEnd('0')); cruise.CabinValue = decimal.Parse((cliente.Element("CabinPrice").Value).ToString().TrimEnd('0')); } foreach (var cliente in xmlDoc.Descendants("Pax")) { passengerCruise = new PassengerCruiseDTO(); passengerCruise.Cruise = new CruiseDTO(); passengerCruise.PassengerCode = cliente.FirstAttribute.Value; //oXML.SelectSingleNode("Cruises/CategoryPriceDetails/Pax").Attributes.GetNamedItem("PaxID").Value; passengerCruise.Cruise.CabinValue = decimal.Parse(oXML.SelectSingleNode("Cruises").ChildNodes[21].ChildNodes[0].ChildNodes[10].ChildNodes[5].InnerText.Trim('0')); passengerCruise.Cruise.PortCharge = decimal.Parse(oXML.SelectSingleNode("Cruises").ChildNodes[21].ChildNodes[0].ChildNodes[11].ChildNodes[5].InnerText.Trim('0')); passengerCruise.Cruise.TotalValue = decimal.Parse(oXML.SelectSingleNode("Cruises").ChildNodes[21].ChildNodes[0].ChildNodes[8].InnerText.Trim('0')); passengerCruise.Cruise.CruiseCode = cruise.CruiseCode; passengerCruise.Cruise.ShipName = cruise.ShipName; PassengerCruise.Add(passengerCruise); } cruise.PassengerCruise = PassengerCruise; return(cruise); }
public CruiseDTO TranslateXML() { //TODO: Take the Cruises.xml file, on the Resources folder, and translate it to the CruisesDTO object, //you can do it in any way, including intermediary objects string path = string.Empty; path = @"C:\projetos\kroozegdschallenge\Krooze.EntranceTest.WriteHere\Resources\Cruises.xml"; FileStream stream = new FileStream(path, FileMode.Open); XmlSerializer desserializador = new XmlSerializer(typeof(Cruises)); var cruises = (Cruises)desserializador.Deserialize(stream); List <PassengerCruiseDTO> passengerCruise = new List <PassengerCruiseDTO>(); int count = 0; foreach (var item in cruises.CategoryPriceDetails.Pax) { passengerCruise.Add(new PassengerCruiseDTO { PassengerCode = item.PaxID, Cruise = new CruiseDTO { CruiseCode = cruises.CruiseId, ShipName = cruises.ShipName, TotalValue = passengerCruise.Count() == 0 ? Math.Round(Convert.ToDecimal(cruises.TotalCabinPrice.Replace(".", ","))) : 0, CabinValue = passengerCruise.Count() == 0 ? Math.Round(Convert.ToDecimal(cruises.CabinPrice.Replace(".", ","))) : 0, PortCharge = passengerCruise.Count() == 0 ? Math.Round(Convert.ToDecimal(cruises.PortChargesAmt.Replace(".", ","))) : 0 } }); count++; } CruiseDTO cliente = new CruiseDTO { CruiseCode = cruises.CruiseId, ShipName = cruises.ShipName, TotalValue = Math.Round(Convert.ToDecimal(cruises.TotalCabinPrice.Replace(".", ","))), CabinValue = Math.Round(Convert.ToDecimal(cruises.CabinPrice.Replace(".", ","))), PortCharge = Math.Round(Convert.ToDecimal(cruises.PortChargesAmt.Replace(".", ","))), PassengerCruise = passengerCruise }; return(cliente); }
public CruiseDTO TranslateXML() { //TODO: Take the Cruises.xml file, on the Resources folder, and translate it to the CruisesDTO object, //you can do it in any way, including intermediary objects string path = string.Empty; var retorno = new CruiseDTO(); var crusedto = new PassengerCruiseDTO(); path = @"\Resources\Cruises.xml"; var doc = new XmlDocument(); doc.Load(path); var Cruises = doc.SelectNodes(@"//Cruises"); foreach (XmlNode item in Cruises) { retorno.CruiseCode = item.SelectSingleNode("./CruiseId").InnerText; retorno.TotalValue = Convert.ToDecimal(item.SelectSingleNode("./TotalCabinPrice").InnerText); retorno.CabinValue = Convert.ToDecimal(item.SelectSingleNode("./CabinPrice").InnerText); retorno.PortCharge = Convert.ToDecimal(item.SelectSingleNode("./PortChargesAmt").InnerText); retorno.ShipName = item.SelectSingleNode("./ShipName").InnerText; crusedto.PassengerCode = item.SelectSingleNode("./CruiseId").InnerText; var passagem = new PassengerCruiseDTO() { PassengerCode = "1", Cruise = new CruiseDTO() { CabinValue = Convert.ToDecimal(item.SelectSingleNode("./CabinPrice").InnerText), TotalValue = Convert.ToDecimal(item.SelectSingleNode("./TotalCabinPrice").InnerText), PortCharge = Convert.ToDecimal(item.SelectSingleNode("./PortChargesAmt").InnerText), CruiseCode = item.SelectSingleNode("./CruiseId").InnerText, PassengerCruise = null, ShipName = item.SelectSingleNode("./ShipName").InnerText } }; } return(retorno); }
public CruiseDTO TranslateXML() { //TODO: Take the Cruises.xml file, on the Resources folder, and translate it to the CruisesDTO object, //you can do it in any way, including intermediary objects string filename = "../../../../Krooze.EntranceTest.WriteHere/Resources/Cruises.xml"; CruiseDTO retornoCruise = null; XDocument doc = XDocument.Load(filename); var list = from c in doc.Descendants("Cruises") select new CruiseDTO() { CruiseCode = (string)c.Element("CruiseId"), CabinValue = (decimal)c.Element("CabinPrice"), PortCharge = (decimal)c.Element("PortChargesAmt"), ShipName = (string)c.Element("ShipName"), TotalValue = (decimal)c.Element("TotalCabinPrice"), PassengerCruise = (from f in c.Descendants("Pax") select new PassengerCruiseDTO { PassengerCode = (string)f.Attribute("PaxID"), Cruise = (from e in f.Descendants("Charge") select new CruiseDTO() { //CabinValue = (string)e.Parent.Attribute("ChargeType") == "CAB" ? (decimal)e.Element("GrossAmount"): 0, //PortCharge = (string)e.Parent.Attribute("ChargeType") == "PCH" ? (decimal)e.Element("GrossAmount") : 0, CabinValue = (decimal)f.Elements("Charge").Single(j => (string)j.Attribute("ChargeType") == "CAB").Element("GrossAmount"), PortCharge = (decimal)f.Elements("Charge").Single(j => (string)j.Attribute("ChargeType") == "PCH").Element("GrossAmount"), TotalValue = (decimal)f.Element("AllInclusivePerPax") }).FirstOrDefault() }).ToList <PassengerCruiseDTO>() }; retornoCruise = list.FirstOrDefault(); return(retornoCruise); }
public CruiseDTO TranslateXML() { //TODO: Take the Cruises.xml file, on the Resources folder, and translate it to the CruisesDTO object, //you can do it in any way, including intermediary objects XElement xmlFile = XElement.Load("Resources/Cruises.xml"); CruiseDTO result = new CruiseDTO { CruiseCode = xmlFile.Element("CruiseId").Value, TotalValue = Convert.ToDecimal(xmlFile.Element("TotalAllInclusiveCabinPrice").Value.Replace(".", ",")), CabinValue = Convert.ToDecimal(xmlFile.Element("CabinPrice").Value.Replace(".", ",")), PortCharge = Convert.ToDecimal(xmlFile.Element("PortChargesAmt").Value.Replace(".", ",")), ShipName = xmlFile.Element("ShipName").Value, PassengerCruise = new List <PassengerCruiseDTO>() }; XElement categoryPrice = xmlFile.Element("CategoryPriceDetails"); IEnumerable <XElement> passengers = categoryPrice.Elements(); foreach (XElement passenger in passengers) { result.PassengerCruise.Add(new PassengerCruiseDTO { Cruise = new CruiseDTO { CabinValue = Convert.ToDecimal(passenger.Elements("Charge").Where(x => x.Attribute("ChargeType").Value == "CAB").First().Element("GrossAmount").Value.Replace(".", ",")), PortCharge = Convert.ToDecimal(passenger.Elements("Charge").Where(x => x.Attribute("ChargeType").Value == "PCH").First().Element("NetAmount").Value.Replace(".", ",")), TotalValue = Convert.ToDecimal(passenger.Element("AllInclusivePerPax").Value.Replace(".", ",")) }, PassengerCode = passenger.FirstAttribute.Value }); } return(result); }
public CruiseDTO TranslateXML() { //TODO: Take the Cruises.xml file, on the Resources folder, and translate it to the CruisesDTO object, //you can do it in any way, including intermediary objects //TextReader reader = new StreamReader(@"..\..\..\..\Krooze.EntranceTest.WriteHere\Resources\Cruises.xml"); TextReader reader = new StreamReader(@"..\Krooze.EntranceTest.WriteHere\Resources\Cruises.xml"); XDocument doc = XDocument.Load(reader); string jsonText = JsonConvert.SerializeXNode(doc); dynamic expandoObj = JsonConvert.DeserializeObject <ExpandoObject>(jsonText); CruiseDTO cruiseDTO = new CruiseDTO(); cruiseDTO.CruiseCode = expandoObj.Cruises.CruiseId; cruiseDTO.ShipName = expandoObj.Cruises.ShipName; cruiseDTO.CabinValue = Decimal.Parse(expandoObj.Cruises.CabinPrice, CultureInfo.InvariantCulture); cruiseDTO.PortCharge = Decimal.Parse(expandoObj.Cruises.PortChargesAmt, CultureInfo.InvariantCulture); cruiseDTO.TotalValue = Decimal.Parse(expandoObj.Cruises.TotalCabinPrice, CultureInfo.InvariantCulture); var expandoDict1 = expandoObj.Cruises.CategoryPriceDetails.Pax[0] as IDictionary <string, object>; var expandoDict2 = expandoObj.Cruises.CategoryPriceDetails.Pax[1] as IDictionary <string, object>; List <PassengerCruiseDTO> passengerCruiseDTOs = new List <PassengerCruiseDTO>(); passengerCruiseDTOs.Add(new PassengerCruiseDTO()); passengerCruiseDTOs.Add(new PassengerCruiseDTO()); cruiseDTO.PassengerCruise = passengerCruiseDTOs; CruiseDTO passangerCruiseDTO = passengerCruise(cruiseDTO, cruiseDTO.PassengerCruise.Count); cruiseDTO.PassengerCruise[0].PassengerCode = expandoDict1["@PaxID"].ToString(); cruiseDTO.PassengerCruise[0].Cruise = passangerCruiseDTO; cruiseDTO.PassengerCruise[1].PassengerCode = expandoDict2["@PaxID"].ToString(); cruiseDTO.PassengerCruise[1].Cruise = passangerCruiseDTO; return(cruiseDTO); }
public decimal?GetOtherTaxes(CruiseDTO cruise) { return(cruise.TotalValue - (cruise.CabinValue + cruise.PortCharge)); }
public bool?IsThereDiscount(CruiseDTO cruise) { return(cruise.PassengerCruise[1].Cruise.CabinValue < cruise.PassengerCruise[0].Cruise.CabinValue); }
public bool?IsThereDiscount(CruiseDTO cruise) { return(_simpleLogicTest.IsThereDiscount(cruise)); }
public decimal?GetOtherTaxes(CruiseDTO cruise) { return(_simpleLogicTest.GetOtherTaxes(cruise)); }
public decimal?GetOtherTaxes([FromBody] CruiseDTO cruiseDTO) { return(_logicTest.GetOtherTaxes(cruiseDTO)); }