public void Execute(CreatePorudzbinaDto request)
        {
            _validator.ValidateAndThrow(request);
            int idKlijent  = _actor.Id;
            var porudzbina = new Porudzbina
            {
                DatumPorudzbine = request.PorudzbinaDatum,
                KlijentId       = idKlijent,
                Adresa          = request.Adresa
            };

            foreach (var i in request.Items)
            {
                var cena                 = _context.Cene.Find(i.IdCena);
                var proizvod             = _context.Proizvodi.Find(i.ProizvodId);
                var konacnaCenaProizvoda = cena.CenaP;
                proizvod.KolicinaProizvoda -= i.Kolicina;
                porudzbina.DetaljiPorudzbina.Add(new DetaljiPorudzbine
                {
                    Naziv      = proizvod.NazivProizvoda,
                    Kolicina   = i.Kolicina,
                    Cena       = konacnaCenaProizvoda,
                    ProizvodId = i.ProizvodId
                });
                _context.Porudzbine.Add(porudzbina);
                _context.SaveChanges();
            }
        }
Example #2
0
 public Porudzbina SelectObject(Porudzbina objekat)
 {
     try
     {
         _broker.OpenConnection();
         _broker.BeginTransaction();
         Porudzbina porudzbina = _broker.SelectObjectJoin(objekat) as Porudzbina;
         porudzbina.Stavke = _broker.ReturnByCriteriaJoin($"WHERE SifraPorudzbine={porudzbina.Id}", new StavkaPorudzbine()).OfType <StavkaPorudzbine>().ToList();
         _broker.Commit();
         return(porudzbina);
     }
     catch (SqlException ex)
     {
         Debug.Write(">>>>>>>> " + ex.Message);
         _broker.Rollback();
         throw new Exception(ex.Message);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(">>>> " + ex.Message);
         _broker.Rollback();
         throw new Exception(ex.Message);
     }
     finally
     {
         _broker.CloseConnection();
     }
 }
Example #3
0
 public List <Porudzbina> SelectAll(Porudzbina objekat)
 {
     try
     {
         _broker.OpenConnection();
         _broker.BeginTransaction();
         List <Porudzbina> list = _broker.SelectAllJoin(objekat).OfType <Porudzbina>().ToList();
         _broker.Commit();
         return(list);
     }
     catch (SqlException ex)
     {
         Debug.Write(">>>>>>>> " + ex.Message);
         _broker.Rollback();
         throw new Exception(ex.Message);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(">>>> " + ex.Message);
         _broker.Rollback();
         throw new Exception(ex.Message);
     }
     finally
     {
         _broker.CloseConnection();
     }
 }
Example #4
0
        //-----------------------------------------OnPostPostvrdi------------------------------------------------
        public async Task <IActionResult> OnPostPotvrdi(InputBuyConfirmed BuyConfirmed)
        {
            if (ModelState.IsValid)
            {
                string userId = signInManager.UserManager.GetUserId(User);

                Porudzbina porudzbina = new Porudzbina
                {
                    UserId                = userId,
                    VremePosiljke         = DateTime.Now,
                    BrojPorucenihStripova = BuyConfirmed.IdPorucenihStripova.Count,
                    Pitanje               = BuyConfirmed.Pitanje,
                    Grad          = BuyConfirmed.Grad,
                    KucniBroj     = BuyConfirmed.KucniBroj,
                    Placanje      = BuyConfirmed.Placanje,
                    UkupnaCena    = BuyConfirmed.UkupnaCena,
                    Ulica         = BuyConfirmed.Ulica,
                    PostanskiBroj = BuyConfirmed.PostanskiBroj.Value,
                    Status        = "Pakovanje"
                };
                await porudzbinaRepository.AddPorudzbinu(porudzbina, BuyConfirmed.IdPorucenihStripova);

                await korpaRepository.DeleteSveUKorpi(userId);

                TempData["message"] = "Uspesno ste izvrsili porudzbinu!";
                return(RedirectToPage("Index"));
            }

            await GetSveInformacije();

            return(Page());
        }
