public ActionResult LogIn(Anketa_Proekt.Models.Louse user)
        {
            //if (ModelState.IsValid)
            //{
            if (user.isValidUser(user.e_mail, user.lozinka))
            {
                //FormsAuthentication.SetAuthCookie(user.e_mail, true);
                //FormsAuthentication.SetAuthCookie()
                using (var db = new AnketiEntities5())
                {
                    var query = from a in db.Lice
                                where a.e_mail.Equals(user.e_mail) & a.lozinka.Equals(user.lozinka)
                                select a.id_lice;

                    int idLice = query.FirstOrDefault();

                    Session["id_lice"] = idLice;
                    return(RedirectToAction("Index", "Anketa"));
                }
            }
            else
            {
                ModelState.AddModelError("", "Login data is incorrect!");
            }
            //}
            return(View(user));
        }
        public ActionResult BuyPremium(Premium_Korisnik premiumKorsinik)
        {
            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    Premium_Korisnik premiumUser = db.Premium_Korisnik.Create();

                    premiumUser.id_lice = (int)Session["id_lice"];
                    premiumUser.datum_starts = DateTime.Today;
                    premiumUser.datum_end = DateTime.Today.AddMonths(12);

                    db.Premium_Korisnik.Add(premiumUser);

                    db.SaveChanges();

                    return RedirectToAction("CheckStatus", "User");
                }
            }
            else
            {
                return RedirectToAction("Index", "Anketa");
            }

            return View();
        }
示例#3
0
        // GET: /Anketa/Create
        public ActionResult Create()
        {
            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    List <SelectListItem> kategoriiLista = new List <SelectListItem>();

                    foreach (Kategorija k in db.Kategorijas)
                    {
                        SelectListItem selectList = new SelectListItem()
                        {
                            Text  = k.ime_k,
                            Value = k.id_k.ToString()
                        };

                        kategoriiLista.Add(selectList);
                    }

                    ViewBag.MyKategorii = kategoriiLista;

                    ViewBag.id_lice = new SelectList(db.Lice, "id_lice", "ime");
                }

                return(View());
            }

            return(RedirectToAction("Index"));
        }
        // GET: /Anketa/Create
        public ActionResult Create()
        {
            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    List<SelectListItem> kategoriiLista = new List<SelectListItem>();

                    foreach (Kategorija k in db.Kategorijas)
                    {
                        SelectListItem selectList = new SelectListItem()
                        {
                            Text = k.ime_k,
                            Value = k.id_k.ToString()
                        };

                        kategoriiLista.Add(selectList);
                    }

                    ViewBag.MyKategorii = kategoriiLista;

                    ViewBag.id_lice = new SelectList(db.Lice, "id_lice", "ime");
                }

                return View();
            }

            return RedirectToAction("Index");
        }
示例#5
0
        public ActionResult ZapisiGlas(Anketa anketa)
        {
            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    foreach (int i in anketa.GlasoviId)
                    {
                        DateTime date  = DateTime.Now;
                        string   datum = date.ToString("yyyy-MM-dd HH:mm:ss");

                        var novGlas = db.Glasas.Create();
                        novGlas.id_anketa      = anketa.id_anketa;
                        novGlas.id_lice        = (int)Session["id_lice"];
                        novGlas.id_odg         = i;
                        novGlas.datum_glasanje = Convert.ToDateTime(datum);

                        db.Glasas.Add(novGlas);
                    }

                    db.SaveChanges();
                }

                return(RedirectToAction("Details", "Anketa", new { id = anketa.id_anketa }));
            }
            //ViewBag.id_lice = new SelectList(db.Lice, "id_lice", "ime", anketa.id_lice);
            return(View(anketa));
        }
