Exemple #1
0
        public async Task <ReceiptModel[]> GetLastReceipts(int number)
        {
            var receiptCollection = new ReceiptModel[number];

            for (int i = 0; i < number; i++)
            {
                receiptCollection[i] = new ReceiptModel
                {
                    Id       = Guid.NewGuid(),
                    Number   = $"{i}",
                    Articles = "",
                    Discount = 0,
                    Summ     = 0
                };
                await Task.Delay(10); // Типо ждём, пока база вернёт чек.
            }
            return(receiptCollection);
        }
Exemple #2
0
 public async Task <int> SaveReceipt(ReceiptModel receipt)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         var    cmd     = new StringBuilder();
         string command = "exec save_cheques @id, @number, @summ, @discount, @articles";
         ;
         return(await connection.ExecuteAsync(command, new
         {
             id = receipt.Id,
             number = receipt.Number,
             summ = receipt.Summ,
             discount = receipt.Discount,
             articles = String.Join(";", receipt.Articles)
         }));
     }
 }
Exemple #3
0
        public async Task <int> SaveReceipt(ReceiptModel receipt)
        {
            int rows;

            try
            {
                using (var writer = new StreamWriter(Path.Combine(_pathToRepo, $"{DateTime.Now.Ticks:X16}.txt")))
                {
                    await writer.WriteAsync(JsonConvert.SerializeObject(receipt));
                }
                rows = 1;
            }
            catch (Exception)
            {
                rows = 0;
            }

            return(rows);
        }