Ejemplo n.º 1
0
        public async Task <string> Post([FromBody] MessageVM msg)
        {
            string returnMessage = string.Empty;

            try
            {
                //////////// to be removed
                this.BroadCastAll = true;
                //////////
                this.referenceUserName = msg.ReferenceUserName;
                await this.SetNotificationHeaderDetails(msg.NotificationTypeId, msg.Reference);

                msg.Header                    = this.NotificationHeader;
                msg.Payload                   = this.NotifcationBody;
                msg.notificationGroupId       = this.notificationGroupId;
                msg.BroadCastSpecificUserList = this.BroadCastUserList;
                msg.BroadCastAll              = this.BroadCastAll;


                await _hubContext.Clients.All.BroadcastMessage(msg);

                await _hubContext.Clients.User("5").BroadcastMessage(msg);

                returnMessage = msg.Header + " |  " + msg.Payload + " | " + msg.BroadCastSpecificUserList.ToString();
            }
            catch (Exception e)
            {
                returnMessage = e.ToString();
            }
            return(returnMessage);
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            try
            {
                ViewBag.Error = false;
                var tempData = (MessageVM)TempData["UserMessage"];
                TempData["UserMessage"] = tempData;
                ViewBag.DisplayName     = Thread.CurrentPrincipal.Identity.Name;
                if (ViewBag.Path != null)
                {
                    m_LdapService = new LdapService(ViewBag.Path);
                    var usuario = m_LdapService.Search();
                    ViewBag.DisplayName = usuario.Nome;
                    return(View(usuario));
                }

                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.Error           = true;
                TempData["UserMessage"] = new MessageVM()
                {
                    CssClassName = "alert-error", Title = "Erro", Message = ex.Message
                };
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(View());
            }
        }
Ejemplo n.º 3
0
        public IActionResult Message(string su = null, string idchat = null, string srch_mess = null)
        {
            ChatsVM mainchats = new ChatsVM();

            if (su != null)
            {
                mainchats.chats = repo.GetUserChats(Current_idUser, su);
            }
            else
            {
                mainchats.chats = repo.GetUserChats(Current_idUser, null);
            }
            if (idchat != null)
            {
                MessageVM mvm = new MessageVM();
                mvm.myprofile = repo.GetUserById(User.Identity.Name);
                if (srch_mess != null)
                {
                    mvm.messages         = repo.GetChatMessages(Convert.ToInt32(idchat)).Where(x => x.Text != null && x.Text.IndexOf(srch_mess) != -1).ToList();
                    mainchats.search_str = srch_mess;
                }
                else
                {
                    mvm.messages = repo.GetChatMessages(Convert.ToInt32(idchat));
                }
                mvm.chat_attachments  = repo.GetChatAttach(Convert.ToInt32(idchat));
                mvm.FavMessages       = repo.GetMessFavo(Convert.ToInt32(idchat), Current_idUser).Select(x => x.Id_Mess).ToList();
                mainchats.idChat      = idchat;
                mainchats.currentChat = mainchats.chats.Where(x => x.ChatId == idchat).FirstOrDefault();
                mainchats.messageVm   = mvm;
            }
            return(View(mainchats));
        }
