Exemple #1
0
        public ActionResult Join()
        {
            int          idUsera      = Int32.Parse(User.Identity.Name);
            gospodarstva gospodarstvo = db.gospodarstva.Find(idUsera);

            gospodarstvo.id_zadruge = Int32.Parse(Request["id_zadruge"]);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "id,ime,lozinka,id_zadruge,prezime,kontakt,email")] gospodarstva gospodarstva)
 {
     if (ModelState.IsValid)
     {
         db.Entry(gospodarstva).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     return(View(gospodarstva));
 }
 public ActionResult Create([Bind(Include = "id,ime,prezime,kontakt,id_zadruge,email,lozinka")] gospodarstva gospodarstva)
 {
     /* if (ModelState.IsValid)
      * {
      *   db.gospodarstva.Add(gospodarstva);
      *   db.SaveChanges();
      *   return RedirectToAction("Index");
      * }
      *
      * ViewBag.id_zadruge = new SelectList(db.zadruge, "id", "ime", gospodarstva.id_zadruge);
      * return View(gospodarstva);*/
     return(RedirectToAction("Index", "Home"));
 }
        public ActionResult DeleteConfirmed(int id)
        {
            gospodarstva gospodarstva = db.gospodarstva.Find(id);

            try
            {
                db.gospodarstva.Remove(gospodarstva);
                db.SaveChanges();
            }
            catch
            {
                return(View("Error"));
            }
            return(RedirectToAction("Index", "Home"));
        }
        // GET: gospodarstva/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            gospodarstva gospodarstva = db.gospodarstva.Find(id);
            var          userId       = Int32.Parse(User.Identity.Name);

            if (gospodarstva == null || gospodarstva.id != userId)
            {
                return(HttpNotFound());
            }
            return(View(gospodarstva));
        }
        // GET: gospodarstva/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            gospodarstva gospodarstva = db.gospodarstva.Find(id);
            var          userId       = Int32.Parse(User.Identity.Name);

            if (gospodarstva == null || gospodarstva.id != userId)
            {
                return(HttpNotFound());
            }
            ViewBag.id_zadruge = new SelectList(db.zadruge, "id", "ime", gospodarstva.id_zadruge);
            return(View(gospodarstva));
        }
Exemple #7
0
 public ActionResult Register(gospodarstva gospodarstva)
 {
     if (ModelState.IsValid)
     {
         if (!db.gospodarstva.Any(g => g.email == gospodarstva.email))
         {
             gospodarstva.lozinka = Crypto.SHA256(gospodarstva.lozinka);
             db.gospodarstva.Add(gospodarstva);
             db.SaveChanges();
             ModelState.Clear();
             TempData["shortMessage"] = "Uspješno ste se registrirali. Molimo prijavite se.";
             return(RedirectToAction("Login"));
         }
         else
         {
             ViewBag.Message = "Unijeli ste postojeću email adresu.";
             return(View());
         }
     }
     return(View());
 }
Exemple #8
0
        public ActionResult Login(gospodarstva login, string returnUrl)
        {
            var hashedLozinka = Crypto.SHA256(login.lozinka);
            var usr           = db.gospodarstva.Where(g => g.email == login.email && g.lozinka == hashedLozinka).FirstOrDefault();

            if (usr != null)
            {
                FormsAuthentication.SetAuthCookie(usr.id.ToString(), false);
                if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ModelState.AddModelError("", "Netočan email ili lozinka.");
                return(View());
            }
        }