private void MakeOrder(MedOrder medOrder) { List <Volunteer> volonteri = _dbContext.Volunteers.ToList(); Patient patient = new Patient(); patient.Name = medOrder.Name; patient.Telephone = medOrder.Telephone; patient.Location = medOrder.Address; patient.Email = medOrder.Email; patient.Emergency = medOrder.Emergency; _dbContext.Patients.Add(patient); _dbContext.SaveChanges(); int Id = GetPatientId(patient); foreach (var medicineId in medOrder.Medicine) { PatientMedicineLink patientMedicineLink = new PatientMedicineLink { PatientId = Id, MedicineId = medOrder.Medicine[0] }; _dbContext.PatientMedicineLinks.Add(patientMedicineLink); _dbContext.SaveChanges(); } MailMessage mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); foreach (Volunteer volonter in volonteri) { mail.To.Add(volonter.Email); } mail.Subject = "Obavijest"; mail.Body = "Poštovani, <br />" + Environment.NewLine + " upravo je registrovana nova narudžba. Detalje možete provjeriti na Volonter hub-u. <br />" + Environment.NewLine + "CodeWizards tim"; mail.IsBodyHtml = true; ViewBag.From = mail.From; ViewBag.To = mail.To; ViewBag.Subject = mail.Subject; ViewBag.Body = mail.Body; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "hakaton2021!"); smtp.EnableSsl = true; smtp.Send(mail); }
public IActionResult OrderDone(MedOrder medOrder) { MakeOrder(medOrder); TempData["ShowAlert"] = "show"; return(RedirectToAction("Order")); }