Example #1
0
        public bool Add(ChatMessage newChatMessage)
        {
            bool result = false;

            try
            {
                using (var context = new ApplicationDbContext())
                {

                        var message = context.ChatMessages.Create();
                        message.Message = newChatMessage.Message;
                        message.ChatUserID = newChatMessage.ChatUserID;
                        message.RepliedBy = newChatMessage.RepliedBy;
                        message.Date = DateTime.Now;
                        context.ChatMessages.Add(message);
                        context.SaveChanges();
                        Clients.All.messageCreated(message);
                        result = true;

                }
            }
            catch (Exception)
            {
                Clients.Caller.raiseError("Unable to create a new Person.");
            }

            return result;
        }
Example #2
0
 public ActionResult Support(int chatUserId)
 {
     ChatMessage model = new ChatMessage();
     if (User.Identity.IsAuthenticated)
     {
         var chatUser = db.ChatUsers.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
         ViewBag.RepliedBy = User.Identity.Name;
         model.ChatUserID = chatUserId;
     }
     return View(model);
 }
Example #3
0
        public ActionResult Index()
        {
            ChatMessage model = new ChatMessage();
            var chatUser = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
            ViewBag.UserId = 1;
            model.RepliedBy = User.Identity.Name;

            List<ChatUser> usersOnline = db.ChatUsers.Where(u => u.IsOnline == true).ToList();
            ViewBag.OnlineUsers = usersOnline;
            return View(model);
        }
 public ActionResult Index()
 {
     ChatMessage model = new ChatMessage();
     if (User.Identity.IsAuthenticated)
     {
         var chatUser = db.ChatUsers.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
         ViewBag.ChatUserID = chatUser.ID;
         model.ChatUserID = chatUser.ID;
     }
     return View(model);
 }
Example #5
0
        public bool Update(ChatMessage updatedChatMessage)
        {
            bool result = false;

            try
            {
                using (var context = new ApplicationDbContext())
                {
                    var existingChatMessage = context.ChatMessages.FirstOrDefault(x => x.ID == updatedChatMessage.ID);

                    if (existingChatMessage != null)
                    {
                        existingChatMessage.Message = updatedChatMessage.Message;
                        existingChatMessage.ChatUserID = updatedChatMessage.ChatUserID;
                        existingChatMessage.RepliedBy = updatedChatMessage.RepliedBy;

                        context.SaveChanges();
                        Clients.All.chatMessageUpdated(existingChatMessage);
                        result = true;
                    }
                }
            }
            catch (Exception)
            {
                Clients.Caller.raiseError("Unable to update the Person.");
            }

            return result;
        }