public ActionResult AddMsgToChat(JobMSG model) { using (ApplicationDbContext db = new ApplicationDbContext()) { var uid = User.Identity.GetUserId(); db.Jobs.FirstOrDefault(x => x.ID == model.NewMSG.job.ID).JobMSGS.Add(new JobMSGS { job = db.Jobs.SingleOrDefault(x => x.ID == model.NewMSG.job.ID), Sender = db.Users.FirstOrDefault(x => x.Id == uid), Text = model.NewMSG.Text }); db.SaveChanges(); return(new EmptyResult()); } }
public ActionResult GetMSG(int id) { using (ApplicationDbContext db = new ApplicationDbContext()) { JobMSG model = new JobMSG(); var list = db.JobMSGs.Include("job").Include("Sender").Where(x => x.job.ID == id).ToList(); foreach (var el in list) { model.msgs.Add(el); } model.NewMSG = new JobMSGS(); model.NewMSG.job = new Job(); model.NewMSG.job.ID = id; return(PartialView("_Chat", model)); } }