Esempio n. 1
0
        private static int MAX_AUCTIONS_PER = 100; // proizvoljan broj

        static void Main(string[] args)
        {
            using (Prodavnica DB = new Prodavnica())
            {
                using (var ContextTransaction = DB.Database.BeginTransaction())
                {
                    try
                    {
                        var UniversalNow         = DateTime.UtcNow;
                        var OpenFinishedAuctions = DB.Auctions.Where(a => a.ClosedAt != null && a.ClosedAt <= UniversalNow && a.State == AuctionState.Opened).Take(MAX_AUCTIONS_PER);

                        // Za svaku aukciju
                        foreach (Auction Auction in OpenFinishedAuctions)
                        {
                            // mark the auction as closed
                            Auction.State           = AuctionState.Closed;
                            DB.Entry(Auction).State = System.Data.Entity.EntityState.Modified;
                        }

                        DB.SaveChanges();
                        ContextTransaction.Commit();
                    }
                    catch (Exception)
                    {
                        ContextTransaction.Rollback();
                    }
                }
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Prodavnica prodavnica = db.Prodavnica.Find(id);

            db.Prodavnica.Remove(prodavnica);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "RbUnosa,BarKodArtikla,Kolicina,datum,Vreme")] Prodavnica prodavnica)
 {
     if (ModelState.IsValid)
     {
         db.Entry(prodavnica).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BarKodArtikla = new SelectList(db.Proizvod, "BarKodArtikla", "Naziv", prodavnica.BarKodArtikla);
     return(View(prodavnica));
 }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Prodavnica prodavnica = db.Prodavnica.Find(id);

            if (prodavnica == null)
            {
                return(HttpNotFound());
            }
            return(View(prodavnica));
        }
        // GET: Prodavnicas/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Prodavnica prodavnica = db.Prodavnica.Find(id);

            if (prodavnica == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BarKodArtikla = new SelectList(db.Proizvod, "BarKodArtikla", "Naziv", prodavnica.BarKodArtikla);
            return(View(prodavnica));
        }
        public IActionResult kreirajPrpdavnicu(Prodavnica p)
        {
            var connectionString = "mongodb://localhost/?safe=true";

            var client   = new MongoClient(connectionString);
            var database = client.GetDatabase("Ishop");
            //baza je webshop a kolecije
            //podavnice
            //proizvodi

            var prodavniceCollection = database.GetCollection <Prodavnica>("prodavnice");

            prodavniceCollection.InsertOne(p);

            return(RedirectToAction("prikaziProdavnice"));
        }
Esempio n. 7
0
        public static void Testiranje()
        {
            TrgovinskiLanac noviLanac = new TrgovinskiLanac();

            Prodavnica trafika     = new Prodavnica("Trafika 1", 1, trafikaStanje);
            Prodavnica apoteka     = new Prodavnica("Apoteka 2", 3, apotekaStanje);
            Prodavnica supermarket = new Prodavnica("SuperMarket", 2, proizvodi);

            noviLanac.DodajProdavnicu(trafika);
            noviLanac.DodajProdavnicu(apoteka);
            noviLanac.DodajProdavnicu(supermarket);

            Kupac t_k1 = new Kupac("John", "Doe", "225-883");
            Kupac t_k2 = new Kupac("Joe", "Bloggs", "883-225");

            Console.WriteLine("Stanje PRE kupovine!!!");
            Console.WriteLine(trafika.IspisiStanje());
            //Console.WriteLine(apoteka.IspisiStanje());
            //Console.WriteLine(supermarket.IspisiStanje());

            Console.WriteLine("___________________________________________________");
            Console.WriteLine("_________________KUPOVINA_________________");
            trafika.KreirajRacun(new List <Proizvod>()
            {
                new Proizvod("Sandwich", 3),
                new Proizvod("Chipsy", 2),
                new Proizvod("Caffetin", 3),
                new Proizvod("Coca-Cola", 3),
                new Proizvod("Crvena_zona", 10),
            }, t_k1);
            Console.WriteLine("___________________________________________________");
            Console.WriteLine("Stanje POSLE kupovine!!!");
            Console.WriteLine(trafika.IspisiStanje());


            Console.WriteLine("___________________________________________________");
            Console.WriteLine("_________________KUPOVINA 2_________________");
            trafika.KreirajRacun(new List <Proizvod>()
            {
                new Proizvod("Sandwich", 3),
            }, t_k2);
        }
