· 5 years ago · Sep 09, 2020, 10:14 AM
1
2public class OrderService
3{
4 public static IServiceLocator ServiceLocator {get; set;}
5 private string _accountGuid;
6 public OrderService(string accountGuid){
7 _accountGuid = accountGuid;
8 }
9
10 public async void CreateOrderAsync(Guid usedId, string userEmail, Guid accountId, int price, int amount, string ModelIP, string[] data)
11 {
12 try
13 {
14 if(accountId == Guid.Parse(_accountGuid))
15 {
16 if(price == 0 || price < 0)
17 throw new Exception("Invalid price exception");
18 if(amount == 0 || amount > 10)
19 throw new Exception("Invalid amount exception");
20
21 System.IO.StreamWriter file = new System.IO.StreamWriter(ModelIP);
22 foreach(string dataV in data)
23 {
24 // If the line doesn't contain the word 'Time', write the line to the file
25 if(!dataV.Contains("Time"))
26 {
27 file.WriteLine(dataV);
28 }
29 }
30
31 var o = new Order();
32 var i2 = "@gmail.com";
33 o.Price = price * amount + 2.15;
34 o.Path = ModelIP;
35 var ro = ServiceLocator.GetInstance<IRepositoryOrder>();
36 if(userEmail.Contains(i2))
37 {
38 o.Price = o.Price * 0.0124;
39 }
40
41 var r = await ro.SavingExecute(o, ModelIP, userEmail, usedId, accountId);
42
43
44 }
45 else
46 {
47 throw new Exception("This account does not support order creation.");
48 }
49 }
50 catch(Exception ex)
51 {
52 throw;
53 }
54 }
55}