Example #5
0
        private void Ukupno_Click(object sender, EventArgs e)
        {
            try
            {
                ISession sesija = DataLayer.GetSession();

                Porudzbina p = sesija.Load <Porudzbina>(13);

                MessageBox.Show("Narudzbina broj: " + p.Idp + "\n");
                string podaci = "";
                int    ukupno = 0;
                int    cena   = 0;
                foreach (Sadrzi podatak in p.Sadrzaj)
                {
                    Pizza         pizza    = podatak.PizzaId;
                    VelicinaPizze velicina = podatak.VelicinaId;
                    podaci += pizza.Naziv + " cena: " + pizza.Cena + " velicina: " + velicina.Velicina + " bodovi: " + velicina.Bodovi + "\n";
                    ukupno += velicina.Bodovi;
                    cena   += pizza.Cena;
                }
                MessageBox.Show(podaci + "\nUkupna cena: " + cena + "\nUkupno bodova: " + ukupno);

                sesija.Close();
            }
            catch (Exception exc) { MessageBox.Show(exc.Message); }
        }
        public void Izvrsi(NapraviPorudzbinuDto dto)
        {
            _validator.ValidateAndThrow(dto);

            var korisnikId = 4;

            var porudzbina = new Porudzbina
            {
                KorisnikId      = korisnikId,
                Adresa          = dto.Adresa,
                VremePorudzbine = dto.VremePorudzbine,
            };

            foreach (var item in dto.StavkePorudzbine)
            {
                var product = _context.Proizvodi.Find(item.ProizvodId);

                product.Kolicina -= item.Kolicina;

                porudzbina.StavkaPorudzbine.Add(new StavkaPorudzbine
                {
                    ProizvodId = item.ProizvodId,
                    Kolicina   = item.Kolicina,
                    Naziv      = product.Naziv,
                    Cena       = product.Cena
                });
            }

            _context.Porudzbine.Add(porudzbina);

            _context.SaveChanges();
        }
Example #7
0
        public async Task <Porudzbina> DodajPorudzbinu(Porudzbina d)
        {
            var porudzbina = unitOfWork.PorudzbinaRepository.Add(d);
            await unitOfWork.Commit();

            return(porudzbina);
        }
Example #8
0
 public List <Porudzbina> SelectByCriteria(string criteria, Porudzbina objekat)
 {
     try
     {
         _broker.OpenConnection();
         _broker.BeginTransaction();
         List <Porudzbina> porudzbine = _broker.ReturnByCriteriaJoin(criteria, objekat).OfType <Porudzbina>().ToList();
         _broker.Commit();
         return(porudzbine);
     }
     catch (SqlException ex)
     {
         Debug.Write(">>>>>>>> " + ex.Message);
         _broker.Rollback();
         throw new Exception(ex.Message);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(">>>> " + ex.Message);
         _broker.Rollback();
         throw new Exception(ex.Message);
     }
     finally
     {
         _broker.CloseConnection();
     }
 }
Example #9
0
        public void Execute(PravljenjePorudzbineDto request)
        {
            validator.ValidateAndThrow(request);
            int IdKorisnik = actor.Id;
            var porudzbina = new Porudzbina
            {
                IdKorisnik      = IdKorisnik,
                Adresa          = request.Adresa,
                DatumPorudzbine = request.DatumPorudzbine
            };

            foreach (var item in request.Stavke)
            {
                var proizvod     = _context.Proizvodi.Find(item.IdProduct);
                var cena         = _context.Cenovnici.Find(item.IdCenovnik);
                var CenaProizvod = cena.CenaProizvod;
                proizvod.Kolicina -= item.Kolicina;
                porudzbina.DetaljiPorudzbina.Add(new DetaljiPorudzbine
                {
                    NazivProizvoda = proizvod.Naziv,
                    Kolicina       = item.Kolicina,
                    Cena           = CenaProizvod,
                    IdProizvod     = item.IdProduct,
                });;
            }
            _context.Porudzbine.Add(porudzbina);
            _context.SaveChanges();
        }