Ejemplo n.º 4
0
        public async Task SendMessageAsync(ChatMessage chat)
        {
            try
            {
                if (chat.ChatId == 0)
                {
                    MessageVM msg = new MessageVM();
                    msg.Message    = chat.Text;
                    msg.ReceiverId = chat.ReceiverId;
                    msg.SenderId   = chat.SenderId;
                    Result result = await _genericService.Entry(msg);

                    if (result.IsSuccess)
                    {
                        chat.IsChnaged = false;
                        chat.ChatId    = Convert.ToInt64(((string[])result.Data)[0]);
                        chat.Time      = ((string[])result.Data)[1];
                        await Clients.All.MessageReceivedFromHub(chat);

                        //await Clients.User(chat.ReceiverId.ToString()).MessageReceivedFromHub(chat);
                    }
                }
                else
                {
                    chat.IsChnaged = true;
                    await Clients.All.MessageReceivedFromHub(chat);
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 5
0
        public List <MessageVM> GetMessages()
        {
            List <MessageVM> messages = new List <MessageVM>();

            using (SqlConnection con = new SqlConnection(connectionString))

            {
                SqlCommand cmd = new SqlCommand("Get_Messages", con);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                //cmd.ExecuteNonQuery();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    MessageVM message = new MessageVM();
                    message.Email   = rdr["Email"].ToString();
                    message.Name    = rdr["Name"].ToString();
                    message.Subject = rdr["Subject"].ToString();
                    message.Message = rdr["Message"].ToString();
                    messages.Add(message);
                }
                con.Close();
            }
            return(messages);
        }
Ejemplo n.º 6
0
        public IActionResult SendMessage(MessageVM messageVM)
        {
            var success   = true;
            var message   = string.Empty;
            var selectors = string.Empty;

            if (ModelState.IsValid)
            {
                try
                {
                    messageVM.Status = Status.P;
                    UnitOfWork.Message.MergeMessage(messageVM);
                }
                catch (Exception)
                {
                    success = false;
                    message = "Internal error. Please, contact support team!";
                }
            }
            else
            {
                success   = false;
                message   = $"Errors occured:<br /> -{string.Join("<br />- ", ModelState.Values.Where(x => x.ValidationState == ModelValidationState.Invalid).SelectMany(x => x.Errors.Select(e => e.ErrorMessage)))}";
                selectors = string.Join(',', ModelState.AllErrors().Select(x => $"[name={x.Key}]"));
            }

            return(Json(new { success, message, selectors }));
        }
Ejemplo n.º 7
0
        public Task SendMessageToUser()
        {
            MessageVM messageVM = new MessageVM();

            return(null);
            //  return _hubContext.Clients.Client(connectionId).BroadcastMessage(messageVM);
        }
Ejemplo n.º 8
0
        public ActionResult Reset(string Email, string EmailConfirmationCode)
        {
            // The user filled out the reset form.

            MessageVM result = new MessageVM()
            {
                MMessage = ""
            };

            try
            {
                User user = _db.Users.FirstOrDefault(u => u.EmailConfirmationCode == EmailConfirmationCode && u.Email == Email);
                if (user != null)
                {
                    _db.Users.Remove(user);
                    _db.SaveChanges();
                }

                // Whether or not the user's account was found, the result is 'Success!' to mislead imposters.
                result.MMessage = "Your account has been succesfully deleted.";
            } catch (Exception e)
            {
                // Something went technically wrong. Inform the user.
                result.MMessage = "Due to technical problems your account has not been deleted. The server said: " + e.Message;
            }

            return(View("App", result));
        }
Ejemplo n.º 9
0
 public async Task <IActionResult> Create(CreateLocationViewModel model)
 {
     if (ModelState.IsValid)
     {
         Location newLocation = new Location()
         {
             LocationId   = Guid.NewGuid().ToString(),
             LocationName = model.LocationName
         };
         if (await _locationServices.CreateLocation(newLocation))
         {
             var userMessage = new MessageVM()
             {
                 CssClassName = "alert alert-success", Title = "Thành công", Message = "Tạo địa điểm mới thành công"
             };
             TempData["UserMessage"] = JsonConvert.SerializeObject(userMessage);
         }
         else
         {
             var userMessage = new MessageVM()
             {
                 CssClassName = "alert alert-danger", Title = "Không thành công", Message = "Đã có lỗi khi thao tác, xin mời thử lại"
             };
             TempData["UserMessage"] = JsonConvert.SerializeObject(userMessage);
         };
     }
     return(RedirectToAction(actionName: "Index", controllerName: "Location"));
 }
Ejemplo n.º 10
0
        public void SaveMessage(MessageVM message)
        {
            var messageToAdd = MapModels(message);

            _repository.Create(messageToAdd);
            _repository.Save();
        }
Ejemplo n.º 11
0
        public ActionResult Create(MessageVM messageVM)
        {
            if (ModelState.IsValid)
            {
                if (messageAppService.SaveNewMessage(messageVM))
                {
                    // Push Notify All Connect Client to Increase Notification Count
                    IHubContext messageHubContext =
                        GlobalHost.ConnectionManager.GetHubContext <MessageHub>();
                    messageHubContext.Clients.All.NotifyNewMessage(messageVM.DealerId);

                    notificationAppService.IncrementNotificationCount(messageVM.DealerId);

                    return(RedirectToAction("Index", "Home", new { area = "" }));
                }
                else
                {
                    return(View(messageVM));
                }
            }
            else
            {
                return(View(messageVM));
            }
        }
        public ActionResult Contact(MessageVM viewModel)
        {
            // Check if the model is valid
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            // Create a Message object
            Message message = new Message()
            {
                FirstName   = viewModel.FirstName,
                LastName    = viewModel.LastName,
                Email       = viewModel.Email,
                Subject     = viewModel.Subject,
                Description = viewModel.Description,
            };

            // Add the message to the database
            if (!new Managers.MessageManager().AddMessage(message))
            {
                ModelState.AddModelError("", "An error has occured.");
                return(View(viewModel));
            }

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 13
0
        public async Task <Result> Get([FromQuery] MessageVM model = null)
        {
            if (User.Identity.IsAuthenticated)
            {
                UserVM objLoggedInUser = new UserVM();
                var    claimsIndentity = HttpContext.User.Identity as ClaimsIdentity;
                var    userClaims      = claimsIndentity.Claims;

                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    foreach (var claim in userClaims)
                    {
                        var cType  = claim.Type;
                        var cValue = claim.Value;
                        switch (cType)
                        {
                        case "USERID":
                            objLoggedInUser.UserId = Convert.ToInt64(cValue);
                            break;

                        case "EMAIL":
                            objLoggedInUser.Email = cValue;
                            break;
                        }
                    }
                }
                if (objLoggedInUser.UserId == model.SenderId)
                {
                    return(await _genericService.Get(model));
                }
            }
            return(null);
        }
Ejemplo n.º 14
0
        public int RegisterUser(User user)
        {
            if (RegisteredUsers.Exists(x => x.UserName.Equals(user.UserName, StringComparison.OrdinalIgnoreCase)))
            {
                return((int)RegistrationEnum.UsernameAlreadyExists);
            }

            user.RegistrationDate = DateTime.UtcNow;
            _repository.RegisterUser(user);

            _registeredUsers.Add(new UserVM()
            {
                UserName = user.UserName, FirstName = user.FirstName, LastName = user.LastName, StateId = (int)UserStateEnum.Online
            });
            userChangedState(user.UserName, (int)UserStateEnum.Online);

            var message = new MessageVM()
            {
                Content = $"{user.UserName} joined #ChatApp!", SenderUsername = "", MessageId = 0, TimeSent = DateTime.UtcNow
            };

            _repository.StoreChannelMessage(1L, message.SenderUsername, message.Content, message.TimeSent);
            NotifyChannelUsers(message, 1L);

            _userCallbacks.Add(user, OperationContext.Current.GetCallbackChannel <IChatServiceCallback>());

            return((int)RegistrationEnum.Successful);
        }
        public ActionResult SendMessage(MessageVM msg)
        {
            var db = new DatabaseAccess();

            db.SendMessage(msg, User.Identity.Name);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 16
0
        public MessageVM GetDetailsVM(int id)
        {
            try
            {
                IActionResult HttpResult = messageCont.Get(id);

                if (HttpResult is OkObjectResult)
                {
                    var       result  = HttpResult as OkObjectResult;
                    Message   content = result.Value as Message;
                    User      user    = client.GetUser("http://localhost:51520/", "api/User/" + content.SenderUserID);
                    MessageVM vm      = new MessageVM()
                    {
                        DateSent       = content.DateSent,
                        MessageContent = content.MessageContent,
                        Title          = content.Title,
                        UserName       = user.Name
                    };

                    return(vm);
                }
                else
                {
                    return(new MessageVM());
                }
            }
            catch (Exception e)
            {
                return(new MessageVM());
            }
        }
Ejemplo n.º 17
0
        public IActionResult Inbox()
        {
            if (HttpContext.Session.GetString("Guardian") != null &&
                HttpContext.Session.GetString("Guardian") != "Expired")
            {
                var guardian   = HttpContext.Session.GetString("Guardian");
                var guardianId = db.Guardian.Where(a => a.UserName == guardian).FirstOrDefault();
                ViewBag.GuardianName = guardianId.FirstName + " " + guardianId.LastName;

                ViewBag.StuName = db.Student.Where(b => b.GuardianId == guardianId.id).ToList();
                var msglist = db.MessageList.ToList();
                var querry  = from msg in msglist
                              where msg.GuardianId == guardianId.id & msg.SentBy == "tc"
                              select new
                {
                    id    = msg.Id,
                    title = msg.MessageTitle,
                    date  = msg.Date,
                    time  = msg.Time
                };
                //MessageList m = new MessageList();
                List <MessageVM> m = new List <MessageVM>();
                foreach (var item in querry)
                {
                    MessageVM ml = new MessageVM();
                    ml.MId    = item.id;
                    ml.MTitle = item.title;
                    ml.MDate  = item.date;
                    ml.MTime  = item.time;
                    m.Add(ml);
                }
                return(View(m));
            }
            return(RedirectToAction("Login"));
        }
Ejemplo n.º 18
0
        public IActionResult StatusMessage(string message)
        {
            MessageVM model = new MessageVM();

            model.Message = message;
            return(View(model));
        }
Ejemplo n.º 19
0
 public async Task <IActionResult> Create(CreateVehicleBrandViewModel model)
 {
     if (ModelState.IsValid)
     {
         VehicleBrand newBrand = new VehicleBrand()
         {
             BrandId   = Guid.NewGuid().ToString(),
             BrandName = model.BrandName
         };
         if (await _brandServices.CreateBrand(newBrand))
         {
             var userMessage = new MessageVM()
             {
                 CssClassName = "alert alert-success", Title = "Thành công", Message = "Tạo nhãn hiệu mới thành công"
             };
             TempData["UserMessage"] = JsonConvert.SerializeObject(userMessage);
         }
         else
         {
             var userMessage = new MessageVM()
             {
                 CssClassName = "alert alert-danger", Title = "Không thành công", Message = "Đã có lỗi khi thao tác, xin mời thử lại"
             };
             TempData["UserMessage"] = JsonConvert.SerializeObject(userMessage);
         };
     }
     return(RedirectToAction(actionName: "Index"));
 }
        public JsonResult GetMessages(string UserTo)
        {
            string         Username1 = User.Identity.Name;
            string         Username2 = UserTo;
            UserRepository Userdb    = new UserRepository();
            User           U1        = Userdb.GetByUsername(Username1);
            User           U2        = Userdb.GetByUsername(Username2);

            List <MessageVM> messages = new List <MessageVM>();
            MessageVM        msg      = new MessageVM();



            MessageRepository messageRepo = new MessageRepository();

            var msges = messageRepo.GetBySenderRecveiverUsername(U1, U2);

            for (int i = 0; i < msges.Count; i++)
            {
                msg          = new MessageVM();
                msg.Id       = msges[i].Id;
                msg.Text     = msges[i].Text;
                msg.Sender   = msges[i].Sender;
                msg.Receiver = msges[i].Receiver;
                msg.DateTime = msges[i].DateTime.ToString();
                msg.Deleted  = msges[i].Deleted;
                messages.Add(msg);
            }
            return(Json(messages, JsonRequestBehavior.AllowGet));
        }
        public IHttpActionResult GetProduct(int senderID, int bookID, int recieverID)
        {
            var msgs = (from m in db.Messages
                        where m.Book_Id == bookID && (m.Sender_Id == senderID || m.Sender_Id == recieverID) && (m.Receiver_Id == recieverID || m.Receiver_Id == senderID)
                        select m).ToList();
            List <MessageVM> msgsList = new List <MessageVM>();

            foreach (var item in msgs)
            {
                MessageVM msgVM = new MessageVM();
                if (item.Sender_Id == senderID)
                {
                    msgVM.Type = "Sent";
                }
                else
                {
                    msgVM.Type = "Received";
                }
                msgVM.Message1    = item.Message1;
                msgVM.Book_Id     = item.Book_Id;
                msgVM.Msg_Date    = item.Msg_Date;
                msgVM.Sender_Id   = item.Sender_Id;
                msgVM.Receiver_Id = item.Receiver_Id;
                msgsList.Add(msgVM);
            }
            return(Ok(msgsList));
        }
Ejemplo n.º 22
0
        public IEnumerable <MessageUC> GetMessages(ChatModel chatModel)
        {
            List <MessageUC>         messageUCs  = new List <MessageUC>();
            IService                 service     = new WCFService();
            IChatMap                 chatMap     = new Map();
            IEnumerable <MessageDTO> messageDTOs = service.GetMessages(chatMap.ChatModelToChatDTO(chatModel));

            if (messageDTOs != null)
            {
                foreach (MessageDTO mess in messageDTOs)
                {
                    MessageUC messageUC = new MessageUC();
                    MessageVM messageVM = new MessageVM();
                    messageVM.Message.Id     = mess.Id;
                    messageVM.Message.Text   = mess.Text;
                    messageVM.Message.Time   = mess.Time;
                    messageVM.Message.Author = mess.Author;
                    messageVM.Message.Img    = mess.Img;

                    messageUC.DataContext = messageVM;
                    messageUCs.Add(messageUC);
                }
            }

            return(messageUCs);
        }
Ejemplo n.º 23
0
        public IHttpActionResult Send(MessageVM mess)
        {
            GenericResult result;
            User          user      = this._repository.Entity <User>().Where(u => u.Username == mess.Sender).FirstOrDefault();
            Message       messToAdd = new Message()
            {
                Sender = user, Channel = mess.Channel, Text = mess.Text
            };

            this._repository.Insert(messToAdd);
            bool saveOk = this._repository.Save();

            if (saveOk)
            {
                result = new GenericResult()
                {
                    Succeeded = true,
                    Message   = "Message Send"
                };

                return(Json(result));
            }

            else
            {
                result = new GenericResult()
                {
                    Succeeded = false,
                    Message   = "Message Error"
                };
                return(Json(result));
            }
        }
Ejemplo n.º 24
0
 // POST: MessagesMVC/Send
 public IActionResult SaveMessage([FromBody] MessageVM vm)
 {
     if (ModelState.IsValid)
     {
         return(StatusCode(messaging.MVCSend(vm)));
     }
     return(View(vm));
 }
Ejemplo n.º 25
0
        public PartialViewResult MessagePartial(string DealerID)
        {
            MessageVM messageVM = new MessageVM {
                DealerId = DealerID
            };

            return(PartialView("_MessagePartial", messageVM));
        }
Ejemplo n.º 26
0
 public async Task <Result> Put([FromBody] MessageVM value)
 {
     if (HttpContext.User.Identity.IsAuthenticated)
     {
         return(await _genericService.Update(value));
     }
     return(null);
 }
        public async Task <ActionResult> AlterStudent(StudentViewModel oStudentVM)
        {
            TempData["UserMessage"] = new MessageVM()
            {
                IsSuccessful = false, Title = "Error!", Message = "Something went wrong."
            };

            if (Helpers.Helpers.IsStaff(User))
            {
                return(RedirectToAction("Index", "Staff"));
            }

            if (!ModelState.IsValid)
            {
                return(View(oStudentVM));
            }

            Student oStudent = db.Students.SingleOrDefault(s => s.StudentId == oStudentVM.StudentId);

            if (oStudent == null)//Error. Student DNE.
            {
                throw new ArgumentException("AlterStudent(StudentViewModel oStudentVM) - Student DNE.");
            }

            Parent oParent = db.Parents.Include(p => p.Children).SingleOrDefault(p => p.ParentId == SessionSingleton.Current.ParentId && p.Children.Any(s => s.StudentId == oStudent.StudentId));

            if (oParent == null) //Error. This Student/Child doesn't belong to this Parent.
            {
                throw new ArgumentException("AlterStudent(StudentViewModel oStudentVM) - Parent DNE.");
            }

            oStudent.StudentId  = oStudentVM.StudentId;
            oStudent.Username   = oStudentVM.Username;
            oStudent.Email      = oStudentVM.Email;
            oStudent.FirstName  = oStudentVM.FirstName;
            oStudent.LastName   = oStudentVM.LastName;
            oStudent.Gender     = oStudentVM.Gender;
            oStudent.Phone      = oStudentVM.Phone;
            oStudent.LastActive = DateTime.Now;

            try
            {
                //if (db.SaveChanges() <= 0)
                //    return View(oStudentVM);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(View(oStudentVM));
            }

            TempData["UserMessage"] = new MessageVM()
            {
                IsSuccessful = true, Title = "Success!", Message = "Your child has been successfully updated."
            };

            return(RedirectToAction("Index", new { StudentId = oStudent.StudentId, CourseId = 0 }));
        }
Ejemplo n.º 28
0
        public bool UpdateMessage(MessageVM messageViewModel)
        {
            var message = Mapper.Map <Message>(messageViewModel);

            TheUnitOfWork.Message.Update(message);
            TheUnitOfWork.Commit();

            return(true);
        }
Ejemplo n.º 29
0
        //[ValidateAntiForgeryToken]
        public IActionResult AddMessageToStore([FromBody] MessageVM model)
        {
            User user = new User {
                NickName = "Nick", Password = "******"
            };

            _messageService.SaveMessage(model);
            return(Json(true));
        }
Ejemplo n.º 30
0
        public Message MapModels(MessageVM message)
        {
            Message messageModel = new Message()
            {
                Text = message.Text
            };

            return(messageModel);
        }