public IActionResult Dodaj([FromBody] KupiDodaj x)
        {
            Narudzba narudzba = new Narudzba()
            {
                CijenaDostave        = 10,
                DostavaAdresa        = x.dostavaAdresa + " " + x.dostavaGrad,
                DostavaIme           = x.dostavaIme,
                DostavaOpstinaID     = null,
                DostavaPostanskiBroj = "",
                DostavaTelefon       = x.dostavaTelefon,
                Napomena             = "",
                DatumNarudzbe        = DateTime.Now,
                KupacID = 1,
            };
            Proizvod proizvod = _dbContext.Proizvod.Find(x.ProizvodId);


            narudzba.IznosNarudzbe = x.Kolicina * proizvod.Cijena;


            NarudzbaStavka stavka = new NarudzbaStavka();

            stavka.Kolicina   = x.Kolicina;
            stavka.ProizvodID = x.ProizvodId;
            stavka.Narudzba   = narudzba;

            _dbContext.Add(narudzba);
            _dbContext.Add(stavka);

            _dbContext.SaveChanges();
            return(Ok(new { poruka = "uspješno" }));
        }
Example #2
0
        public static void ChangeQuantityInCart(int GotoviProizvodID, int Kolicina)
        {
            NarudzbaStavka exist = stavkeNarudzbe.Find(x => x.GotoviProizvodID == GotoviProizvodID);

            if (exist != null)
            {
                stavkeNarudzbe.Find(x => x.GotoviProizvodID == GotoviProizvodID).Kolicina = Kolicina;
            }
        }
Example #3
0
        public async Task <IActionResult> Confirm(string data, string userId)
        {
            var items = JsonConvert.DeserializeObject <Dictionary <string, string> >(data);

            if (items.Count == 0)
            {
                return(Content("Korpa je prazna"));
            }

            var check = CheckItems(items);

            if (check != null)
            {
                return(Content("Greška: Na stanju je trenutno " + check.Kolicina + " komada za proizvod "
                               + check.NazivProizvoda));
            }

            var user = await _userManager.FindByIdAsync(userId);

            var order = new Narudzba()
            {
                Aktivna = true,
                DatumKreiranjaNarudzbe = DateTime.Now,
                NaruciocId             = user.Id,
                Potvrdjena             = false,
                DostavljacId           = 1
            };

            var orderResult = await _context.Narudzba.AddAsync(order);

            await _context.SaveChangesAsync();

            foreach (var item in items)
            {
                for (int i = 0; i < int.Parse(item.Value); i++)
                {
                    var stavka = new NarudzbaStavka()
                    {
                        NarudzbaId = orderResult.Entity.Id,
                        ProizvodId = int.Parse(item.Key)
                    };
                    await _context.NarudzbaStavka.AddAsync(stavka);
                }
                await _context.SaveChangesAsync();
            }

            await _context.SaveChangesAsync();

            return(Content(""));
        }
Example #4
0
        public static void AddToCart(int GotoviProizvodID, int Kolicina)
        {
            NarudzbaStavka ns = stavkeNarudzbe.Find(x => x.GotoviProizvodID == GotoviProizvodID);

            if (ns != null)
            {
                stavkeNarudzbe.Find(x => x.GotoviProizvodID == GotoviProizvodID).Kolicina += 1;
            }
            else
            {
                stavkeNarudzbe.Add(new NarudzbaStavka()
                {
                    Kolicina         = Kolicina,
                    GotoviProizvodID = GotoviProizvodID,
                });
            }
        }
        public IActionResult Obrisi(int id, int narudzbaID)
        {
            NarudzbaStavka ns = ctx.NarudzbaStavka.Find(id);

            ctx.NarudzbaStavka.Remove(ns);
            ctx.SaveChanges();

            Narudzba a          = ctx.Narudzba.Find(narudzbaID);
            int      brojStavki = ctx.NarudzbaStavka.Where(x => x.NarudzbaId == a.Id).Count();

            if (brojStavki < 1)
            {
                Narudzba narudzbaZaBrisanje = ctx.Narudzba.Find(a.Id);
                ctx.Narudzba.Remove(narudzbaZaBrisanje);
                ctx.SaveChanges();

                //HttpContext.SetAKtivnaNarudzba(null);
            }


            return(RedirectToAction("Index", "NarudzbaStavke"));
        }
