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")); } }
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")); } } }