Example #1
0
        public bool AddMessageAdmin(MessageDto messageDto)
        {
            if (_user.GetAll().Any(i => i.Login == messageDto.Customer_Login)
                && (_user.GetAll().Any(i => i.Login == messageDto.Sender_Login))
                && messageDto.Theme.Length <= 150)
            {
                _message.Add(new Messages
                {
                    Theme = messageDto.Theme,
                    Content = messageDto.Content,
                    Customer_ID = _user.GetAll().First(i => i.Login == messageDto.Customer_Login).ID,
                    IfRead = messageDto.IfRead,
                    PostDate = DateTime.Now,
                    Sender_ID = _user.GetAll().First(i => i.Login == messageDto.Sender_Login).ID
                });

                _unitOfWork.Commit();
                return true;
            }
            return false;
        }
Example #2
0
        public MessageDto ConentMessage(int ID, string User)
        {
            MessageDto message = new MessageDto();

            foreach (var item in _message.GetAll().Where(i => i.ID == ID))
            {
                message.ID = item.ID;
                message.Customer_Login = _user.Get(item.Customer_ID).Login;
                message.Sender_Login = _user.Get(item.Sender_ID).Login;
                message.Theme = item.Theme;
                message.Content = item.Content;
                message.PostDate = (DateTime)item.PostDate;

                if (item.Customer_ID == _user.GetAll().First(i => i.Login == User).ID)
                {
                    item.IfRead = true;
                    _unitOfWork.Commit();
                }
            }

            return message;
        }
Example #3
0
        public bool UpdateMessageAdmin(MessageDto messageDto)
        {
            if (_user.GetAll().Any(i => i.Login == messageDto.Customer_Login)
                && (_user.GetAll().Any(i => i.Login == messageDto.Sender_Login))
               && messageDto.Theme.Length <= 150)
            {
                foreach (var item in _message.GetAll().Where(i => i.ID == messageDto.ID))
                {
                    item.IfRead = messageDto.IfRead;
                    item.Sender_ID = _user.GetAll().First(i => i.Login == messageDto.Sender_Login).ID;
                    item.Content = messageDto.Content;
                    item.Customer_ID = _user.GetAll().First(i => i.Login == messageDto.Customer_Login).ID;
                    item.Theme = messageDto.Theme;
                    item.PostDate = messageDto.PostDate;
                }

                _unitOfWork.Commit();
                return true;
            }
            return false;
        }
Example #4
0
        public bool SendMessage(MessageDto message)
        {
            try
            {
                _message.Add(new Messages
                {
                    Customer_ID = _user.GetAll().First(i => i.Login == message.Customer_Login).ID,
                    Sender_ID = _user.GetAll().First(i => i.Login == message.Sender_Login).ID,
                    Theme = message.Theme,
                    Content = message.Content,
                    PostDate = DateTime.Now,
                    IfRead = false
                });
                _unitOfWork.Commit();

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Example #5
0
 public void ReadMessage(MessageDto message)
 {
     throw new NotImplementedException();
 }
Example #6
0
        public ActionResult AddMessageAdmin(MessageViewModel messageModel)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            MessageDto messageDto = new MessageDto();

            messageDto.Content = messageModel.viewModel.Content;
            messageDto.Customer_Login = messageModel.viewModel.Customer_Login;
            messageDto.Sender_Login = messageModel.viewModel.Sender_Login;
            messageDto.Theme = messageModel.viewModel.Theme;
            messageDto.IfRead = messageModel.viewModel.Read.ToLower().Contains("tak") ? true : false;

            if(_messageService.AddMessageAdmin(messageDto))
            {
                errors.Add("Dodano wiadomość.");
            }
            else
            {
                errors.Add("Błąd. Spróbuj ponownie.");
            }
            Session["val"] = errors.ToArray<string>();

            return RedirectToAction("Admin");
        }