Example #1
0
 public ActionResult Home()
 {
     using (YourSayDB db = new YourSayDB())
     {
         return(View(db.Causes.Take(3).ToList()));        //Return the first 3 causes from the DbSet
     }
 }
Example #2
0
 // For use by the developer only
 public ActionResult Index()
 {
     using (YourSayDB db = new YourSayDB())
     {
         return(View(db.userAccount.ToList()));                                                           //return the Causes BdSet to the View
     }
 }
Example #3
0
 public JsonResult Show(string title)
 {
     using (YourSayDB db = new YourSayDB())
     {
         var tempCause = db.Causes.First(c => c.Title == title);                                 //Creates a temporary cause with the clicked title
         return(Json(tempCause, JsonRequestBehavior.AllowGet));                                  //Returns the temporary cause as Jason
     }
 }
Example #4
0
 public ActionResult RemoveCause(string title)
 {
     using (YourSayDB db = new YourSayDB())
     {
         db.Causes.Remove(db.Causes.First(c => c.Title == title));                               //Remove the cause with the title clicked
         db.SaveChanges();                                                                       //Save changes
         return(RedirectToAction("Causes", "Causes"));
     }
 }
Example #5
0
 //Method to manually remove all causes from the DbSet (to be used only by the developer)
 public ActionResult Remove()
 {
     using (YourSayDB db = new YourSayDB())
     {
         db.Causes.RemoveRange(db.Causes);
         db.SaveChanges();
         return(View());
     }
 }
Example #6
0
 public ActionResult Create(Causes tempCause)
 {
     using (YourSayDB db = new YourSayDB())
     {
         if (ModelState.IsValid)                                             //Check if the form is complete
         {
             db.Causes.Add(tempCause);                                       //Add the passed cause to the DbSet
             db.SaveChanges();                                               //Save changed
         }
         ModelState.Clear();                                                 //Clear the form
         return(RedirectToAction("Causes", "Causes"));                       //Redirect to causes
     }
 }
Example #7
0
 public ActionResult Register(UserAccount account, bool AcceptTerms)                                     //Get the account details and the accept terms from the form
 {
     if (ModelState.IsValid && AcceptTerms == true)                                                      //Check in the backend if the form is valid
     {
         using (YourSayDB db = new YourSayDB())
         {
             db.userAccount.Add(account);                                                                //Add the inserted account details to the DbSet
             db.SaveChanges();                                                                           //Save changes
         }
         ModelState.Clear();                                                                             //Clear the form
         ViewBag.Message = account.FirstName + " " + account.LastName + " successfully registered";      //Pass the message to the viewer
     }
     return(View());                                                                                     //return the view
 }
Example #8
0
 public ActionResult Login(UserAccount user)
 {
     using (YourSayDB db = new YourSayDB())
     {
         var usr = db.userAccount.Single(u => u.UserName == user.UserName && u.Password == user.Password);//Check if the username and password match the DbSet
         if (usr != null)
         {
             Session["UserID"]   = usr.UserId.ToString();                                                 //Crete the session ID
             Session["Username"] = usr.UserName.ToString();                                               //Create hte session Username
             return(RedirectToAction("LoggedIn"));                                                        //Redirect to LoggedIn
         }
         else
         {
             ModelState.AddModelError("", "Username or password is wrong");                               //Send error message to the view
         }
     }
     return(View());                                                                                      //return the view
 }
Example #9
0
 //Check if user is logged in and return the appropriate view
 public ActionResult Causes()
 {
     using (YourSayDB db = new YourSayDB())
     {
         if (Session["UserID"] == null)                                                          //Check if user is logged in
         {
             return(View("CausesLoggedOut", db.Causes.ToList()));
         }
         else if (Session["Username"].ToString() == "admin1")
         {
             return(View("CausesAdmin", db.Causes.ToList()));
         }
         else
         {
             return(View(db.Causes.ToList()));
         }
     }
 }
Example #10
0
        public JsonResult Sign(int id)
        {
            using (YourSayDB db = new YourSayDB())
            {
                var usr = Session["Username"];                                                              //takes the username from the session

                if (db.Causes.FirstOrDefault(c => c.CauseId == id).Supporter.Contains(usr.ToString()))      //Check if the username already exists as a supporter
                {
                    var count = db.Causes.First(c => c.CauseId == id).Counter;                              //creates the count
                    return(Json(count, JsonRequestBehavior.AllowGet));                                      //returns the count as Json
                }
                else
                {
                    db.Causes.FirstOrDefault(c => c.CauseId == id).Supporter += " " + usr.ToString();       //Adds the username to the cause supporters
                    db.Causes.First(c => c.CauseId == id).Counter++;                                        //Adds one to the counter
                    db.SaveChanges();                                                                       //Save changes

                    var count = db.Causes.First(c => c.CauseId == id).Counter;                              //creates the count
                    return(Json(count, JsonRequestBehavior.AllowGet));                                      //returns the count as Json
                }
            }
        }