Exemplo n.º 1
0
        public IActionResult CreateQuote(string author, string content)
        {
            string query = $"INSERT INTO quotes (content, author, created_at, updated_at) VALUES ('{content}', '{author}', NOW(), NOW())";

            MySqlConnector.Execute(query);
            return(RedirectToAction("Quotes"));
        }
Exemplo n.º 2
0
 public IActionResult addUser(string firstName, string lastName, int?age, string email, string password, string pw_confirm)
 {
     ViewBag.Errors = new List <string>();
     if (firstName == null || firstName.Length < 4)
     {
         ViewBag.Errors.Add("First name field has to have at least 4 characters.");
     }
     if (lastName == null || lastName.Length < 4)
     {
         ViewBag.Errors.Add("Last name field has to have at least 4 characters.");
     }
     if (age == null)
     {
         ViewBag.Errors.Add("You have to provide your age.");
     }
     if (email == null)
     {
         ViewBag.Errors.Add("You have to provide an e-mail address");
     }
     else
     {
         if (isValidEmail(email) == false)
         {
             ViewBag.Errors.Add("The email format provided is not correct");
         }
     }
     if (password == null || password.Length < 8)
     {
         ViewBag.Errors.Add("You have to provide a password");
     }
     if (pw_confirm == null || pw_confirm != password)
     {
         ViewBag.Errors.Add("Password and password confirmation do not match");
     }
     if (ViewBag.Errors.Count > 0)
     {
         TempData["Errors"] = ViewBag.Errors;
         return(RedirectToAction("Index"));
     }
     else
     {
         string selectQuery = $"SELECT * FROM users WHERE email = '{email}'";
         var    emailVal    = MySqlConnector.Query(selectQuery);
         if (emailVal.Count > 0)
         {
             ViewBag.Errors.Add("This e-mail already belongs to a registered user");
             TempData["Errors"] = ViewBag.Errors;
             return(RedirectToAction("Index"));
         }
         else
         {
             string rightNow = DateTime.Now.ToString("yyyyMMddHHmmss");
             string query    = $"INSERT INTO users (firstName,lastName,age,email,password,created_at,updated_at) VALUES ('{firstName}','{lastName}','{age}','{email}','{password}',{rightNow},{rightNow})";
             MySqlConnector.Execute(query);
             HttpContext.Session.SetString("userpass", (string)email);
             return(RedirectToAction("Index"));
         }
     }
 }
 public IActionResult Register(User user)
 {
     if (ModelState.IsValid)
     {
         MySqlConnector.Execute($"INSERT INTO logregusers (first_name, last_name, email, password, created_at, updated_at) VALUES ('{user.firstName}', '{user.lastName}', '{user.email}', '{user.password}', NOW(), NOW())");
         return(View("success"));
     }
     return(View("index"));
 }
