Example #1
0
        public ActionResult Edit(Pitanje pitanje)
        {
            if (ModelState.IsValid)
            {
                ViewBag.K = db.Parametris.FirstOrDefault().K;
                if (pitanje.Zakljucano == true)
                {
                    pitanje.VrPoslZaklj = DateTime.Now;
                }

                int K            = (int)db.Parametris.FirstOrDefault <Parametri>().K;
                int tacanOdgovor = Convert.ToInt32(Request["radioPonudjeno"]);
                for (int i = 0; i < K; i++)
                {
                    string tekstPonudjenog = Request["ponudjeno" + i].ToString();
                    if (tekstPonudjenog == "")
                    {
                        ModelState.AddModelError(string.Empty, "Uneti ponudjene odgovore");
                        pitanje.PonudjeniOdgs = db.PonudjeniOdgs.Where(p => p.IdPit == pitanje.IdPit).ToList();
                        return(View(pitanje));
                    }
                    PonudjeniOdg ponudjeni = db.PonudjeniOdgs.Where(p => p.IdPit == pitanje.IdPit).Where(p => p.RedniBr == i).FirstOrDefault();
                    ponudjeni.Sadrzaj = tekstPonudjenog;
                    ponudjeni.Tacan   = (i == tacanOdgovor ? true : false);

                    db.Entry(ponudjeni).State = EntityState.Modified;
                }

                db.Entry(pitanje).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.IdKor = new SelectList(db.Korisniks, "IdKor", "Ime", pitanje.IdKor);
            return(View(pitanje));
        }
Example #2
0
        private void CloseChannels()
        {
            List <Kanal> kanals = db.Kanals.Where(p => p.VrOgranicen == true).Where(p => p.Status == "Otvoren").ToList();

            foreach (var kanal in kanals)
            {
                TimeSpan minutesPast = DateTime.Now - kanal.VrOtvaranja;
                if (minutesPast.TotalMinutes > kanal.IntervalTrajanja)
                {
                    kanal.VrZatvaranja = kanal.VrOtvaranja.AddMinutes((double)kanal.IntervalTrajanja);
                    kanal.Status       = "Zatvoren";

                    db.Entry(kanal).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
Example #3
0
 public ActionResult Edit([Bind(Include = "IdNar,BrTokena,Cena,Status,IdKor")] Narudzbina narudzbina)
 {
     if (ModelState.IsValid)
     {
         db.Entry(narudzbina).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IdKor = new SelectList(db.Korisniks, "IdKor", "Ime", narudzbina.IdKor);
     return(View(narudzbina));
 }
Example #4
0
        public ActionResult Edit(Korisnik korisnik)
        {
            if (Session["uloga"] == null || Session["uloga"].ToString() != "admin")
            {
                return(RedirectToAction("UnauthorizedAccess", "Home"));
            }

            korisnik.PotvrdaLozinke  = korisnik.Lozinka;
            db.Entry(korisnik).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Registrations", "Home"));
        }
Example #5
0
 public ActionResult Edit([Bind(Include = "IdKlo,Naslov,Tekst,Slika,VrPravljenja,VrPoslZaklj,Zakljucano,IdPit,IdKan")] Klon klon)
 {
     if (ModelState.IsValid)
     {
         db.Entry(klon).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IdKan = new SelectList(db.Kanals, "IdKan", "Naziv", klon.IdKan);
     ViewBag.IdPit = new SelectList(db.Pitanjes, "IdPit", "Naslov", klon.IdPit);
     return(View(klon));
 }
Example #6
0
        public ActionResult CentiliReturn(string status)
        {
            if (Session["uloga"] == null || Session["uloga"].ToString() == "admin")
            {
                return(RedirectToAction("UnauthorizedAccess"));
            }

            using (baza db = new baza())
            {
                string     email      = Session["email"].ToString();
                Korisnik   korisnik   = db.Korisniks.Where(a => a.Email == email).FirstOrDefault <Korisnik>();
                Narudzbina narudzbina = db.Narudzbinas.Where(a => a.IdKor == korisnik.IdKor).OrderByDescending(x => x.IdNar).FirstOrDefault();

                if (status == "success")
                {
                    narudzbina.Status          = "realizovana";
                    db.Entry(narudzbina).State = System.Data.Entity.EntityState.Modified;

                    korisnik.BrTokena        = korisnik.BrTokena + narudzbina.BrTokena;
                    korisnik.PotvrdaLozinke  = korisnik.Lozinka;
                    db.Entry(korisnik).State = System.Data.Entity.EntityState.Modified;

                    db.SaveChanges();

                    SendEmail();
                    return(RedirectToAction("Tokens"));
                }
                else
                {
                    narudzbina.Status          = "ponistena";
                    db.Entry(narudzbina).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("FailedPurchase"));
                }
            }
        }
Example #7
0
        public ActionResult Edit([Bind(Include = "IdPar,K,M,E,S,G,P")] Parametri parametri)
        {
            if (Session["uloga"] == null || Session["uloga"].ToString() != "admin")
            {
                return(RedirectToAction("UnauthorizedAccess", "Home"));
            }

            if (ModelState.IsValid)
            {
                db.Entry(parametri).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            return(View(parametri));
        }
Example #8
0
        public ActionResult Register(Korisnik korisnik)
        {
            if (ModelState.IsValid)
            {
                using (baza db = new baza())
                {
                    try
                    {
                        if (db.Korisniks.Where(p => p.Email == korisnik.Email).FirstOrDefault() != null)
                        {
                            ModelState.AddModelError(string.Empty, "Email je zauzet!");
                            return(View(korisnik));
                        }
                        PasswordHasher hasher = new PasswordHasher();
                        korisnik.Lozinka         = hasher.HashPassword(korisnik.Lozinka);
                        korisnik.PotvrdaLozinke  = korisnik.Lozinka;
                        korisnik.Status          = "neaktivan";
                        db.Entry(korisnik).State = System.Data.Entity.EntityState.Modified;

                        db.Korisniks.Add(korisnik);
                        db.SaveChanges();

                        return(RedirectToAction("Login"));
                    }
                    catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                    {
                        Exception raise = dbEx;
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                string message = string.Format("{0}:{1}",
                                                               validationErrors.Entry.Entity.ToString(),
                                                               validationError.ErrorMessage);
                                // raise a new exception nesting
                                // the current instance as InnerException
                                raise = new InvalidOperationException(message, raise);
                            }
                        }
                        throw raise;
                    }
                }
            }

            return(View(korisnik));
        }