예제 #1
0
 public void PrintBill()
 {
     Console.WriteLine(this);
     Console.WriteLine("Details:");
     Console.WriteLine(BillLine.ToStringHeader());
     BillLines.ToList().ForEach(Console.WriteLine);
 }
예제 #2
0
        public static Bill CreateBill(User user, IEnumerable <ItemLine> lines)
        {
            ClientMessaging _clientMessaging = new ClientMessaging("bill_queue");
            List <BillLine> billLines        = new List <BillLine>();

            foreach (ItemLine line in lines)
            {
                var billline = new BillLine(line.Item, line.Quantity);
                billLines.Add(billline);
            }
            var request = new Dictionary <string, object>
            {
                { "user", JsonConvert.SerializeObject(user) },
                { "products", JsonConvert.SerializeObject(billLines) }
            };
            var response = _clientMessaging.Send(request);
            var bill     = JsonConvert.DeserializeObject <Bill>((string)response["bill"]);

            _clientMessaging.Close();
            return(bill);
        }
예제 #3
0
        public static Bill createBill(User user, List <ItemLine> lines)
        {
            /*string json = JsonConvert.SerializeObject(user);
             * json += JsonConvert.SerializeObject(lines);*/

            /* On aurait dû utiliser des propriétés dans les classes parce que sans
             * ça Newtoonsoft ne peut pas sérialiser les objets automatiquement*/

            Bill bill = new Bill();

            bill.setUser(user);
            double ssTotal = 0;

            foreach (ItemLine il in lines)
            {
                BillLine bl = new BillLine(il.getItem(), il.getQuantite(), il.getItem().getPrix() * il.getQuantite());
                bill.getBillLines().Add(bl);
                ssTotal += bl.getSousTotal();
            }
            bill.setSousTotal(ssTotal);
            bill.setTotal(Math.Round(ssTotal * 1.149975, 2));
            return(bill);
        }