Example #10
0
        public async Task UpisPorudzbine(int idRestoran, [FromBody] Porudzbina porudzbina)
        {
            var restoran = await Context.Restorani.FindAsync(idRestoran);

            porudzbina.Restoran = restoran;
            Context.Porudzbine.Add(porudzbina);
            await Context.SaveChangesAsync();
        }
 public void Update(Porudzbina entity)
 {
     using (var db = new Entities())
     {
         db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
 public void Insert(Porudzbina entity)
 {
     using (var db = new Entities())
     {
         db.Porudzbinas.Add(entity);
         db.SaveChanges();
     }
 }
        public Porudzbina GetById(string id)
        {
            using (var db = new Entities())
            {
                Porudzbina porudzbina = db.Porudzbinas.Where(p => p.ID.Equals(id)).Include(x => x.Nalazi_se).FirstOrDefault();

                return(porudzbina);
            }
        }
Example #14
0
        public async Task AzurirajPorudzbinu(Porudzbina p)
        {
            Porudzbina porudzbina = unitOfWork.PorudzbinaRepository.Get(p.Id);

            if (porudzbina != null)
            {
                unitOfWork.PorudzbinaRepository.Update(p);
                await unitOfWork.Commit();
            }
        }
        public IHttpActionResult PostPorudzbina(Porudzbina porudzbina)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _manager.Insert(porudzbina);
            return(Ok(porudzbina));
        }
        public void Delete(string id)
        {
            using (var db = new Entities())
            {
                Porudzbina porudzbina = db.Porudzbinas.Where(p => p.ID.Equals(id)).FirstOrDefault();

                db.Entry(porudzbina).State = System.Data.Entity.EntityState.Deleted;
                db.SaveChanges();
            }
        }
Example #17
0
        public async Task ObrisiPorudzbinu(int id)
        {
            Porudzbina p = unitOfWork.PorudzbinaRepository.Get(id);

            if (p != null)
            {
                unitOfWork.PorudzbinaRepository.Delete(p);
                await unitOfWork.Commit();
            }
        }
Example #18
0
 private void ListBox1_SelectedPorudzbina(object sender, EventArgs e)
 {
     if (listBox1.SelectedValue != null && listBox1.DataSource != null)
     {
         Porudzbina p = Client.vratiPorudzbinu(int.Parse(listBox1.SelectedValue.ToString()));
         tbPorudzbineIDKnjige.Text    = p.Id_knjige.ToString();
         tbPorudzbineIDKorisnika.Text = p.Id_korisnika.ToString();
         tbPorudzbineKolicina.Text    = p.Kolicina.ToString();
     }
 }
        public IHttpActionResult GetPorudzbina(string id)
        {
            Porudzbina porudzbina = _manager.GetById(id);

            if (porudzbina == null)
            {
                return(NotFound());
            }

            return(Ok(porudzbina));
        }
Example #20
0
        public void Insert(Porudzbina entity)
        {
            if (entity.ID == null)
            {
                entity.ID = Guid.NewGuid().ToString();
            }

            entity.DAT = DateTime.Now;

            _provider.Insert(entity);
        }
Example #21
0
 public bool Update(Porudzbina entity)
 {
     if (_provider.GetById(entity.ID) == null)
     {
         return(false);
     }
     else
     {
         _provider.Update(entity);
         return(true);
     }
 }
        public void Update(Dostava entity)
        {
            using (var db = new Entities())
            {
                db.Entry(entity).State = System.Data.Entity.EntityState.Modified;

                Porudzbina por = db.Porudzbinas.Where(p => p.ID.Equals(entity.ID)).FirstOrDefault();
                db.Entry(por).State = System.Data.Entity.EntityState.Modified;

                db.SaveChanges();
            }
        }
        protected override void IzvrsiKonkretnuOperaciju(IDomenskiObjekat objekat)
        {
            Porudzbina porudzbina = (Porudzbina)objekat;

            broker.Sacuvaj(porudzbina);
            Porudzbina = porudzbina;
            foreach (StavkaPorudzbine sp in porudzbina.StavkePorudzbine)
            {
                sp.SifraPorudzbine = broker.VratiID(porudzbina);
                broker.Sacuvaj(sp);
            }
        }
        public async Task <IActionResult> Index()
        {
            Korpa korpa = kServis.CitajKorpu();

            if (korpa.Stavke.Count() == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ApplicationUser user = await um.GetUserAsync(User);

            string     id = user.Id;
            Porudzbina p1 = new Porudzbina {
                KupacId       = id,
                DatumKupovine = DateTime.Now
            };

            decimal ukupnaCena = 0;

            try
            {
                db.Porudzbine.Add(p1);
                db.SaveChanges();
                int pId = p1.PorudzbinaId;

                foreach (StavkaKorpe st in korpa.Stavke)
                {
                    Stavka st1 = new Stavka {
                        PorudzbinaId = pId,
                        ProizvodId   = st.Proizvod.ProizvodId,
                        Kolicina     = st.Kolicina
                    };

                    ukupnaCena = st.Proizvod.Cena * st.Kolicina + ukupnaCena;

                    db.Stavke.Add(st1);
                    db.SaveChanges();
                }

                kServis.ObrisiKorpu();

                ViewBag.UkupnaCena = ukupnaCena;

                return(View(korpa));
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        private void KreirajPorudzbinu(List <Pizza> pizzeZaDodati)
        {
            _porudzbina = new Porudzbina();
            _porudzbina.KreirajPorucioca();

            foreach (Pizza element in pizzeZaDodati)
            {
                _porudzbina.Pizze.Add(new PorucenaPizza()
                {
                    Velicina = element.Velicina(), Kora = element.Kora(), Zacini = imaLiDodataka(element), Cena = element.Cena()
                });

                _porudzbina.Cena += element.Cena();
            }
        }
Example #26
0
        public void Prikaz(int idPorudzbine)
        {
            porudzbina = db.Porudzbine.Find(idPorudzbine);

            Console.WriteLine("\nBroj porudzbine: {0}\n\nNarucilac: {1}\nTelefon: {2}\nAdressa: {3}\nDatum: {4}", porudzbina.PorudzbinaId, porudzbina.PorucilacIme, porudzbina.Telefon, porudzbina.Adressa, porudzbina.Datum);

            Console.WriteLine();
            foreach (PorucenaPizza element in db.Pizze.Where(p => p.PorudzbinaId == idPorudzbine))
            {
                Console.WriteLine("{0} --- {1} --- {2} --- {3:C}", element.Velicina, element.Kora, element.Zacini, element.Cena);
            }

            Console.WriteLine("\nUkupno za uplatu: {0:C}", porudzbina.Cena);
            Console.WriteLine("------------------------------------------------");
        }
        private Porudzbina ValidacijaPorudzbine(Label lblDatumPorudzbine, TextBox txtRok, TextBox txtUkupanIznos, DataGridView dgvProizvodi, Label lblRokPrispeca)
        {
            Porudzbina porudzbina = new Porudzbina();
            bool       dobro      = true;

            porudzbina.DatumPorudzbine = DateTime.Now;

            if (int.TryParse(txtRok.Text, out int brDana))
            {
                porudzbina.RokPrispeca = porudzbina.DatumPorudzbine.AddDays(brDana);
            }
            else
            {
                dobro = false;
                MessageBox.Show("Unesite ponovo broj dana.");
                lblRokPrispeca.ForeColor = Color.FromArgb(250, 62, 62);
            }

            if (double.TryParse(txtUkupanIznos.Text, out double ukupno))
            {
                porudzbina.UkupanIznos = ukupno;
            }
            else
            {
                dobro = false;
                MessageBox.Show("Greska prilikom upisa ukupnog iznosa.");
                txtUkupanIznos.ForeColor = Color.FromArgb(250, 62, 62);
            }

            Korisnik k = FrmGlavnaFormaKorisnik.k;

            porudzbina.Korisnik1 = k;
            try
            {
                porudzbina.StavkePorudzbine = listaStavkiBinding.ToList();
            }
            catch (Exception)
            {
                dobro = false;
                MessageBox.Show("Greska sa listom stavki.");
            }

            if (!dobro)
            {
                return(null);
            }
            return(porudzbina);
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Porudzbina = await _context.Porudzbina
                         .Include(p => p.User).FirstOrDefaultAsync(m => m.IdPorudzbine == id);

            if (Porudzbina == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Example #29
0
        public async Task <IActionResult> Index()
        {
            Narucivanje narucivanje = nServis.CitajSpisak();

            if (narucivanje.Kartas.Count() == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ApplicationUser user = await um.GetUserAsync(User);

            string     id = user.Id;
            Porudzbina p1 = new Porudzbina
            {
                KorisnikId       = id,
                DatumPorucivanja = DateTime.Now
            };

            try
            {
                db.Porudzbina.Add(p1);
                db.SaveChanges();
                int pId = p1.PorudzbinaId;

                foreach (NarucenaKarta kr in narucivanje.Kartas)
                {
                    Karta kr1 = new Karta
                    {
                        PorudzbinaId = pId,
                        PredstavaId  = kr.Predstava.PredstavaId,
                        Kolicina     = kr.Kolicina
                    };

                    db.Karta.Add(kr1);
                    db.SaveChanges();
                }


                nServis.ObrisiSpisak();

                return(View());
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Porudzbina = await _context.Porudzbina.FindAsync(id);

            if (Porudzbina != null)
            {
                _context.Porudzbina.Remove(Porudzbina);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }