public string addMessage(string str, string textOfMess) { string toWhom = str; string fromWhom = User.Identity.Name.ToString(); string write_messages = ""; StreamWriter w = new StreamWriter(@"E:\logWebSite5.txt"); w.WriteLine(write_messages); w.Close(); Mesage message = new Mesage(); message.towhom = toWhom; message.fromwhom = fromWhom; message.read = 0; message.message = textOfMess; message.date = DateTime.Now; using (var db = new Entities5()) { if (0 < db.Mesages.Count()) { message.Id = db.Mesages.Select(m => m.Id).ToList().Max() + 1; } else { message.Id = 0; } db.Mesages.Add(message); db.SaveChanges(); refreshChat(toWhom); return(write_messages); } }
public async Task <int> AddUpdate(AppointmentVM model) { var startDate = DateTime.Parse(model.StartDate); var endDate = DateTime.Parse(model.StartDate).AddMinutes(Convert.ToDouble(model.Duration)); var patient = _db.Users.FirstOrDefault(u => u.Id == model.PatientId); var doctor = _db.Users.FirstOrDefault(u => u.Id == model.DoctorId); //var message = new Mesage(new string[] { "*****@*****.**" }, "Test email async", "This is the content from our email.");//File.ReadAllText(path).Replace() var mesageBody = File.ReadAllText(Path.Combine(_emailConfig.TemplatesPath, "WelcomeEmail.cshtml")); mesageBody = mesageBody.Replace("[UserName]", model.AdminName); var message = new Mesage(new string[] { "*****@*****.**" }, "Test email async", mesageBody); if (model != null && model.Id > 0) { //update var appointment = _db.Appointments.Single(x => x.Id == model.Id); appointment.Title = model.Title; appointment.Description = model.Description; appointment.StartDate = startDate; appointment.EndDate = endDate; appointment.Duration = model.Duration; appointment.DoctorId = model.DoctorId; appointment.PatientId = model.PatientId; appointment.IsDoctorApproved = false; appointment.AdminId = model.AdminId; return(await _db.SaveChangesAsync() == 1 ? 1 : -1); } else { //create Appointment appointment = new Appointment() { Title = model.Title, Description = model.Description, StartDate = startDate, EndDate = endDate, Duration = model.Duration, DoctorId = model.DoctorId, PatientId = model.PatientId, IsDoctorApproved = false, AdminId = model.AdminId }; _db.Appointments.Add(appointment); /*await _emailSender.SendEmailAsync(doctor.Email, "Appointment Created", * $"Your appointment with {patient.Name} is created and in pending status"); * await _emailSender.SendEmailAsync(patient.Email, "Appointment Created", * $"Your appointment with {doctor.Name} is created and in pending status");*/ await _emailSender.SendEmailAsync(message); return(await _db.SaveChangesAsync() == 1 ? 2 : -2); } return(0); }
protected void Button1_Click(object sender, EventArgs e) { if (TextBox3.Text != "") { string toWhom = "all"; string fromWhom = ""; if (TextBox2.Text == "") { fromWhom = "Гість"; } else { fromWhom = TextBox2.Text; } Mesage message = new Mesage(); String write_messages = ""; message.towhom = toWhom; message.fromwhom = fromWhom; message.read = 0; message.message = TextBox3.Text; message.date = DateTime.Now; using (var db = new Entities5()) { System.Diagnostics.Debug.WriteLine("MESSAGE : " + db.Mesages.Count().ToString()); if (0 < db.Mesages.Count()) { message.Id = db.Mesages.Select(m => m.Id).ToList().Max() + 1; } else { message.Id = 0; } db.Mesages.Add(message); db.SaveChanges(); List <Mesage> messageHistory = db.Mesages.Where(m => (m.towhom.ToString() == toWhom)).ToList(); messageHistory.Reverse(); foreach (Mesage m in messageHistory) { write_messages += m.fromwhom + "(" + m.date.Value.ToShortTimeString().ToString() + "):" + "\n"; write_messages += " " + m.message + "\n"; } } TextBox1.Text = write_messages; } }