public ActionResult create(string message) { string userlogin = User.Identity.Name; var checkit = db.Webmasters.Where(w => w.Username == userlogin); if (message != "") { ChatBox p = new ChatBox(); HttpPostedFileBase _file = Request.Files["file"]; if (_file.FileName != "") { if (_file.ContentLength > 0) { string filename = _file.FileName.Replace(" ", "_"); string filePath = Path.Combine(HttpContext.Server.MapPath("/Content/File/"), Path.GetFileName(filename)); _file.SaveAs(filePath); p.AttachFile = "/Content/File/" + _file.FileName.Replace(" ", "_"); } } p.Message = message; p.DateSend = DateTime.Now; if (checkit.Any()) { p.Sender = 0;//0: webmaster, 1: money pacific admin } else p.Sender = 1; p.WebmasterId = checkit.First().Id; db.ChatBoxes.AddObject(p); db.SaveChanges(); TransactionLogViewModel.AddLog(userlogin + " has just created the message on Pacific Messenger!", DateTime.Now); } return RedirectToAction("Create"); }
/// <summary> /// Deprecated Method for adding a new object to the ChatBoxes EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToChatBoxes(ChatBox chatBox) { base.AddObject("ChatBoxes", chatBox); }
public ActionResult sendWebmaster(string message, string[] selectWebmaster)// send message to webmaster { if (!string.IsNullOrEmpty(message)) { HttpPostedFileBase file = Request.Files["file"]; string fileAttach = ""; string listWebmaster=""; if (file.FileName != "") { if (file.ContentLength > 0)// co attach file { string filename = file.FileName.Replace(' ', '_'); string filePath = Path.Combine(HttpContext.Server.MapPath("/Content/File/"), Path.GetFileName(filename)); file.SaveAs(filePath); fileAttach = "/Content/File/" + file.FileName.Replace(" ", "_"); } } if (int.Parse(selectWebmaster[0]) != 0) { //send to 1 nguoi ChatBox msg = new ChatBox(); msg.AttachFile = fileAttach; msg.DateSend = DateTime.Now; msg.Message = message; msg.Sender = 1;//0: webmaster, 1: money pacific admin msg.WebmasterId = int.Parse(selectWebmaster[0]); Webmaster w = db.Webmasters.Single(ww=>ww.Id == msg.Id); listWebmaster+=w.Username+" "; db.ChatBoxes.AddObject(msg); } else // send to all webmaster { var webmaster = from web in db.Webmasters select web; foreach (var x in webmaster) { ChatBox msg = new ChatBox(); msg.AttachFile = fileAttach; msg.DateSend = DateTime.Now; msg.Message = message; msg.Sender = 1;//0: webmaster, 1: money pacific admin msg.WebmasterId = x.Id; Webmaster w = db.Webmasters.Single(ww=>ww.Id == msg.Id); listWebmaster+=w.Username+" "; db.ChatBoxes.AddObject(msg); } } TransactionLogViewModel.AddLog("Money Pacific Admin has just sent the message on Pacific Messenger to: "+listWebmaster, DateTime.Now); db.SaveChanges(); } return View("SendDone"); }
/// <summary> /// Create a new ChatBox object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="sender">Initial value of the Sender property.</param> /// <param name="webmasterId">Initial value of the WebmasterId property.</param> public static ChatBox CreateChatBox(global::System.Int32 id, global::System.Int32 sender, global::System.Int32 webmasterId) { ChatBox chatBox = new ChatBox(); chatBox.Id = id; chatBox.Sender = sender; chatBox.WebmasterId = webmasterId; return chatBox; }