Esempio n. 1
0
        public ActionResult Login(LoginViewModel model)
        {
            using (TestElectricityKobiEntities db = new TestElectricityKobiEntities())
            {
                var customer = db.Customers.FirstOrDefault(x => (x.Email == model.UserName || x.UserName == model.UserName));

                if (customer != null && Crypto.VerifyHashedPassword(customer.Password, model.Password))
                {
                    Session["UserName"]    = $"{customer.FirstName} {customer.LastName}";
                    Session["UserEmail"]   = customer.Email;
                    Session["PhoneNumber"] = customer.PhoneNumber;
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Kullanıcı bulunamadı. Kullanıcı adı ya da şifre yanlış.");
                    return(View(model));
                }
            }
        }
        private void SendMail(string phoneNumber, string emailAddress, Stream file1 = null, string file1Name = "", Stream file2 = null, string file2Name = "")
        {
            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);

            smtpClient.Credentials    = new System.Net.NetworkCredential("*****@*****.**", "ab12*cd34");
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtpClient.EnableSsl      = true;

            MailMessage mail = new MailMessage();

            mail.Subject = "Yeni Müşteri Talebi"; // mail konusu yazılır
            var bodyString = new StringBuilder();

            bodyString.Append(string.IsNullOrWhiteSpace(phoneNumber) ? string.Empty : $"{DateTime.Now} tarihinde iletişim bilgisi Phone Number: {phoneNumber} ");
            bodyString.Append(string.IsNullOrWhiteSpace(emailAddress) ? string.Empty : string.IsNullOrWhiteSpace(phoneNumber) ? $"{DateTime.Now} tarihinde iletişim bilgisi EmailAddress: {emailAddress} " : $"EmailAddress: { emailAddress} ");
            bodyString.Append("olan müşteri talebi oluşmuştur.");
            //bodyString.Append("Fatura bilgileri ek'te yer almaktadır.");
            mail.Body = bodyString.ToString();
            //mail.Attachments.Add(new Attachment(file1, file1Name));
            //mail.Attachments.Add(new Attachment(file2, file2Name));
            mail.From = new MailAddress("*****@*****.**", "EnergyKobi"); // display ismi yazılır

            TestElectricityKobiEntities db = new TestElectricityKobiEntities();

            foreach (var email in db.SendEmailAddresses.ToList())
            {
                if (email.IsCC.HasValue && !email.IsCC.Value)
                {
                    mail.To.Add(new MailAddress(email.EmailAddress));
                }
                else
                {
                    mail.CC.Add(new MailAddress(email.EmailAddress));
                }
            }

            //Mail gönderimi yapılır
            smtpClient.Send(mail);
        }
        public ActionResult CustomerRequest(RegisterRequestModel model)
        {
            using (TestElectricityKobiEntities db = new TestElectricityKobiEntities())
            {
                //ViewBag.IsModalOpen = "false";
                TempData["IsModalOpen"] = "false";
                string phoneNumber = string.Empty;
                //string olarak gelen değeri, Decimal değer tipine dönüştürdük.
                //model.AverageElectricityBillDecimal = Convert.ToDecimal(model.AverageElectricityBill);
                if (!string.IsNullOrWhiteSpace(model.PhoneNumber))
                {
                    phoneNumber = new String(model.PhoneNumber.Where(Char.IsDigit).ToArray());
                }

                var customerRequest = new CustomerRequest
                {
                    FirstName              = string.Empty,
                    LastName               = string.Empty,
                    PhoneNumber            = phoneNumber,
                    CompanyName            = string.Empty,
                    SubscriberGroupId      = 4,
                    AverageElectricityBill = default(decimal),
                    Email = string.IsNullOrWhiteSpace(model.Email) ? string.Empty : model.Email
                };

                db.CustomerRequests.Add(customerRequest);
                db.SaveChanges();
                TempData["IsModalOpen"] = "true";

                //var customerRequestId = customerRequest.Id;

                //var fileList = new List<HttpPostedFileBase>();
                //fileList.Add(model.Attachment1);
                //fileList.Add(model.Attachment2);

                //foreach (var file in fileList)
                //{
                //    byte[] billDocumentBinary = null;

                //    if (file != null)
                //    {
                //        try
                //        {
                //            using (Stream inputStream = file.InputStream)
                //            {
                //                MemoryStream memoryStream = inputStream as MemoryStream;
                //                if (memoryStream == null)
                //                {
                //                    memoryStream = new MemoryStream();
                //                    inputStream.CopyTo(memoryStream);
                //                }
                //                billDocumentBinary = memoryStream.ToArray();
                //            }

                //            db.BillDocuments.Add(new BillDocument { FileName = file.FileName, FileBinary = billDocumentBinary, CustomerRequestId = customerRequestId });
                //            db.SaveChanges();
                //            TempData["IsModalOpen"] = "true";
                //        }
                //        catch (Exception ex)
                //        {
                //            return RedirectToAction("Index", "Home");
                //        }
                //    }
                //}

                SendMail(phoneNumber, model.Email, null, string.Empty, null, string.Empty);

                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 4
0
        public ActionResult Register(RegisterViewModel model)
        {
            using (TestElectricityKobiEntities db = new TestElectricityKobiEntities())
            {
                try
                {
                    var hashPassword = Crypto.HashPassword(model.Password);
                    var phoneNumber  = new String(model.PhoneNumber.Where(Char.IsDigit).ToArray());

                    db.Customers.Add(new Customer
                    {
                        FirstName    = model.FirstName,
                        LastName     = model.LastName,
                        UserName     = model.UserName,
                        Password     = hashPassword,
                        Email        = model.Email,
                        ConfirmEmail = model.Email,
                        PhoneNumber  = phoneNumber
                    });

                    db.SaveChanges();

                    #region Email Gönderimi

                    SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);

                    smtpClient.Credentials    = new System.Net.NetworkCredential("*****@*****.**", "ab12*cd34");
                    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtpClient.EnableSsl      = true;

                    MailMessage mail = new MailMessage();

                    mail.Subject = "Sisteme Yeni Üye Katıldı";                                                             // mail konusu yazılır
                    mail.Body    = $"{DateTime.Now} tarinde {model.Email} adresine sahip kullanıcı sisteme kaydolmuştur."; //mail içeriği yazılır
                    mail.From    = new MailAddress("*****@*****.**", "EnergyKobi");                        // display ismi yazılır

                    foreach (var email in db.SendEmailAddresses.ToList())
                    {
                        if (email.IsCC.HasValue && !email.IsCC.Value)
                        {
                            mail.To.Add(new MailAddress(email.EmailAddress));
                        }
                        else
                        {
                            mail.CC.Add(new MailAddress(email.EmailAddress));
                        }
                    }

                    //Mail gönderimi yapılır
                    smtpClient.Send(mail);

                    #endregion

                    return(RedirectToAction("Login", "Login"));
                }
                catch (Exception ex)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
        }