示例#6
0
        public ActionResult ZapisiKomentar()
        {
            string sodrzinaKom = Request.Params["sodrzinaKom"];
            string anketaId    = Request.Params["anketa_id"];

            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    DateTime date  = DateTime.Now;
                    string   datum = date.ToString("yyyy-MM-dd HH:mm:ss");

                    var novKom = db.Komentars.Create();
                    novKom.sodrzina = sodrzinaKom;

                    db.Komentars.Add(novKom);

                    var komentarZa = db.Komentar_Za.Create();
                    komentarZa.id_anketa = Convert.ToInt32(anketaId);
                    komentarZa.id_kom    = novKom.id_kom;
                    komentarZa.id_lice   = (int)Session["id_lice"];
                    komentarZa.datum     = Convert.ToDateTime(datum);

                    db.Komentar_Za.Add(komentarZa);

                    db.SaveChanges();
                }
                //return RedirectToAction("Details", "Anketa", new { id = anketa.id_anketa });
            }

            //ViewBag.id_lice = new SelectList(db.Lice, "id_lice", "ime", anketa.id_lice);
            return(View());
        }
        public ActionResult BuyPremium(Premium_Korisnik premiumKorsinik)
        {
            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    Premium_Korisnik premiumUser = db.Premium_Korisnik.Create();

                    premiumUser.id_lice      = (int)Session["id_lice"];
                    premiumUser.datum_starts = DateTime.Today;
                    premiumUser.datum_end    = DateTime.Today.AddMonths(12);

                    db.Premium_Korisnik.Add(premiumUser);

                    db.SaveChanges();

                    return(RedirectToAction("CheckStatus", "User"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Anketa"));
            }

            return(View());
        }
示例#8
0
        public JsonResult DonatChartData(int?id)
        {
            Anketa anketa;

            List <Mozni_Odgovori> allUser;
            //Dictionary<string, int> mapa = new Dictionary<string, int>();

            var movies = new List <object>();

            using (var dc = new AnketiEntities5())
            {
                anketa = db.Anketas.Find(id);

                allUser = anketa.Mozni_Odgovori.ToList();

                foreach (Mozni_Odgovori odg in allUser)
                {
                    int brGlasovi = odg.Glasas.Count;

                    //mapa.Add(odg.ime_odg, brGlasovi);

                    movies.Add(new { Ime_odg = odg.ime_odg, Br_glasovi = brGlasovi });
                }
            }

            return(Json(movies, JsonRequestBehavior.AllowGet));
        }
示例#9
0
        public ActionResult MySearch(string searchText)
        {
            string search_text = searchText;

            List <Kategorija>     kategorii = new List <Kategorija>();
            List <Mozni_Odgovori> odgovori  = new List <Mozni_Odgovori>();
            List <Anketa>         anketi    = new List <Anketa>();

            using (var db = new AnketiEntities5())
            {
                kategorii = (from a in db.Kategorijas
                             where a.ime_k.StartsWith(search_text)
                             select a).ToList();

                anketi = (from a in db.Anketas
                          where a.prasanje.StartsWith(search_text)
                          select a).ToList();

                odgovori = (from a in db.Mozni_Odgovori
                            where a.ime_odg.StartsWith(search_text)
                            select a).ToList();

                if (anketi.Count > 0)
                {
                    ViewBag.AnketiPrasanje = anketi.Count;
                }

                if (kategorii.Count > 0)
                {
                    foreach (Kategorija k in kategorii)
                    {
                        List <Anketa> anketa = k.Anketas.ToList();

                        if (anketa.Count > 0)
                        {
                            ViewBag.AnketiVoKategorijata = anketa;
                        }
                    }
                }

                if (odgovori.Count > 0)
                {
                    foreach (Mozni_Odgovori odg in odgovori)
                    {
                        List <Anketa> anketa = odg.Anketas.ToList();

                        if (anketa.Count > 0)
                        {
                            ViewBag.AnketaSoOdg = anketa;
                        }
                    }
                }

                ViewBag.SearchWord = search_text;
            }

            //return RedirectToAction("MySearch", "Anketa");
            return(View(anketi));
        }
示例#10
0
        public JsonResult GraphChartData(int?id)
        {
            Anketa anketa;

            List <Glasa> glasovi;

            var myGlas = new List <object>();

            using (var dc = new AnketiEntities5())
            {
                anketa = db.Anketas.Find(id);

                glasovi = anketa.Glasas.ToList();

                SortedDictionary <string, int> mapa = new SortedDictionary <string, int>();

                foreach (Glasa g in glasovi)
                {
                    string datum = g.datum_glasanje.ToString();

                    int start = datum.IndexOf(" ");
                    int end   = datum.Length;

                    int delete = end - start;

                    string myDatum = datum.Remove(datum.IndexOf(" "), delete);

                    String[] elements = myDatum.Split('.');

                    string dateFinal = elements[2] + "-";
                    dateFinal += elements[1] + "-";
                    dateFinal += elements[0];

                    if (mapa.ContainsKey(dateFinal))
                    {
                        int mom = mapa[dateFinal];
                        mom++;

                        mapa[dateFinal] = mom;
                    }
                    else
                    {
                        mapa.Add(dateFinal, 1);
                    }
                }

                foreach (KeyValuePair <string, int> entry in mapa)
                {
                    string den        = entry.Key;
                    int    br_glasovi = entry.Value;

                    myGlas.Add(new { Den = den, Br_glasovi = br_glasovi });
                }
            }

            return(Json(myGlas, JsonRequestBehavior.AllowGet));
        }
示例#11
0
        public ActionResult zapisiMultiChoiceGlas()
        {
            string glasoviIds = Request.Params["odgovoriId"];
            string anketaId   = Request.Params["anketa_id"];

            String[] elements = glasoviIds.Split(',');

            if (Session["id_lice"] != null)
            {
                if (glasoviIds.Length > 0)
                {
                    using (var db = new AnketiEntities5())
                    {
                        Anketa anketa = db.Anketas.Find(Convert.ToInt32(anketaId));

                        for (int i = 0; i < elements.Length; i++)
                        {
                            DateTime date  = DateTime.Now;
                            string   datum = date.ToString("yyyy-MM-dd HH:mm:ss");

                            Mozni_Odgovori odgovor = db.Mozni_Odgovori.Find(Convert.ToInt32(elements[i]));

                            if (anketa.Mozni_Odgovori.Contains(odgovor))
                            {
                                var novGlas = db.Glasas.Create();
                                novGlas.id_anketa      = Convert.ToInt32(anketaId);
                                novGlas.id_lice        = (int)Session["id_lice"];
                                novGlas.id_odg         = Convert.ToInt32(elements[i]);
                                novGlas.datum_glasanje = Convert.ToDateTime(datum);

                                db.Glasas.Add(novGlas);
                            }
                        }

                        db.SaveChanges();
                    }

                    //return RedirectToAction("Details", "Anketa", new { id = anketaId });
                }
                else
                {
                    //return RedirectToAction("Details", "Anketa", new { id = anketaId });
                }
            }

            return(View());
        }
示例#12
0
        public JsonResult MyAutoComplete(string term)
        {
            List <string> strJsonKategorii = new List <string>();
            List <string> strJsonOdgovori  = new List <string>();
            List <string> strJsonAnketi    = new List <string>();

            using (var db = new AnketiEntities5())
            {
                strJsonKategorii = (from a in db.Kategorijas
                                    where a.ime_k.StartsWith(term)
                                    select a.ime_k).ToList();

                strJsonAnketi = (from a in db.Anketas
                                 where a.prasanje.StartsWith(term)
                                 select a.prasanje).ToList();

                strJsonOdgovori = (from a in db.Mozni_Odgovori
                                   where a.ime_odg.StartsWith(term)
                                   select a.ime_odg).ToList();
            }

            List <string> retrunJson = new List <string>();

            foreach (string s in strJsonKategorii)
            {
                retrunJson.Add(s);
            }

            foreach (string s in strJsonAnketi)
            {
                retrunJson.Add(s);
            }

            foreach (string s in strJsonOdgovori)
            {
                retrunJson.Add(s);
            }

            //List<string> pom = new List<string>();
            //pom.Add("dd");
            //pom.Add("ddd");

            return(Json(retrunJson));
        }
        public ActionResult Registration()
        {
            using (var db = new AnketiEntities5())
            {
                List <SelectListItem> listSelectListItems = new List <SelectListItem>();

                foreach (Grad city in db.Grads)
                {
                    SelectListItem selectList = new SelectListItem()
                    {
                        Text  = city.ime_grad,
                        Value = city.id_grad.ToString()
                    };

                    listSelectListItems.Add(selectList);
                }

                ViewBag.MyGradovi = listSelectListItems;

                return(View());
            }
        }
        public ActionResult BuyPremium()
        {
            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    Premium_Korisnik premiumKorisnik = db.Premium_Korisnik.Find((int) Session["id_lice"]);

                    if (premiumKorisnik == null)
                    {
                        return View(premiumKorisnik);
                    }
                    else
                    {
                        return RedirectToAction("CheckStatus", "User");
                    }
                }
            }
            else
            {
                return RedirectToAction("Index", "Anketa");
            }
        }
        public ActionResult BuyPremium()
        {
            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    Premium_Korisnik premiumKorisnik = db.Premium_Korisnik.Find((int)Session["id_lice"]);

                    if (premiumKorisnik == null)
                    {
                        return(View(premiumKorisnik));
                    }
                    else
                    {
                        return(RedirectToAction("CheckStatus", "User"));
                    }
                }
            }
            else
            {
                return(RedirectToAction("Index", "Anketa"));
            }
        }
        public ActionResult CheckStatus()
        {
            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    Korisnik korisnik = db.Korisniks.Find((int)Session["id_lice"]);

                    Premium_Korisnik premiumKorsinik = db.Premium_Korisnik.Find((int)Session["id_lice"]);

                    Louse lice = db.Lice.Find((int)Session["id_lice"]);

                    if (premiumKorsinik != null)
                    {
                        ViewBag.PremiumUserStartDate = premiumKorsinik.datum_starts;
                        ViewBag.PremiumUserEndDate   = premiumKorsinik.datum_end;

                        ViewBag.UserName     = lice.ime;
                        ViewBag.UserLastName = lice.prezime;

                        return(View(korisnik));
                    }
                    else
                    {
                        ViewBag.UserName     = lice.ime;
                        ViewBag.UserLastName = lice.prezime;

                        return(View(korisnik));
                    }
                }
            }
            else
            {
                return(RedirectToAction("Index", "Anketa"));
            }
        }
        public JsonResult MyAutoComplete(string term)
        {
            List<string> strJsonKategorii = new List<string>();
            List<string> strJsonOdgovori = new List<string>();
            List<string> strJsonAnketi = new List<string>();

            using (var db = new AnketiEntities5())
            {
                strJsonKategorii = (from a in db.Kategorijas
                                  where a.ime_k.StartsWith(term)
                                  select a.ime_k).ToList();

                strJsonAnketi = (from a in db.Anketas
                                 where a.prasanje.StartsWith(term)
                                 select a.prasanje).ToList();

                strJsonOdgovori = (from a in db.Mozni_Odgovori
                                   where a.ime_odg.StartsWith(term)
                                   select a.ime_odg).ToList();
            }

            List<string> retrunJson = new List<string>();

            foreach (string s in strJsonKategorii)
            {
                retrunJson.Add(s);
            }

            foreach (string s in strJsonAnketi)
            {
                retrunJson.Add(s);
            }

            foreach (string s in strJsonOdgovori)
            {
                retrunJson.Add(s);
            }

            //List<string> pom = new List<string>();
            //pom.Add("dd");
            //pom.Add("ddd");

            return Json(retrunJson);
        }
        public ActionResult myCreate()
        {
            var myOdgovori = Request.Params["odgovori"];
            string myPrasanje = Request.Params["prasanje"];
            string myDesc = Request.Params["description"];
            string myDueDate = Request.Params["dueDate"];
            string myMultiChoice = Request.Params["multiChoice"];
            string myIdKategorii = Request.Params["idKategorii"];
            string url_slika = Request.Params["urlSlika"];

            String[] elements = myOdgovori.Split(',');

            String[] idKategorii = new  string[1] {"kola"};
            bool zname = false;

            if (myIdKategorii.Length > 0)
            {
                idKategorii = myIdKategorii.Split(',');
                zname = true;
            }

            int multiChoice = 0;
            if (myMultiChoice.Equals("1"))
            {
                multiChoice = 1;
            }

            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    Korisnik korisnik = db.Korisniks.Find((int)Session["id_lice"]);
                    Premium_Korisnik premiumKorisnik = db.Premium_Korisnik.Find((int)Session["id_lice"]);

                    bool flag = true;

                    if (korisnik.br_anketi >= 3)
                    {
                        flag = false;
                    }

                    if (premiumKorisnik != null)
                    {
                        flag = true;
                    }

                    if (flag)
                    {

                        DateTime date = DateTime.Now;
                        string datum = date.ToString("yyyy-MM-dd HH:mm:ss");

                        var novaAnketa = db.Anketas.Create();
                        novaAnketa.prasanje = myPrasanje;
                        novaAnketa.opis_a = myDesc;
                        novaAnketa.kraen_datum = Convert.ToDateTime(myDueDate);
                        novaAnketa.id_lice = (int)Session["id_lice"];
                        novaAnketa.datum_kreiranje = Convert.ToDateTime(datum);
                        novaAnketa.multi_choice = multiChoice;

                        if (url_slika.Length > 1)
                        {
                            novaAnketa.url_slika = url_slika;
                        }

                        db.Anketas.Add(novaAnketa);

                        db.SaveChanges();

                        Anketa anketa = db.Anketas.Find(novaAnketa.id_anketa);

                        for (int i = 0; i < elements.Length; i++)
                        {
                            string str = elements[i];
                            str = str.Replace(";;;", ",");

                            Mozni_Odgovori odg = db.Mozni_Odgovori.Create();
                            odg.ime_odg = str;

                            db.Mozni_Odgovori.Add(odg);

                            db.SaveChanges();

                            anketa.Mozni_Odgovori.Add(odg);
                        }

                        db.SaveChanges();

                        if (zname)
                        {
                            for (int i = 0; i < idKategorii.Length; i++)
                            {
                                int id_k = Convert.ToInt32(idKategorii[i]);

                                Kategorija kategorija = db.Kategorijas.Find(id_k);

                                anketa.Kategorijas.Add(kategorija);

                                db.SaveChanges();
                            }

                            db.SaveChanges();
                        }

                        korisnik.br_anketi = korisnik.br_anketi + 1;
                        db.SaveChanges();

                        string strJson = "Your pool has been added. Thanks for your participation!!";

                        return Json(strJson);
                    }
                    else
                    {
                        string strJson = "You have already posted 3 pools. If you want to post more pools You have to upgrade to Premium User!";

                        return Json(strJson);
                    }
                }
            }

            string strJson2 = "You are Not Logged IN!!!";
            return Json(strJson2);
        }