Example #6
0
        public IActionResult ProvjeraKolicine(int ProizvodId, int kol, int BojaID, int Brojac, int?Popust)
        {
            if (ModelState.IsValid)
            {
                if (Popust == null)
                {
                    Popust = 0;
                }
                Proizvod          p  = ctx.Proizvod.Find(ProizvodId);
                ProizvodSkladiste ps = ctx.ProizvodSkladiste.Where(x => x.ProizvodId == p.Id).First();


                Korisnik k = HttpContext.GetLogiraniKorisnik();
                if (k == null)
                {
                    return(RedirectToAction("Index", "Autentifikacija"));
                }

                Kupac kupacLogiran = ctx.Kupac.Where(x => x.KorisnikId == k.Id).FirstOrDefault();


                Narudzba aktivna   = null;
                int      aktivnaBr = ctx.Narudzba.Where(x => x.KupacId == kupacLogiran.Id && x.Aktivna == true).Count();
                if (aktivnaBr > 0)
                {
                    aktivna = ctx.Narudzba.Where(x => x.KupacId == kupacLogiran.Id && x.Aktivna == true).First();
                }


                if (ps.Kolicina >= kol)
                {
                    if (aktivna == null)
                    {
                        //int brojNarudzbe = 1;
                        if (ctx.Narudzba.Count() > 0)
                        {
                            broj = Convert.ToInt32(ctx.Narudzba.Last().BrojNarudzbe) + 1;
                        }

                        Narudzba n = new Narudzba
                        {
                            BrojNarudzbe = broj.ToString(),
                            Datum        = DateTime.Now,
                            Status       = true,
                            Otkazano     = false,
                            Aktivna      = true,
                            NaCekanju    = false,
                            KupacId      = kupacLogiran.Id
                        };
                        ctx.Narudzba.Add(n);
                        ctx.SaveChanges();

                        // TempData["error_poruka"] = "Proizvod uspješno dodat!";

                        NarudzbaStavka ns = new NarudzbaStavka
                        {
                            Kolicina        = kol,
                            ProizvodId      = ProizvodId,
                            NarudzbaId      = n.Id,
                            BojaId          = BojaID,
                            CijenaProizvoda = p.Cijena,
                            PopustNaCijenu  = (int)Popust,
                            //TotalStavke=p.Cijena*kol
                            TotalStavke = (p.Cijena - (p.Cijena * (decimal)Popust / 100)) * kol
                        };
                        ctx.NarudzbaStavka.Add(ns);
                        //broj++;
                        ps.Kolicina -= kol;


                        // HttpContext.SetAKtivnaNarudzba(n);
                    }
                    else
                    {
                        Narudzba n1      = ctx.Narudzba.Where(n => n.KupacId == kupacLogiran.Id && n.Id == aktivna.Id).First();
                        bool     postoji = false;

                        foreach (var x in ctx.NarudzbaStavka.Where(x => x.NarudzbaId == n1.Id).ToList())
                        {
                            if (x.ProizvodId == ProizvodId && x.BojaId == BojaID)
                            {
                                NarudzbaStavka nsUpdate = ctx.NarudzbaStavka.Where(y => y.Id == x.Id).First();
                                nsUpdate.Kolicina += kol;
                                ctx.SaveChanges();
                                ps.Kolicina         -= kol;
                                nsUpdate.TotalStavke = (p.Cijena - (p.Cijena * (decimal)Popust / 100)) * nsUpdate.Kolicina;
                                postoji = true;
                            }
                        }

                        if (!postoji)
                        {
                            ctx.NarudzbaStavka.Add(new NarudzbaStavka
                            {
                                Kolicina        = kol,
                                ProizvodId      = ProizvodId,
                                NarudzbaId      = n1.Id,
                                BojaId          = BojaID,
                                CijenaProizvoda = p.Cijena,
                                PopustNaCijenu  = Popust ?? 0,
                                TotalStavke     = (p.Cijena - (p.Cijena * (decimal)Popust / 100)) * kol
                            });
                            ps.Kolicina -= kol;
                        }
                    }
                    ctx.SaveChanges();
                    return(RedirectToAction("Index", "NarudzbaStavke"));
                }
                //return RedirectToAction("Index", "NarudzbaStavke");
                return(RedirectToAction("Detalji", new { @proizvodId = ProizvodId, @brojac = Brojac }));
            }
            else
            {
                //TempData["error_poruka"] = "Prozvoda nema na stanju u datoj količini!";
                return(RedirectToAction("Detalji", new { @proizvodId = ProizvodId, @brojac = Brojac }));
            }
        }
Example #7
0
 public StavkaPresenter(NarudzbaStavka stavka)
 {
     this.model = stavka;
 }