Esempio n. 1
0
        public ActionResult Contact()
        {
            var vm = new Models.ContactViewModel();
            vm.Address = "";
            vm.TimeSent = DateTime.UtcNow;

            return View(vm);
        }
Esempio n. 2
0
        public ActionResult Contact(Models.ContactViewModel contactInfo)
        {
            if (!ModelState.IsValid)
            {
                return(View(contactInfo));
            }//if - modelstate not valid

            // make the email
            string body = string.Format(
                $"firstname: {contactInfo.firstname}<br />"
                + $"lastname: {contactInfo.lastname}<br />"
                + $"email: {contactInfo.email}<br />"
                + $"subject: {contactInfo.subject}<br />"
                + $"message: {contactInfo.message}");

            // create the mailmessage object - System.Net.Mail

            MailMessage msg = new MailMessage(
                "*****@*****.**",
                "*****@*****.**",
                contactInfo.subject, body);

            //set MailMessage objects properties
            msg.IsBodyHtml = true;
            msg.CC.Add("*****@*****.**");

            // SMTP client needs created and config'd
            SmtpClient client = new SmtpClient("mail.jenmcook.com");

            client.Credentials = new NetworkCredential("*****@*****.**", "FakePassword");
            client.EnableSsl   = false;
            client.Port        = 25;

            //use SMTP client object to sent email
            using (client)
            {
                try
                {
                    client.Send(msg);
                } // try
                catch
                {
                    //message if failed to send
                    ViewBag.ErrorMessage = "An error has occurred in sending your message.\n"
                                           + "Please try again";
                    return(View());
                } //catch
            }     // using - cient

            //if message is sent successfully
            return(View("ContactConfirmation", contactInfo));
        } //  email
Esempio n. 3
0
        public ActionResult Edit([Bind(Include = "ID, Ime, Prezime, Telefon, Email")] Models.ContactViewModel contact)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AdresarConnectionString"].ToString()))
                    {
                        conn.Open();

                        using (SqlCommand cmd = new SqlCommand("[dbo].[SP_IzmijeniKontakt]", conn))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.Add(new SqlParameter("@ID", contact.ID));
                            cmd.Parameters.Add(new SqlParameter("@Ime", contact.Ime));
                            cmd.Parameters.Add(new SqlParameter("@Prezime", contact.Prezime));
                            cmd.Parameters.Add(new SqlParameter("@Telefon", contact.Telefon));
                            cmd.Parameters.Add(new SqlParameter("@Email", contact.Email));
                            cmd.CommandTimeout = 140;

                            using (SqlDataReader rdr = cmd.ExecuteReader())
                            {
                                while (rdr.Read())
                                {
                                    contact = new Models.ContactViewModel()
                                    {
                                        ID               = (Int64)rdr["ID"],
                                        Ime              = (String)rdr["Ime"],
                                        Prezime          = (String)rdr["Prezime"],
                                        Telefon          = (String)rdr["Telefon"],
                                        Email            = (rdr["Email"] != DBNull.Value) ? (String)rdr["Email"] : null,
                                        VrijemeKreiranja = ((DateTimeOffset)rdr["VrijemeKreiranja"]).ToString("G"),
                                        ZadnjaIzmjena    = ((DateTimeOffset)rdr["ZadnjaIzmjena"]).ToString("G")
                                    };
                                }
                            }
                        }
                    }
                    TempData["Success"] = Resources.SuccessEdit;

                    return(View("Edit", contact));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(contact));
        }
Esempio n. 4
0
        public ActionResult Contact(Models.ContactViewModel contactInfo)
        {
            if (!ModelState.IsValid)
            {
                return(View(contactInfo));
            }

            string body = string.Format(
                $"Name: {contactInfo.Name}<br />"
                + $"Email: {contactInfo.Email}<br />"
                + $"Subject: {contactInfo.Subject}<br />"
                + $"Message: {contactInfo.Message}");

            MailMessage msg = new MailMessage(
                "*****@*****.**",
                "*****@*****.**",
                contactInfo.Subject,
                body);

            msg.IsBodyHtml = true;
            msg.CC.Add("*****@*****.**");
            msg.Priority = MailPriority.High;

            SmtpClient client = new SmtpClient("mail.hjkangweb.com");

            client.Credentials = new NetworkCredential("*****@*****.**", "kang1226@@");
            client.EnableSsl   = false;
            client.Port        = 8889;

            using (client)
            {
                try
                {
                    client.Send(msg);
                }
                catch
                {
                    ViewBag.ErrorMessage = "There was an error sending your message.\n" + "Please try again";
                    return(View());
                }
            }

            return(View("ContactConfirmation", contactInfo));
        }