示例#19
0
        public ActionResult myCreate()
        {
            var    myOdgovori    = Request.Params["odgovori"];
            string myPrasanje    = Request.Params["prasanje"];
            string myDesc        = Request.Params["description"];
            string myDueDate     = Request.Params["dueDate"];
            string myMultiChoice = Request.Params["multiChoice"];
            string myIdKategorii = Request.Params["idKategorii"];
            string url_slika     = Request.Params["urlSlika"];

            String[] elements = myOdgovori.Split(',');

            String[] idKategorii = new  string[1] {
                "kola"
            };
            bool zname = false;

            if (myIdKategorii.Length > 0)
            {
                idKategorii = myIdKategorii.Split(',');
                zname       = true;
            }

            int multiChoice = 0;

            if (myMultiChoice.Equals("1"))
            {
                multiChoice = 1;
            }

            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    Korisnik         korisnik        = db.Korisniks.Find((int)Session["id_lice"]);
                    Premium_Korisnik premiumKorisnik = db.Premium_Korisnik.Find((int)Session["id_lice"]);

                    bool flag = true;

                    if (korisnik.br_anketi >= 3)
                    {
                        flag = false;
                    }

                    if (premiumKorisnik != null)
                    {
                        flag = true;
                    }

                    if (flag)
                    {
                        DateTime date  = DateTime.Now;
                        string   datum = date.ToString("yyyy-MM-dd HH:mm:ss");

                        var novaAnketa = db.Anketas.Create();
                        novaAnketa.prasanje        = myPrasanje;
                        novaAnketa.opis_a          = myDesc;
                        novaAnketa.kraen_datum     = Convert.ToDateTime(myDueDate);
                        novaAnketa.id_lice         = (int)Session["id_lice"];
                        novaAnketa.datum_kreiranje = Convert.ToDateTime(datum);
                        novaAnketa.multi_choice    = multiChoice;

                        if (url_slika.Length > 1)
                        {
                            novaAnketa.url_slika = url_slika;
                        }

                        db.Anketas.Add(novaAnketa);

                        db.SaveChanges();

                        Anketa anketa = db.Anketas.Find(novaAnketa.id_anketa);

                        for (int i = 0; i < elements.Length; i++)
                        {
                            string str = elements[i];
                            str = str.Replace(";;;", ",");

                            Mozni_Odgovori odg = db.Mozni_Odgovori.Create();
                            odg.ime_odg = str;

                            db.Mozni_Odgovori.Add(odg);

                            db.SaveChanges();

                            anketa.Mozni_Odgovori.Add(odg);
                        }

                        db.SaveChanges();

                        if (zname)
                        {
                            for (int i = 0; i < idKategorii.Length; i++)
                            {
                                int id_k = Convert.ToInt32(idKategorii[i]);

                                Kategorija kategorija = db.Kategorijas.Find(id_k);

                                anketa.Kategorijas.Add(kategorija);

                                db.SaveChanges();
                            }

                            db.SaveChanges();
                        }

                        korisnik.br_anketi = korisnik.br_anketi + 1;
                        db.SaveChanges();

                        string strJson = "Your pool has been added. Thanks for your participation!!";

                        return(Json(strJson));
                    }
                    else
                    {
                        string strJson = "You have already posted 3 pools. If you want to post more pools You have to upgrade to Premium User!";

                        return(Json(strJson));
                    }
                }
            }

            string strJson2 = "You are Not Logged IN!!!";

            return(Json(strJson2));
        }
        public ActionResult MySearch(string searchText)
        {
            string search_text = searchText;

            List<Kategorija> kategorii = new List<Kategorija>();
            List<Mozni_Odgovori> odgovori = new List<Mozni_Odgovori>();
            List<Anketa> anketi = new List<Anketa>();

            using (var db = new AnketiEntities5())
            {
                kategorii = (from a in db.Kategorijas
                                    where a.ime_k.StartsWith(search_text)
                                    select a).ToList();

                anketi = (from a in db.Anketas
                                 where a.prasanje.StartsWith(search_text)
                                 select a).ToList();

                odgovori = (from a in db.Mozni_Odgovori
                                   where a.ime_odg.StartsWith(search_text)
                                   select a).ToList();

                if (anketi.Count > 0)
                {
                    ViewBag.AnketiPrasanje = anketi.Count;
                }

                if (kategorii.Count > 0)
                {
                    foreach (Kategorija k in kategorii)
                    {
                        List<Anketa> anketa = k.Anketas.ToList();

                        if (anketa.Count > 0)
                        {
                            ViewBag.AnketiVoKategorijata = anketa;
                        }
                    }
                }

                if (odgovori.Count > 0)
                {
                    foreach (Mozni_Odgovori odg in odgovori)
                    {
                        List<Anketa> anketa = odg.Anketas.ToList();

                        if (anketa.Count > 0)
                        {
                            ViewBag.AnketaSoOdg = anketa;
                        }
                    }
                }

                ViewBag.SearchWord = search_text;
            }

            //return RedirectToAction("MySearch", "Anketa");
            return View(anketi);
        }
        public ActionResult ZapisiGlas(Anketa anketa)
        {
            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    foreach (int i in anketa.GlasoviId)
                    {
                        DateTime date = DateTime.Now;
                        string datum = date.ToString("yyyy-MM-dd HH:mm:ss");

                        var novGlas = db.Glasas.Create();
                        novGlas.id_anketa = anketa.id_anketa;
                        novGlas.id_lice = (int)Session["id_lice"];
                        novGlas.id_odg = i;
                        novGlas.datum_glasanje = Convert.ToDateTime(datum);

                        db.Glasas.Add(novGlas);
                    }

                    db.SaveChanges();
                }

                return RedirectToAction("Details", "Anketa", new { id = anketa.id_anketa });
            }
            //ViewBag.id_lice = new SelectList(db.Lice, "id_lice", "ime", anketa.id_lice);
            return View(anketa);
        }
        public ActionResult CheckStatus()
        {
            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    Korisnik korisnik = db.Korisniks.Find((int)Session["id_lice"]);

                    Premium_Korisnik premiumKorsinik = db.Premium_Korisnik.Find((int)Session["id_lice"]);

                    Louse lice = db.Lice.Find((int)Session["id_lice"]);

                    if (premiumKorsinik != null)
                    {
                        ViewBag.PremiumUserStartDate = premiumKorsinik.datum_starts;
                        ViewBag.PremiumUserEndDate = premiumKorsinik.datum_end;

                        ViewBag.UserName = lice.ime;
                        ViewBag.UserLastName = lice.prezime;

                        return View(korisnik);
                    }
                    else
                    {
                        ViewBag.UserName = lice.ime;
                        ViewBag.UserLastName = lice.prezime;

                        return View(korisnik);
                    }
                }
            }
            else
            {
                return RedirectToAction("Index", "Anketa");
            }
        }
        public ActionResult Registration(Anketa_Proekt.Models.Louse user)
        {
            using (var db = new AnketiEntities5())
            {
                List<SelectListItem> listSelectListItems = new List<SelectListItem>();

                foreach (Grad city in db.Grads)
                {
                    SelectListItem selectList = new SelectListItem()
                    {
                        Text = city.ime_grad,
                        Value = city.id_grad.ToString(),
                        //Selected = false
                    };

                    listSelectListItems.Add(selectList);
                }

                ViewBag.MyGradovi = listSelectListItems;

                //return View();
            }

            if (ModelState.IsValid)
            {
                    using (var db = new AnketiEntities5())
                    {
                        var newUser = db.Lice.Create();

                        newUser.ime = user.ime;
                        newUser.prezime = user.prezime;
                        newUser.e_mail = user.e_mail;
                        newUser.lozinka = user.lozinka;
                        newUser.tel_broj = user.tel_broj;
                        newUser.ulica = user.ulica;
                        newUser.id_grad = user.id_grad;
                        newUser.datum_r = user.datum_r;

                        db.Lice.Add(newUser);

                        db.SaveChanges();

                        Session["id_lice"] = newUser.id_lice;

                        var korisnik = db.Korisniks.Create();

                        korisnik.id_lice = newUser.id_lice;
                        korisnik.br_anketi = 0;

                        db.Korisniks.Add(korisnik);

                        db.SaveChanges();

                        return RedirectToAction("Index", "Anketa");
                    }

            }
            else
            {
                ModelState.AddModelError("", "The data that you Entered is incorrect!");
            }

            return View();
        }
        public ActionResult Registration()
        {
            using (var db = new AnketiEntities5())
            {
                List<SelectListItem> listSelectListItems = new List<SelectListItem>();

                foreach (Grad city in db.Grads)
                {
                    SelectListItem selectList = new SelectListItem()
                    {
                        Text = city.ime_grad,
                        Value = city.id_grad.ToString()
                    };

                    listSelectListItems.Add(selectList);
                }

                ViewBag.MyGradovi = listSelectListItems;

                return View();
            }
        }
        public JsonResult GraphChartData(int? id)
        {
            Anketa anketa;

            List<Glasa> glasovi;

            var myGlas = new List<object>();
            using (var dc = new AnketiEntities5())
            {
                anketa = db.Anketas.Find(id);

                glasovi = anketa.Glasas.ToList();

                SortedDictionary<string, int> mapa = new SortedDictionary<string, int>();

                foreach (Glasa g in glasovi)
                {
                    string datum = g.datum_glasanje.ToString();

                    int start = datum.IndexOf(" ");
                    int end = datum.Length;

                    int delete = end - start;

                    string myDatum = datum.Remove(datum.IndexOf(" "), delete);

                    String[] elements = myDatum.Split('.');

                    string dateFinal = elements[2] + "-";
                    dateFinal += elements[1] + "-";
                    dateFinal += elements[0];

                    if (mapa.ContainsKey(dateFinal))
                        {
                            int mom = mapa[dateFinal];
                            mom++;

                            mapa[dateFinal] = mom;
                        }
                        else
                        {
                            mapa.Add(dateFinal, 1);
                        }
                }

                foreach (KeyValuePair<string, int> entry in mapa)
                {
                    string den = entry.Key;
                    int br_glasovi = entry.Value;

                    myGlas.Add(new { Den = den, Br_glasovi = br_glasovi });
                }
            }

            return Json(myGlas, JsonRequestBehavior.AllowGet);
        }
        public ActionResult zapisiSingleChoiceGlas()
        {
            string glasId = Request.Params["odgovoriId"];
            string anketaId = Request.Params["anketa_id"];

            if (Session["id_lice"] != null)
            {
                if (glasId.Length > 0)
                {
                    using (var db = new AnketiEntities5())
                    {
                        Anketa anketa = db.Anketas.Find(Convert.ToInt32(anketaId));

                        DateTime date = DateTime.Now;
                        string datum = date.ToString("yyyy-MM-dd HH:mm:ss");

                        Mozni_Odgovori odgovor = db.Mozni_Odgovori.Find(Convert.ToInt32(glasId));

                        if (anketa.Mozni_Odgovori.Contains(odgovor))
                        {
                            var novGlas = db.Glasas.Create();
                            novGlas.id_anketa = Convert.ToInt32(anketaId);
                            novGlas.id_lice = (int)Session["id_lice"];
                            novGlas.id_odg = Convert.ToInt32(glasId);
                            novGlas.datum_glasanje = Convert.ToDateTime(datum);

                            db.Glasas.Add(novGlas);
                        }

                        db.SaveChanges();
                    }

                    //return RedirectToAction("Details", "Anketa", new { id = anketaId });
                }
                else
                {
                    //return View();
                }
            }
            return View();
        }
        public ActionResult Registration(Anketa_Proekt.Models.Louse user)
        {
            using (var db = new AnketiEntities5())
            {
                List <SelectListItem> listSelectListItems = new List <SelectListItem>();

                foreach (Grad city in db.Grads)
                {
                    SelectListItem selectList = new SelectListItem()
                    {
                        Text  = city.ime_grad,
                        Value = city.id_grad.ToString(),
                        //Selected = false
                    };

                    listSelectListItems.Add(selectList);
                }

                ViewBag.MyGradovi = listSelectListItems;

                //return View();
            }

            if (ModelState.IsValid)
            {
                using (var db = new AnketiEntities5())
                {
                    var newUser = db.Lice.Create();

                    newUser.ime      = user.ime;
                    newUser.prezime  = user.prezime;
                    newUser.e_mail   = user.e_mail;
                    newUser.lozinka  = user.lozinka;
                    newUser.tel_broj = user.tel_broj;
                    newUser.ulica    = user.ulica;
                    newUser.id_grad  = user.id_grad;
                    newUser.datum_r  = user.datum_r;

                    db.Lice.Add(newUser);

                    db.SaveChanges();

                    Session["id_lice"] = newUser.id_lice;

                    var korisnik = db.Korisniks.Create();

                    korisnik.id_lice   = newUser.id_lice;
                    korisnik.br_anketi = 0;

                    db.Korisniks.Add(korisnik);

                    db.SaveChanges();

                    return(RedirectToAction("Index", "Anketa"));
                }
            }
            else
            {
                ModelState.AddModelError("", "The data that you Entered is incorrect!");
            }

            return(View());
        }
        public ActionResult ZapisiKomentar()
        {
            string sodrzinaKom = Request.Params["sodrzinaKom"];
            string anketaId = Request.Params["anketa_id"];

            if (Session["id_lice"] != null)
            {
                using (var db = new AnketiEntities5())
                {
                    DateTime date = DateTime.Now;
                    string datum = date.ToString("yyyy-MM-dd HH:mm:ss");

                    var novKom = db.Komentars.Create();
                    novKom.sodrzina = sodrzinaKom;

                    db.Komentars.Add(novKom);

                    var komentarZa = db.Komentar_Za.Create();
                    komentarZa.id_anketa = Convert.ToInt32(anketaId);
                    komentarZa.id_kom = novKom.id_kom;
                    komentarZa.id_lice = (int)Session["id_lice"];
                    komentarZa.datum = Convert.ToDateTime(datum);

                    db.Komentar_Za.Add(komentarZa);

                    db.SaveChanges();
                }
                //return RedirectToAction("Details", "Anketa", new { id = anketa.id_anketa });
            }

            //ViewBag.id_lice = new SelectList(db.Lice, "id_lice", "ime", anketa.id_lice);
            return View();
        }
        public ActionResult LogIn(Anketa_Proekt.Models.Louse user)
        {
            //if (ModelState.IsValid)
            //{
                if (user.isValidUser(user.e_mail, user.lozinka))
                {
                    //FormsAuthentication.SetAuthCookie(user.e_mail, true);
                    //FormsAuthentication.SetAuthCookie()
                    using (var db = new AnketiEntities5())
                    {
                        var query = from a in db.Lice
                                    where a.e_mail.Equals(user.e_mail) & a.lozinka.Equals(user.lozinka)
                                    select a.id_lice;

                        int idLice = query.FirstOrDefault();

                        Session["id_lice"] = idLice;
                        return RedirectToAction("Index", "Anketa");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Login data is incorrect!");
                }
            //}
            return View(user);
        }
        public JsonResult DonatChartData(int? id)
        {
            Anketa anketa;

            List<Mozni_Odgovori> allUser;
            //Dictionary<string, int> mapa = new Dictionary<string, int>();

            var movies = new List<object>();
            using (var dc = new AnketiEntities5())
            {
                anketa = db.Anketas.Find(id);

                allUser = anketa.Mozni_Odgovori.ToList();

                foreach (Mozni_Odgovori odg in allUser)
                {
                    int brGlasovi = odg.Glasas.Count;

                    //mapa.Add(odg.ime_odg, brGlasovi);

                    movies.Add(new { Ime_odg = odg.ime_odg, Br_glasovi = brGlasovi });
                }
            }

            return Json (movies, JsonRequestBehavior.AllowGet);
        }