public void Send(String ReciverID, string msg) { var userManager = Ctx.ApplicationUserManager; var theardManager = Ctx.TheardManager; var historyManager = Ctx.HistoryManager; var reciver = ctx.Users.Find(ReciverID); var sender = ctx.Users.Find(Context.User.Identity.GetUserId()); var reciverlList = reciver.ConIDs.Select(e => e.ConnectionId).ToList(); var msgStatues = (reciverlList.Count != 0); reciverlList.AddRange(sender.ConIDs.Select(e => e.ConnectionId)); var theard = sender.Theard.FirstOrDefault(e => e.Users.Contains(reciver)); if (theard == null) { theard = new Theard(); //theardManager.Add(theard); theard.Users.Add(sender); theard.Users.Add(reciver); sender.Theard.Add(theard); reciver.Theard.Add(theard); //theardManager.Update(theard); theard.Users.OrderBy(e => e.UserName); ctx.Theard.Add(theard); ctx.SaveChanges(); } var history = new History { Reciver = reciver, Sender = sender, Message = msg, Statues = Statues.Sent, DateTime = DateTime.Now }; if (msgStatues) { history.Statues = Statues.Delivered; } //historyManager.Add(history); theard.History.Add(history); ctx.History.Add(history); ctx.SaveChanges(); ctx.Theard.Attach(theard); ctx.Entry(theard).State = EntityState.Modified; ctx.SaveChanges(); var orderedusers = theard.Users.OrderBy(e => e.UserName); var id = ""; foreach (var item in orderedusers) { id += item.Id; } Clients.Clients(reciverlList).newMessage(sender.Id.ToString(), msg, id); }
public ActionResult Edit(int id, Theard collection) { try { // TODO: Add update logic here var res = td.UpdateTheard(collection); if (res) { return(RedirectToAction("Index", "MTheard")); } else { ModelState.AddModelError("", "An error occurred!"); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(Theard collection) { try { // TODO: Add insert logic here var res = td.InsertTheard(collection); if (res) { return(RedirectToAction("Index", "MTheard")); } else { ModelState.AddModelError("", "An error occurred!"); } return(RedirectToAction("Index")); } catch { return(View()); } }