public ActionResult SendMessage() { if (!Authorize()) { return(RedirectToAction("RedirectByUser", "Home")); } User CurrentUser = (User)Session["CurrentUser"]; DateTime dateTime = DateTime.Now; dateTime = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second); Massage msg = new Massage { Read = false, date = dateTime, SenderUserName = CurrentUser.UserName, ReciverUserName = des.Encrypt(Request.Form["DoctorCombo"], "Galit@19"), msg = Request.Form["msg"] }; TryValidateModel(msg); if (ModelState.IsValid) { MassageDal msgDal = new MassageDal(); msgDal.Massages.Add(msg); msgDal.SaveChanges(); } return(View("MassagePage")); }
public ActionResult ReadMassage(string sender, DateTime date) { if (!Authorize()) { return(RedirectToAction("RedirectByUser", "Home")); } User CurrentUser = (User)Session["CurrentUser"]; MassageDal msgDal = new MassageDal(); string encryptedsender = des.Encrypt(sender, "Galit@19"); //Massage m = msgDal.Massages.FirstOrDefault<Massage>(x => x.ReciverUserName == CurrentUser.UserName && x.SenderUserName == encryptedsender); Massage m = msgDal.Massages.FirstOrDefault <Massage>(x => x.ReciverUserName == CurrentUser.UserName && x.SenderUserName == encryptedsender && x.date == date); m.Read = true; msgDal.SaveChanges(); return(RedirectToAction("ReciverMessages")); }