Exemple #1
0
        public override async Task <BillPostResponse> AddBillBanka(BankaBillMsg request, ServerCallContext context)
        {
            _logger.LogInformation("Usao u dodavanje racuna koji je poslat bankom");
            await _context.Bills.ToListAsync();

            Bill racunBanka = _convert.ConvertBanka(request);

            racunBanka.WayOfSellingEnum = Bill.WayOfSelling.Banka;
            racunBanka.Barcode ??= string.Empty;
            try
            {
                _context.Bills.Add(racunBanka);
                await _context.SaveChangesAsync();

                return(new BillPostResponse {
                    IsUpisan = true, BillResponse = _convert.ConvertCeoRacun(racunBanka)
                });
            }
            catch (Exception ex)
            {
                _logger.LogInformation("Nije upisao!");
                _logger.LogError(ex.Message);
                return(new BillPostResponse {
                    IsUpisan = false
                });
            }
        }
Exemple #2
0
        public Bill ConvertBanka(BankaBillMsg racunBankaProto)     //saljem klijentu
        {
            Bill racunBanka = new Bill
            {
                Naziv           = racunBankaProto.Naziv,                      //Naziv artikla sta salje
                AdresaMusterije = racunBankaProto.AdresaMusterije,
                NabavnaCena     = racunBankaProto.NabavnaCena,                //Ono sto mu je uplaceno
                ProdajnaCena    = racunBankaProto.ProdajnaCena,               //Ono sto je podigao
                PresekStanja    = racunBankaProto.PresekStanja,               //KOliko mu je ostalo
                DatumSlanja     = racunBankaProto.DatumSlanja.ToDateTime(),   //kad je prodao
                DatumPrimanja   = racunBankaProto.DatumPrimanja.ToDateTime(), //kad je podigao novac
                ID = racunBankaProto.ID
            };

            return(racunBanka);
        }
Exemple #3
0
        public BankaBillMsg ConvertBanka(Bill racunBanka)     //saljem na server
        {
            BankaBillMsg racunBankaProto = new BankaBillMsg
            {
                Naziv           = racunBanka.Naziv,                                                               //Naziv artikla sta salje
                AdresaMusterije = racunBanka.AdresaMusterije,
                NabavnaCena     = racunBanka.NabavnaCena,                                                         //Ono sto mu je uplaceno
                ProdajnaCena    = racunBanka.ProdajnaCena,                                                        //Ono sto je podigao
                PresekStanja    = racunBanka.PresekStanja,                                                        //KOliko mu je ostalo
                DatumSlanja     = DateTime.SpecifyKind(racunBanka.DatumSlanja, DateTimeKind.Utc).ToTimestamp(),   //kad je prodao
                DatumPrimanja   = DateTime.SpecifyKind(racunBanka.DatumPrimanja, DateTimeKind.Utc).ToTimestamp(), //kad je podigao novac
                ID = racunBanka.ID
            };

            return(racunBankaProto);
        }
Exemple #4
0
        public override async Task <BillPostResponse> ChangeBillBanka(BankaBillMsg request, ServerCallContext context)
        {
            var comparativeBill = _context.Bills.Find(request.ID); //nasao ga u bazi

            _logger.LogInformation($"Nadjen je racun sa tim barcodom u bazi i barcode je {comparativeBill.ID}");

            if (comparativeBill is not null)
            {
                _logger.LogInformation("usao sam u if comparativeBill is not null");
                _logger.LogInformation("ovaj Bill sto sam poslao sam smestio u comparativeBill");
                try
                {
                    _logger.LogInformation("Usao sam u try da sacuvam to u bazu");

                    comparativeBill.Naziv           = _convert.ConvertBanka(request).Naziv;
                    comparativeBill.AdresaMusterije = _convert.ConvertBanka(request).AdresaMusterije;
                    comparativeBill.NabavnaCena     = _convert.ConvertBanka(request).NabavnaCena;
                    comparativeBill.ProdajnaCena    = _convert.ConvertBanka(request).ProdajnaCena;
                    comparativeBill.PresekStanja    = _convert.ConvertBanka(request).PresekStanja;
                    comparativeBill.DatumSlanja     = _convert.ConvertBanka(request).DatumSlanja;
                    comparativeBill.DatumPrimanja   = _convert.ConvertBanka(request).DatumPrimanja;
                    await _context.SaveChangesAsync();

                    return(new BillPostResponse {
                        BillResponse = _convert.ConvertCeoRacun(comparativeBill), IsUpisan = true
                    });
                }
                catch (Exception ex)
                {
                    _logger.LogError("Nije nasao racun u bazi da ga izmeni");
                    return(new BillPostResponse {
                        IsUpisan = false
                    });
                }
            }
            else
            {
                _logger.LogInformation("comparativeBill je null, nema takvog u bazi, ovo ne treba da se dogadja");
                return(new BillPostResponse {
                    IsUpisan = false
                });
            }
        }