public BetFileResponse SaveATGFile(BetFileRequest request) { var raceDay = request.RaceDay; var coupons = new List <string[]> (); foreach (var row in request.Rows) { var horses = row.Split(',').Select(x => Int32.Parse(x)); var legs = new List <string>(); foreach (var horse in horses) { var marks = "000000000000000".ToArray(); marks [horse - 1] = '1'; legs.Add(new string(marks)); } coupons.Add(legs.ToArray()); } //var coupons = new List<string[]>() { request.Rows }; var atgXMLFile = new issuer(); atgXMLFile.company = "none"; atgXMLFile.createddate = DateTime.Now; atgXMLFile.product = "TrabLab"; atgXMLFile.version = "0.1"; atgXMLFile.schemaversion = "ATG File Betting XSD ver 1.8"; var betcoupons = new betcouponsType(); atgXMLFile.betcoupons = betcoupons; if (request.RaceDay.BetType == "V75") { int couponId = 1; var couponTypes = new List <v75CouponType>(); foreach (var kupong in coupons) { var couponType = new v75CouponType(); couponType.date = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date); couponType.couponid = Convert.ToString(couponId++); var legTypes = new List <legType>(); int legId = 1; foreach (var leg in kupong) { legType legType = new legType(); legType.marks = leg; legType.legno = Convert.ToString(legId++); legTypes.Add(legType); } couponType.leg = legTypes.ToArray(); couponTypes.Add(couponType); } betcoupons.v75Coupon = couponTypes.ToArray(); } else if (raceDay.BetType == "V65") { int couponId = 1; var couponTypes = new List <v65CouponType>(); foreach (var kupong in coupons) { var couponType = new v65CouponType(); couponType.date = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date); couponType.couponid = Convert.ToString(couponId++); var legTypes = new List <legType>(); int legId = 1; foreach (var leg in kupong) { legType legType = new legType(); legType.marks = leg; legType.legno = Convert.ToString(legId++); legTypes.Add(legType); } couponType.leg = legTypes.ToArray(); couponTypes.Add(couponType); } betcoupons.v65Coupon = couponTypes.ToArray(); } else if (raceDay.BetType == "V86") { int couponId = 1; var couponTypes = new List <v86CouponType>(); foreach (var kupong in coupons) { var couponType = new v86CouponType(); couponType.date = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date); couponType.couponid = Convert.ToString(couponId++); couponType.trackcode = raceDay.TrackId.ToString(); var legTypes = new List <legType>(); int legId = 1; foreach (var leg in kupong) { legType legType = new legType(); legType.marks = leg; legType.legno = Convert.ToString(legId++); legTypes.Add(legType); } couponType.leg = legTypes.ToArray(); couponTypes.Add(couponType); } betcoupons.v86Coupon = couponTypes.ToArray(); } else if (raceDay.BetType == "V64") { int couponId = 1; var couponTypes = new List <v64CouponType>(); foreach (var kupong in coupons) { var couponType = new v64CouponType(); couponType.date = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date); couponType.couponid = Convert.ToString(couponId++); var legTypes = new List <legType>(); int legId = 1; foreach (var leg in kupong) { legType legType = new legType(); legType.marks = leg; legType.legno = Convert.ToString(legId++); legTypes.Add(legType); } couponType.leg = legTypes.ToArray(); couponTypes.Add(couponType); } betcoupons.v64Coupon = couponTypes.ToArray(); } else if (raceDay.BetType == "V5") { int couponId = 1; var couponTypes = new List <v5CouponType>(); foreach (var kupong in coupons) { var couponType = new v5CouponType(); couponType.date = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date); couponType.couponid = Convert.ToString(couponId++); couponType.trackcode = raceDay.TrackId.ToString(); var legTypes = new List <legType>(); int legId = 1; foreach (var leg in kupong) { legType legType = new legType(); legType.marks = leg; legType.legno = Convert.ToString(legId++); legTypes.Add(legType); } couponType.leg = legTypes.ToArray(); couponTypes.Add(couponType); } betcoupons.v5Coupon = couponTypes.ToArray(); } else if (raceDay.BetType == "V4") { int couponId = 1; var couponTypes = new List <v4CouponType>(); foreach (var kupong in coupons) { var couponType = new v4CouponType(); couponType.date = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date); couponType.couponid = Convert.ToString(couponId++); couponType.trackcode = raceDay.TrackId.ToString(); var legTypes = new List <legType>(); int legId = 1; foreach (var leg in kupong) { legType legType = new legType(); legType.marks = leg; legType.legno = Convert.ToString(legId++); legTypes.Add(legType); } couponType.leg = legTypes.ToArray(); couponTypes.Add(couponType); } betcoupons.v4Coupon = couponTypes.ToArray(); } //var systemSize = Coupon.CountRows(legs); //var reducedSize = coupon.Sum(x => Coupon.CountRows(x)); XmlSerializer xmlSerializer = new XmlSerializer(typeof(issuer)); MemoryStream memoryStream = new MemoryStream(); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); xmlSerializer.Serialize(xmlTextWriter, atgXMLFile); xmlTextWriter.BaseStream.Position = 0; string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(request.Filename); Crc16 crc16 = new Crc16(); string checkSumAsHexString = crc16.GetCheckSumAsHexString(xmlTextWriter.BaseStream); var fileName = string.Format("{0}_{1}_{2}_{3}.xml", fileNameWithoutExtension, request.ReducedSize, request.SystemSize, checkSumAsHexString); xmlTextWriter.BaseStream.Position = 0; StreamReader streamReader = new StreamReader(xmlTextWriter.BaseStream); return(new BetFileResponse() { XML = streamReader.ReadToEnd(), Filename = fileName }); //string end = streamReader.ReadToEnd(); //StreamWriter streamWriter = new StreamWriter(fileName, false); //streamWriter.Write(end); //streamWriter.Flush(); //streamWriter.Close(); //xmlTextWriter.Close(); //return fileName; }
public ActionResult <BetFileResponse> GetBettingFile(BetFileRequest request) { return(_fileService.SaveATGFile(request)); }