예제 #1
0
 public IActionResult Delete(int evntid)
 {
     if (HttpContext.Session.GetInt32("Id") != null)
     {
         Event thisEvent = _dbConnector.events.Where(evnt => evnt.EventId == evntid).SingleOrDefault();
         _dbConnector.events.Remove(thisEvent);
         _dbConnector.SaveChanges();
         return(RedirectToAction("Events"));
     }
     return(RedirectToAction("Index", "Users"));
 }
예제 #2
0
        public IActionResult Register(RegisterViewModel model, User newUser)
        {
            ViewBag.errors = new List <string>();
            // If the information is all vaild
            if (ModelState.IsValid)
            {
                // If the email does not already exist
                User checkemail = _dbConnector.users.Where(x => x.Email == newUser.Email).SingleOrDefault();
                if (checkemail == null)
                {
                    // Create/Register a new user and pull the user id and name, then log them in
                    _dbConnector.users.Add(newUser);
                    _dbConnector.SaveChanges();
                    // Saving name and user_id in session
                    User checkuser = _dbConnector.users.Where(x => x.Email == newUser.Email).SingleOrDefault();
                    HttpContext.Session.SetInt32("Id", (int)checkuser.UserId);
                    HttpContext.Session.SetString("FirstName", (string)checkuser.FirstName);

                    return(RedirectToAction("events", "Events"));
                }
                else
                {
                    ViewBag.newerrors = "This email already exists!";
                    return(View("Index"));
                }
            }
            else
            {
                ViewBag.errors = ModelState.Values;
            }
            return(View("Index"));
        }
 public IActionResult AddWedding(Wedding newWedding)
 {
     dbContext.Add(newWedding);
     dbContext.SaveChanges();
     return(RedirectToAction("WeddingList"));
 }