示例#1
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"));
     }
 }
示例#2
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());
     }
 }
示例#3
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
     }
 }
示例#4
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
 }
示例#5
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
                }
            }
        }