public string processTransaction(string UserName, string CardNumber, string CVV, string ExpMonth, string ExpYear, string Amount) { try { string fLocation = Path.Combine(HttpRuntime.AppDomainAppPath, @"App_Data"); string file = Path.Combine(fLocation, "AccountInfo.xml"); string file4 = Path.Combine(fLocation, "TransactionDetails.xml"); XmlDocument xDoc = new XmlDocument(); xDoc.Load(file); XmlNodeList nodes = xDoc.GetElementsByTagName("AccountDetails"); foreach (XmlNode node in nodes) { if (node["Email"].InnerText == UserName) { if (node["CardNumber"].InnerText == CardNumber && node["CVV"].InnerText == CVV && node["ExpMonth"].InnerText == ExpMonth && node["ExpYear"].InnerText == ExpYear) { if (Convert.ToDouble(node["Amount"].InnerText) >= Convert.ToDouble(Amount)) { node["Amount"].InnerText = "" + (Convert.ToDouble(node["Amount"].InnerText) - Convert.ToDouble(Amount)); xDoc.Save(file); xDoc.Load(file4); XmlNodeList nodes1 = xDoc.GetElementsByTagName("TransactionDetails"); foreach (XmlNode node1 in nodes1) { if (node1["Uname"].InnerText == UserName) { TransactionDetails td = new TransactionDetails(UserName, Amount, "Debit"); XmlElement newNode = xDoc.CreateElement("Transaction"); newNode.SetAttribute("Date", td.Date); newNode.SetAttribute("Time", td.Time); newNode.SetAttribute("Type", td.Type); newNode.InnerText = td.Amount; node1.AppendChild(newNode); xDoc.Save(file4); } } return(String.Format("Transaction Successfully Completed! <br />Current Balance: {0}", node["Amount"].InnerText)); } else { return(String.Format("Not enough balance in your account! <br />Current Balance: {0}", node["Amount"].InnerText)); } } else { return("Invalid Data!"); } } } return("Invalid Data!"); } catch (FileNotFoundException) { return("Cannot process the transaction!"); } catch (Exception) { return("Server Error!"); } }
public string[] Registration(string fname, string lname, string email, string password, string amount) { try { string[] details = { fname, lname, email, password, amount }; CompleteDetails cd = new CompleteDetails(details); LoginDetails ld = new LoginDetails(details); AccountDetails ad = new AccountDetails(details); string fLocation = Path.Combine(HttpRuntime.AppDomainAppPath, @"App_Data"); string file1 = Path.Combine(fLocation, "Registration.xml"); string file2 = Path.Combine(fLocation, "LoginInfo.xml"); XmlDocument xDocument = new XmlDocument(); xDocument.Load(file2); XmlNodeList nodesX = xDocument.GetElementsByTagName("LoginDetails"); foreach (XmlNode nodeX in nodesX) { if (nodeX["Uname"].InnerText == email) { return(null); } } string file3 = Path.Combine(fLocation, "AccountInfo.xml"); string file4 = Path.Combine(fLocation, "TransactionDetails.xml"); if (!File.Exists(file1)) { StreamWriter sw = File.CreateText(file1); sw.WriteLine("<root xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"); sw.Close(); sw = File.CreateText(file2); sw.WriteLine("<root xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"); sw.Close(); sw = File.CreateText(file3); sw.WriteLine("<root xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"); sw.Close(); sw = File.CreateText(file4); sw.WriteLine("<root xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"); sw.Close(); } else { List <string> lines = File.ReadAllLines(file1).ToList(); File.WriteAllLines(file1, lines.GetRange(0, lines.Count - 1).ToArray()); List <string> lines2 = File.ReadAllLines(file2).ToList(); File.WriteAllLines(file2, lines2.GetRange(0, lines2.Count - 1).ToArray()); List <string> lines3 = File.ReadAllLines(file3).ToList(); File.WriteAllLines(file3, lines3.GetRange(0, lines3.Count - 1).ToArray()); List <string> lines4 = File.ReadAllLines(file4).ToList(); File.WriteAllLines(file4, lines4.GetRange(0, lines4.Count - 1).ToArray()); } using (StreamWriter sw = File.AppendText(file1)) { sw.WriteLine(" <CompleteDetails>"); sw.WriteLine(String.Format(" <FirstName>{0}</FirstName>", cd.FirstName)); sw.WriteLine(String.Format(" <LastName>{0}</LastName>", cd.LastName)); sw.WriteLine(String.Format(" <Email>{0}</Email>", cd.Email)); sw.WriteLine(String.Format(" <Amount>{0}</Amount>", cd.initialAmount)); sw.WriteLine(" </CompleteDetails>"); sw.WriteLine("</root>"); sw.Close(); } using (StreamWriter sw = File.AppendText(file2)) { sw.WriteLine(" <LoginDetails>"); sw.WriteLine(String.Format(" <Uname>{0}</Uname>", ld.Email)); sw.WriteLine(String.Format(" <Password>{0}</Password>", ld.Password)); sw.WriteLine(" </LoginDetails>"); sw.WriteLine("</root>"); sw.Close(); } using (StreamWriter sw = File.AppendText(file3)) { sw.WriteLine(" <AccountDetails>"); sw.WriteLine(String.Format(" <Email>{0}</Email>", ad.Email)); sw.WriteLine(String.Format(" <CardNumber>{0}</CardNumber>", ad.CardNumber)); sw.WriteLine(String.Format(" <CVV>{0}</CVV>", ad.CVV)); sw.WriteLine(String.Format(" <ExpMonth>{0}</ExpMonth>", ad.ExpMonth)); sw.WriteLine(String.Format(" <ExpYear>{0}</ExpYear>", ad.ExpYear)); sw.WriteLine(String.Format(" <Amount>{0}</Amount>", ad.amount)); sw.WriteLine(" </AccountDetails>"); sw.WriteLine("</root>"); sw.Close(); } using (StreamWriter sw = File.AppendText(file4)) { sw.WriteLine(" <TransactionDetails>"); sw.WriteLine(String.Format(" <Uname>{0}</Uname>", ld.Email)); sw.WriteLine(" </TransactionDetails>"); sw.WriteLine("</root>"); sw.Close(); } XmlDocument xDoc = new XmlDocument(); xDoc.Load(file4); XmlNodeList nodes = xDoc.GetElementsByTagName("TransactionDetails"); foreach (XmlNode node in nodes) { if (node["Uname"].InnerText == cd.Email) { TransactionDetails td = new TransactionDetails(cd.Email, cd.initialAmount, "Credit"); XmlElement newNode = xDoc.CreateElement("Transaction"); newNode.SetAttribute("Date", td.Date); newNode.SetAttribute("Time", td.Time); newNode.SetAttribute("Type", td.Type); newNode.InnerText = td.Amount; node.AppendChild(newNode); xDoc.Save(file4); } } string[] result = { ad.CardNumber, ad.CVV, ad.ExpMonth, ad.ExpYear }; return(result); } catch (FileNotFoundException) { return(null); } catch (Exception) { return(null); } }