Exemplo n.º 4
0
        public IActionResult addQuote(string UserName, string Quote)
        {
            UserName.Replace("'", "_");
            Quote.Replace("'", "`");
            string time  = @DateTime.Now.ToString("yyyy-MM-dd, hh:mm:ss tt");
            string query = $"INSERT INTO QuotesTable(UserName, Quote, DateAdded) values('{@UserName}', '{@Quote}' , '{@time}' )";

            ctx.Execute(query);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
        public IActionResult submit(string name, string content)
        {
            string query = $"INSERT INTO quotes (name, content, created_at, updated_at) VALUES ('{name}', '{content}', NOW(), NOW())";

            MySqlConnector.Execute(query);
            string str    = "SELECT * FROM quotes";
            var    quotes = MySqlConnector.Query(str);

            ViewBag.quotes = quotes;
            return(View("quotes"));
        }
Exemplo n.º 6
0
        public IActionResult addQuote(string yourname, string yourquote)
        {
            // string name = HttpContext.Session.GetString("yourname");
            // string quote = HttpContext.Session.GetString("yourquote");
            // string rightNow = now.ToString("yyyy-MM-dd HH:mm");
            string rightNow = DateTime.Now.ToString("yyyyMMddHHmmss");
            string query    = $"INSERT INTO comments (user,comment,created_at,updated_at) VALUES ('{yourname}','{yourquote}',{rightNow},{rightNow})";

            MySqlConnector.Execute(query);
            return(RedirectToAction("quotes"));
        }
Exemplo n.º 7
0
        public IActionResult deleteMessage(int?messageid)
        {
            // string email = HttpContext.Session.GetString("userpass");
            // string selectQuery = $"SELECT * FROM users WHERE email = '{email}'";
            // var younow = MySqlConnector.Query(selectQuery);
            // int? yourid = (int)younow[0]["id"];
            string delComments = $"DELETE FROM comments WHERE message_id = {messageid}";
            string delMessage  = $"DELETE FROM messages WHERE id = {messageid}";

            MySqlConnector.Execute(delComments);
            MySqlConnector.Execute(delMessage);
            return(RedirectToAction("Main"));
        }
        public IActionResult MovieSearch(string movieName)
        {
            var movieInfo = new Dictionary <string, object>();

            WebRequest.GetMovieDataAsync(movieName, response => {
                movieInfo = response;
            })
            .Wait();
            string name     = (string)((JObject)((JArray)movieInfo["results"])[0])["title"];
            float  rating   = (float)((JObject)((JArray)movieInfo["results"])[0])["vote_average"];
            string released = DateTime.ParseExact((string)((JObject)((JArray)movieInfo["results"])[0])["release_date"], "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture).ToString("MMMM dd, yyyy", System.Globalization.CultureInfo.InvariantCulture);

            MySqlConnector.Execute($"INSERT INTO movies (name, rating, released, created_at, updated_at) VALUE ('{name}','{rating}','{released}',NOW(),NOW())");
            return(RedirectToAction("Index"));
        }
Exemplo n.º 9
0
 public IActionResult addComment(string comment, int?messageid)
 {
     ViewBag.CommentErrors = new List <string>();
     if (comment == null || comment.Length < 4)
     {
         ViewBag.commentErrors.Add("The comment has to have at least 4 characters.");
         TempData["CommentErrors"] = ViewBag.commentErrors;
         return(RedirectToAction("Main"));
     }
     else
     {
         comment = comment.Replace("'", @"\'");
         string email        = HttpContext.Session.GetString("userpass");
         string selectQuery  = $"SELECT * FROM users WHERE email = '{email}'";
         var    younow       = MySqlConnector.Query(selectQuery);
         int?   yourid       = (int)younow[0]["id"];
         string rightNow     = DateTime.Now.ToString("yyyyMMddHHmmss");
         string commentQuery = $"INSERT INTO comments (comment,user_id,message_id,created_at,updated_at) VALUES ('{comment}',{yourid},{messageid},{rightNow},{rightNow})";
         MySqlConnector.Execute(commentQuery);
         return(RedirectToAction("Main"));
     }
 }
 public IActionResult updateNote(int id, string note)
 {
     MySqlConnector.Execute($"UPDATE notes SET note='{note}', updated_at=NOW() WHERE id={id}");
     return(RedirectToAction("Index"));
 }
 public IActionResult deleteNote(int id)
 {
     MySqlConnector.Execute($"DELETE FROM notes WHERE id={id}");
     return(RedirectToAction("Index"));
 }
 public IActionResult addNote(string title)
 {
     MySqlConnector.Execute($"INSERT INTO notes (title, created_at, updated_at) VALUES ('{title}', NOW(), NOW())");
     return(RedirectToAction("Index"));
 }
 public IActionResult PostQuote(string name, string quote){
     MySqlConnector.Execute($"INSERT INTO quotes (name,quote,created_at,updated_at) VALUES ('{name}', '{quote}', NOW(), NOW())");
     return RedirectToAction("Quotes");
 }