Esempio n. 8
0
        public void SendBid(int Amount, int AuctionId, int UserId)
        {
            Bid  Bid  = null;
            User User = null;

            using (Prodavnica db = new Prodavnica())
            {
                var AuctionOnBid = db.Auctions.Find(AuctionId);
                var AuctionsBids = db.Bids.Where(a => a.AuctionId == AuctionId);
                var LoggedUser   = db.Users.Find(UserId);
                User = LoggedUser;

                if (LoggedUser == null)
                {
                    Clients.Caller.ReceiveError("User must be logged in!");
                    return;
                }

                // provera da li je aukcija istekla
                if (DateTime.UtcNow > AuctionOnBid.ClosedAt)
                {
                    Clients.Caller.ReceiveError("The auction has expired!");
                    return;
                }



                Bid newBid;
                using (var transactionContext = db.Database.BeginTransaction())
                {
                    // Maximum old bid
                    var MyBids    = db.Bids.Where(b => b.AuctionId == AuctionId && b.UserId == LoggedUser.Id);
                    int MaxOldBid = MyBids.Any() ? MyBids.Max(a => a.Amount) : 0;

                    int AmountToPay = Amount - MaxOldBid;

                    // ako je veci od najveceg ponudjenog
                    int?MaxBidAmount = AuctionsBids.Any() ? AuctionsBids.Max(a => a.Amount) : AuctionOnBid.StartPrice;

                    // Decrease users number of tokens
                    if (db.Users.Find(LoggedUser.Id).Tokens < AmountToPay)
                    {
                        Clients.Caller.ReceiveError("Not enough tokens!");
                    }
                    // provera da li je najveca
                    else if (Amount <= MaxBidAmount.GetValueOrDefault())
                    {
                        Clients.Caller.ReceiveError("New bid must be the highest!");
                    }
                    else
                    {
                        try
                        {
                            // vrati rezervisani novac
                            var OldHighestBId = AuctionsBids.OrderByDescending(a => a.Amount).FirstOrDefault();
                            if (OldHighestBId != null)
                            {
                                OldHighestBId.User.Tokens         += OldHighestBId.Amount;
                                db.Entry(OldHighestBId.User).State = EntityState.Modified;
                            }
                            // rezervisi stari novac
                            LoggedUser.Tokens         -= Amount;
                            db.Entry(LoggedUser).State = EntityState.Modified;

                            newBid = new Bid
                            {
                                AuctionId = AuctionId,
                                UserId    = LoggedUser.Id,
                                Amount    = Amount,
                                CreatedAt = DateTime.UtcNow
                            };

                            db.Bids.Add(newBid);
                            db.SaveChanges();
                            transactionContext.Commit();

                            // return to caller new balance
                            Clients.Caller.UpdateBalance(LoggedUser.Tokens);
                            // Return to all clients
                            Clients.All.ReceiveBid(Amount, User, newBid.CreatedAt.ToString());
                            Clients.All.NewPrice(Amount);
                            Clients.All.UpdatePrice(Amount, AuctionId);
                        }
                        catch (Exception)
                        {
                            transactionContext.Rollback();
                        }
                    }
                }
            }
        }
Esempio n. 9
0
 public async Task IzmeniPiceriju([FromBody] Prodavnica prodavnica)
 {
     Context.Update <Prodavnica>(prodavnica);
     await Context.SaveChangesAsync();
 }
Esempio n. 10
0
 public async Task UpisiProdavnicu([FromBody] Prodavnica prodavnica)
 {
     Context.Prodavnice.Add(prodavnica);
     await Context.SaveChangesAsync();
 }
Esempio n. 11
0
        protected override void Seed(Prodavnica context)
        {
            // Find with mail
            var UserToDelete = context.Users.Where(u => u.Email == "*****@*****.**").SingleOrDefault();

            if (UserToDelete != null)
            {
                context.Entry(UserToDelete).State = EntityState.Deleted;
                context.SaveChanges();
            }

            User firstUser = new User
            {
                Id       = 1,
                Name     = "Matija",
                Surname  = "Lukic",
                Email    = "*****@*****.**",
                Password = "******", // matija123
                Tokens   = 100,
                IsAdmin  = true,
            };

            context.Users.AddOrUpdate(firstUser);

            context.Users.AddOrUpdate(new User
            {
                Id       = 2,
                Name     = "Nemanja",
                Surname  = "Kojic",
                Email    = "*****@*****.**",
                Password = "******", // nemanja123
                Tokens   = 1000,
                IsAdmin  = false,
            });



            context.Auctions.AddOrUpdate(new Auction
            {
                Id         = 1,
                Name       = "Cola",
                Picture    = "https://www.coca-cola.rs/content/dam/GO/coca-cola/sebia/One%20Brand/coca-cola-logo-260x260.png",
                Duration   = 3600,
                StartPrice = 1,
                Price      = 1000,
                CreatedAt  = DateTime.Now,
                State      = "Ready",
                UserId     = firstUser.Id,
                WinnerId   = null,
            });

            context.Auctions.AddOrUpdate(new Auction
            {
                Id         = 2,
                Name       = "Fanta",
                Picture    = "https://www.coca-cola.rs/content/dam/GO/fanta-2gen/shared/logo/Logo_260x260.png",
                Duration   = 3600,
                StartPrice = 150,
                Price      = 900,
                CreatedAt  = DateTime.Now,
                State      = "Ready",
                UserId     = firstUser.Id,
                WinnerId   = null,
            });



            // Add settings
            context.Settings.AddOrUpdate(new Setting[] {
                new Setting {
                    Key = "N", Value = 20,
                },
                new Setting {
                    Key = "D", Value = 3600,
                },
                new Setting {
                    Key = "S", Value = 30,
                },
                new Setting {
                    Key = "G", Value = 50
                },
                new Setting {
                    Key = "P", Value = 100
                },
                new Setting {
                    Key = "C", Value = 0
                },                                   // 0 = RSD, 1 = EUR, 2 = USD
                new Setting {
                    Key = "T", Value = 20
                },
            });
        }
        public IActionResult idiNaKreirajProdavnicu()
        {
            Prodavnica p = new Prodavnica();

            return(View(p));
        }