Esempio n. 5
0
        public ActionResult Contact(Models.ContactViewModel cont)
        {
            //SUBMITTING COMPLAINT
            using (SqlConnection sqlConnection = new SqlConnection(connectString))
            {
                sqlConnection.Open();
                string query = "INSERT INTO COMPLAINT(COMPLAINTSUBJECT,COMPLAINTDETAILS,USEREMAIL) VALUES " +
                               "(@title,@body,@email)";
                SqlCommand sqlCommand = new SqlCommand(query, sqlConnection);
                sqlCommand.Parameters.AddWithValue("@title", cont.Title);
                sqlCommand.Parameters.AddWithValue("@body", cont.Complaint);
                sqlCommand.Parameters.AddWithValue("@email", cont.Email);

                sqlCommand.ExecuteNonQuery();
            }
            //REDIRECTING TO HOME PAGE
            TempData["msg"] = "<script>alert('You have successfully sent us a complaint. We will look into it as soon as possible.')</script>";
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 6
0
        // GET: Contacts/Edit/5
        public ActionResult Edit(int id)
        {
            Models.ContactViewModel contact = new Models.ContactViewModel();

            try
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AdresarConnectionString"].ToString()))
                {
                    conn.Open();

                    using (SqlCommand cmd = new SqlCommand("[dbo].[SP_Kontakt]", conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@ID", id));

                        using (SqlDataReader rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                contact = new Models.ContactViewModel()
                                {
                                    ID               = (Int64)rdr["ID"],
                                    Ime              = (String)rdr["Ime"],
                                    Prezime          = (String)rdr["Prezime"],
                                    Telefon          = (String)rdr["Telefon"],
                                    Email            = (rdr["Email"] != DBNull.Value) ? (String)rdr["Email"] : null,
                                    VrijemeKreiranja = ((DateTimeOffset)rdr["VrijemeKreiranja"]).ToString("G"),
                                    ZadnjaIzmjena    = ((DateTimeOffset)rdr["ZadnjaIzmjena"]).ToString("G")
                                };
                            }
                        }
                    }
                }

                return(View(contact));
            }
            catch
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(contact));
        }
Esempio n. 7
0
        public ActionResult Contact(Models.ContactViewModel contactInfo)
        {
            if (!ModelState.IsValid)
            {
                return(View(contactInfo));
            }

            string body = string.Format(
                $"Name: {contactInfo.Name}<br />"
                + $"Email: {contactInfo.Email}<br/>"
                + $"Subject: {contactInfo.Subject}<br/>"
                + $"Message: {contactInfo.Message}<br/>");

            MailMessage msg = new MailMessage(
                "*****@*****.**",
                "*****@*****.**",
                contactInfo.Subject, body);

            msg.IsBodyHtml = true;
            msg.CC.Add("*****@*****.**");

            SmtpClient client = new SmtpClient("mail.jenmcook.com");

            client.Credentials = new NetworkCredential("*****@*****.**", "FakePassword");
            client.EnableSsl   = false;
            client.Port        = 8889;

            using (client)
            {
                try
                {
                    client.Send(msg);
                }
                catch
                {
                    ViewBag.ErrorMessage = "An error was encountered sending your message.\n"
                                           + "Please try again.";
                    return(View());
                }
            }
            return(View("ContactConfirmation", contactInfo));
        }
