public SingleTicket(tickets t, matches m) : base() { base.BookingReference = t.BookingReference; base.BookingDate = t.BookingDate; base.Quantity = t.Quantity; base.TicketType = t.TicketType; base.MatchId = t.MatchId; match = m; }
partial void Deletematches(matches instance);
partial void Updatematches(matches instance);
partial void Insertmatches(matches instance);
public SingleTicket() : base() { match = new matches(); }
public string BookTicket(int matchid, string tickettype, int quantity, string email) { DataClassesDataContext db = new DataClassesDataContext(); matches match = db.matches.First(i => i.Id == matchid); if (match == null) { return(new CommonResponse(new BadRequestError("Invalid match id")).json()); } Random rnd = new Random(); tickets ticket = new tickets(); ticket.BookingDate = DateTime.Now; ticket.BookingReference = ( (match.Competitor.Replace(" ", string.Empty) + "XXXX").Substring(0, 4) + rnd.Next(0, 99999).ToString("D5") + ticket.BookingDate.ToString("ddMMyy") ).ToUpper(); ticket.MatchId = matchid; ticket.TicketType = tickettype; ticket.Quantity = quantity; ticket.Email = email; if (email != null && email.Length > 0) { try { string my_email, my_pass; try { using (StreamReader file = new StreamReader(@"C:/crusaders.conf")) { string line = file.ReadLine(); if (line == null) { throw new NoException(); } string[] words = line.Split(' '); if (words.Length != 2) { throw new NoException(); } my_email = words[0]; my_pass = words[1]; } } catch (FileNotFoundException e) { return(new CommonResponse(new InternalError(e.ToString())).json()); } SmtpClient client = new SmtpClient(); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(my_email, my_pass); client.Port = 587; client.Host = "smtp.office365.com"; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; MailMessage mail = new MailMessage(); mail.To.Add(new MailAddress(email)); mail.From = new MailAddress(my_email, "Crusaders booking system"); mail.Subject = "Crusaders match booking reference"; mail.Body = "Match date: " + match.DateTime.ToString() + ";\nBooking reference: " + ticket.BookingReference; System.Threading.ThreadPool.QueueUserWorkItem(delegate { try { client.Send(mail); } catch (Exception) { // TODO: process exception } }, null); } catch (NoException) { } catch (Exception e) { return(new CommonResponse(new BadRequestError("Can't send an email: " + e.ToString())).json()); } } db.tickets.InsertOnSubmit(ticket); db.SubmitChanges(); return(new ListResponse <tickets>(ticket).json()); }