public ActionResult Index(Gospodarstvo add)
        {
            DatabaseController dbCtrl = new DatabaseController();

            dbCtrl.getConnection();
            //AddGospodarstva obj = new AddGospodarstva();
            string s1 =
                "Insert into [dbo].[gospodarstva] (ime,prezime,kontakt,email,lozinka) values (@Ime,@Prezime,@Kontakt,@Email,@Lozinka)";
            SqlCommand sqlcomm = new SqlCommand(s1);

            sqlcomm.Parameters.AddWithValue("@Ime", add.Ime);
            sqlcomm.Parameters.AddWithValue("@Prezime", add.Prezime);
            sqlcomm.Parameters.AddWithValue("@Kontakt", add.Kontakt);
            sqlcomm.Parameters.AddWithValue("@Email", add.Email);
            sqlcomm.Parameters.AddWithValue("@Lozinka", add.Lozinka);

            dbCtrl.executeCommand(sqlcomm);

            return(View(add));
        }
Beispiel #2
0
        public ActionResult Register(Gospodarstvo add)
        {
            DatabaseController dbCtrl = new DatabaseController();

            dbCtrl.getConnection();
            string s1 =
                "Insert into [dbo].[gospodarstva] (ime,prezime,kontakt,email,lozinka) values (@Ime,@Prezime,@Kontakt,@Email,@Lozinka)";
            string     s2  = "Select * from [dbo].[gospodarstva] where email=@Email";
            SqlCommand sql = new SqlCommand(s2);

            sql.Parameters.AddWithValue("@Email", add.Email);
            SqlDataReader sdr = dbCtrl.executeSdr(sql);

            if (sdr.Read())
            {
                ViewBag.Message = "Taj email je vec zauzet";
                return(View());
            }
            else
            {
                sdr.Close();
                SqlCommand sqlcomm = new SqlCommand(s1);
                sqlcomm.Parameters.AddWithValue("@Ime", add.Ime);
                sqlcomm.Parameters.AddWithValue("@Prezime", add.Prezime);
                sqlcomm.Parameters.AddWithValue("@Kontakt", add.Kontakt);
                sqlcomm.Parameters.AddWithValue("@Email", add.Email);
                sqlcomm.Parameters.AddWithValue("@Lozinka", add.Lozinka);
                dbCtrl.executeCommand(sqlcomm);
                ViewBag.Message = "Uspješno ste se registrirali. Možete se prijaviti.";

                /*if(!ModelState.IsValid)
                 * {
                 *  return View(add);
                 * }*/
                return(View("Index"));
            }
        }
Beispiel #3
0
        public ActionResult Index(Gospodarstvo login)
        {
            DatabaseController dbCtrl = new DatabaseController();

            dbCtrl.getConnection();
            string     s1      = "Select email,lozinka from [dbo].[gospodarstva] where email=@Email and lozinka=@Lozinka ";
            SqlCommand sqlcomm = new SqlCommand(s1);

            sqlcomm.Parameters.AddWithValue("@Email", login.Email);
            sqlcomm.Parameters.AddWithValue("@Lozinka", login.Lozinka);
            SqlDataReader sdr = dbCtrl.executeSdr(sqlcomm);

            if (sdr.Read())
            {
                Session["id"] = login.Id.ToString();
                return(RedirectToAction("Welcome"));
            }
            else
            {
                ViewData["Message"] = "Unijeli ste pogrešne podatke.";
            }

            return(View());
        }