Esempio n. 8
0
        [ValidateAntiForgeryToken]//validates token generated from the GET request & protects against cross site scripting
        public ActionResult Contact(Models.ContactViewModel contactInfo)
        {
            //1. Check that the Model information is valid
            //Verify ModelState.IsValid -- we need to ensure that we get correct info that passed our validation. (server side, benefits biz/dev.)
            //We need to add !ModelState.IsValid to return a View(); of the form with the data that the user submitted.
            if (!ModelState.IsValid)
            {
                //If the ModelState is not valid return a View of the contact w/ validation messages.
                return(View(contactInfo));
            }//end if !ModelState.IsValid

            //********************************************
            //If the model was valid, we need to process and send the EMAIL
            //We accept a ContavtViewModel object in order to process the users submitted data via the COntact View (Strongly Typed)
            //Due to the way the @Html methods render, the "name" attr. is created and assigned to the correct ContactViewModel property
            //1. Create the body/content for the email from the ContactViewModel properties
            string body = string.Format(
                $"Name: {contactInfo.Name}<br />"
                + $"Email: {contactInfo.Email}<br />"
                + $"Subject: {contactInfo.Subject}<br />"
                + $"Message:<br/> {contactInfo.Message}");
            //2. Create and configure the MailMessage object. (to/from addresss, subject, email content.)
            //.Addded a using statement System.Net.Mail
            MailMessage msg = new MailMessage("*****@*****.**",         //from address
                                              "*****@*****.**", //to address
                                              contactInfo.Subject,             //subject of email
                                              body);                           //email body

            //3. Set properties of the MailMessage object (cc, bcc, set mail priorty, etc.)
            msg.IsBodyHtml = true;               //
            msg.CC.Add("*****@*****.**");
            /*msg.Priority = MailPriority.High*/ //optional
            //4. create and configure the SMTP client (simple mail transfer protocol) (this will send the actual email)
            //added using System.Net
            SmtpClient client = new SmtpClient("mail.jshdevco.com");

            client.Credentials = new NetworkCredential("*****@*****.**", "COopers21@!");
            client.EnableSsl   = false;
            client.Port        = 8889;
            //5. use the SMTP client object to try and send an email message. We will need to make sure that we close the SMTP client object
            //when we are done attempting to send the email.
            using (client)
            {
                //automatically close and clean up resources related to the smtp client object
                //when its done, it is deleted and gone. (garbage collection)
                try
                {
                    //we are going to try to send the email message (with our client)
                    client.Send(msg);
                }
                catch
                {
                    //Failed to send - we will add a message and display it to the user on the layout
                    //create a ViewBag object to return an error to the user and send them back to the ContactView
                    ViewBag.ErrorMessage = "An error occurred!\nPlease try again.";
                    return(View());
                } //end catch
            }     //end using
            //send successful we will send the user to a ContactConfirmation view and send the ContactInfo object with it.
            //return View();
            return(View("ContactConfirmation", contactInfo));
        }
Esempio n. 9
0
        public JsonResult Index(Models.ContactsSearchViewModel contactsSearchViewModel)
        {
            List <Models.ContactViewModel> cl = new List <Models.ContactViewModel>();

            Models.ContactViewModel      contact;
            Models.ContactsListViewModel result = new Models.ContactsListViewModel();
            int totalRecords = 0;

            // Paging
            if (contactsSearchViewModel.length != 0)
            {
                contactsSearchViewModel.page = (contactsSearchViewModel.start / contactsSearchViewModel.length) + 1;
            }
            else
            {
                contactsSearchViewModel.page = 1;
            }

            contactsSearchViewModel.pageSize = contactsSearchViewModel.length;

            // Sorting
            Int32 columnNumber = Convert.ToInt32(Request.Form.GetValues("order[0][column]")[0]);

            contactsSearchViewModel.sortColumn = Request.Form.GetValues("columns[" + columnNumber + "][data]")[0];
            contactsSearchViewModel.sortOrder  = Request.Form.GetValues("order[0][dir]")[0];

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AdresarConnectionString"].ToString()))
            {
                try
                {
                    conn.Open();

                    using (SqlCommand cmd = new SqlCommand("[dbo].[SP_ListaKontakata]", conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@Filter", contactsSearchViewModel.search));
                        cmd.Parameters.Add(new SqlParameter("@SortColumn", contactsSearchViewModel.sortColumn));
                        cmd.Parameters.Add(new SqlParameter("@SortOrder", contactsSearchViewModel.sortOrder));
                        cmd.Parameters.Add(new SqlParameter("@Page", contactsSearchViewModel.page));
                        cmd.Parameters.Add(new SqlParameter("@PageSize", contactsSearchViewModel.pageSize));
                        cmd.CommandTimeout = 140;

                        using (SqlDataReader rdr = cmd.ExecuteReader())
                        {
                            Int64 id = 0;

                            while (rdr.Read())
                            {
                                id = (Int64)rdr["ID"];

                                contact = new Models.ContactViewModel()
                                {
                                    ID               = id,
                                    Ime              = (String)rdr["Ime"],
                                    Prezime          = (String)rdr["Prezime"],
                                    Telefon          = (String)rdr["Telefon"],
                                    Email            = (rdr["Email"] != DBNull.Value) ? (String)rdr["Email"] : null,
                                    VrijemeKreiranja = ((DateTimeOffset)rdr["VrijemeKreiranja"]).ToString("G"),
                                    ZadnjaIzmjena    = ((DateTimeOffset)rdr["ZadnjaIzmjena"]).ToString("G")
                                };

                                totalRecords = (int)rdr["TotalRecords"];
                                cl.Add(contact);
                            }
                        }
                    }

                    result.draw            = Convert.ToInt32(contactsSearchViewModel.draw);
                    result.recordsTotal    = totalRecords;
                    result.recordsFiltered = totalRecords;
                    result.data            = cl;

                    return(Json(result));
                }
                catch (Exception ex)
                {
                    //wtt.error = "Server is busy! Please try later.";
                }
                finally
                {
                    if (conn.State == System.Data.ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }

            return(Json(result));
        }