コード例 #1
0
        public async Task AddMessageWithUnauthenticatedUser()
        {
            //Arrange

            var mapperConfig = new MapperConfiguration(x => x.AddProfile(new MappingProfile()));
            var mapper       = mapperConfig.CreateMapper();
            var store        = new Mock <IUserStore <User> >();
            var userManager  = new Mock <UserManager <User> >(store.Object, null, null, null, null, null, null, null, null);
            var userService  = new UserService(this.context, userManager.Object, mapper);
            var emailSender  = new Mock <IEmailSender>();

            var messageService = new MessageService(this.context, mapper, userService, emailSender.Object);

            //Act

            var messageDto = new MessageDto()
            {
                Content = "Message",
                Email   = "Email",
                Name    = "Chris",
                Subject = "Subject"
            };

            await messageService.Add(messageDto, "");

            var message = this.context.Messages.First();

            //Assert

            Assert.True(message.isActive);
            Assert.Equal("Message", message.Content);
            Assert.Equal("Subject", message.Subject);
            Assert.Equal("Email", message.Email);
            Assert.Null(message.User);
        }
        public ActionResult Create1(MessageModels msg)
        {
            Message message = new Message();

            message.Date     = msg.Date;
            message.Contenu  = msg.Contenu;
            message.Received = false;

            message.messageTypes = MessageType.Reponse;



            // user= US.Get(u=>u.Email.Equals(msg.userName));
            //user = US.Get(u => u.Email.Equals("*****@*****.**"));
            // user = US.GetById(1);
            message.UsersId = msg.UsersId;
            //  message.users = user;
            // Console.Out.WriteLine(message.users);
            //System.Diagnostics.Debug.WriteLine(message.users);

            MessageService ms = new MessageService();

            ms.Add(message);
            ms.Commit();


            return(RedirectToAction("IndexAdmin"));
        }
        public ActionResult Repondre(int id, FormCollection collection, MessageModels Msg)
        {
            try
            {
                Message msg      = new Message();
                Message msgModif = new Message();
                // msgModif = SM.GetById(idM);
                //  msgModif.Received = true;
                msg.Contenu      = Msg.Contenu;
                msg.Date         = Msg.Date;
                msg.UsersId      = id;
                msg.messageTypes = MessageType.Reponse;
                msg.Received     = true;

                //  SM.Add(msgModif);
                SM.Add(msg);
                SM.Commit();


                return(RedirectToAction("IndexAdmin"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #4
0
        public ActionResult CreateMessage(MessageModels msg)
        {
            MessageModelType messageS;

            Enum.TryParse("Satisfaction", out messageS);
            MessageModelType messageR;

            Enum.TryParse("Reclamation", out messageR);

            Domain.Entity.Message message = new Domain.Entity.Message();
            message.Date     = msg.Date;
            message.Contenu  = msg.Contenu;
            message.Received = false;
            message.UsersId  = msg.UsersId;


            if (msg.messagetype == messageS)
            {
                message.messageTypes = Domain.Entity.MessageType.Satisfaction;
            }
            else if (msg.messagetype == messageR)
            {
                message.messageTypes = Domain.Entity.MessageType.Reclamation;
            }
            else
            {
                message.messageTypes = Domain.Entity.MessageType.Probleme_Technique;
            }
            MessageService ms = new MessageService();

            ms.Add(message);
            ms.Commit();
            return(new HttpStatusCodeResult(System.Net.HttpStatusCode.OK));
        }
コード例 #5
0
        public ResultViewModel <MessageEditViewModel> Post(MessageEditViewModel Message)
        {
            ResultViewModel <MessageEditViewModel> result
                = new ResultViewModel <MessageEditViewModel>();

            try
            {
                if (!ModelState.IsValid)
                {
                    result.Message = "In Valid Model State";
                }
                else
                {
                    MessageEditViewModel selectedMessage
                        = messageService.Add(Message);

                    Hub.Clients.All.MessageRecived(new {
                        UserName    = Message.FullName,
                        PrefMessage = Message.Text.Substring(0, 20),
                    });

                    result.Successed = true;
                    result.Data      = selectedMessage;
                    result.Message   = "Message Sent...";
                }
            }
            catch (Exception ex)
            {
                result.Successed = false;
                result.Message   = "Semething Went Wrong";
            }
            return(result);
        }
コード例 #6
0
        public ActionResult CreateMessageAdmin(MessageModels msg)
        {
            Domain.Entity.Message message = new Domain.Entity.Message();
            message.Date     = msg.Date;
            message.Contenu  = msg.Contenu;
            message.Received = false;

            message.messageTypes = Domain.Entity.MessageType.Reponse;



            // user= US.Get(u=>u.Email.Equals(msg.userName));
            //user = US.Get(u => u.Email.Equals("*****@*****.**"));
            // user = US.GetById(1);
            message.UsersId = msg.UsersId;
            //  message.users = user;
            // Console.Out.WriteLine(message.users);
            //System.Diagnostics.Debug.WriteLine(message.users);

            MessageService ms = new MessageService();

            ms.Add(message);
            ms.Commit();
            return(new HttpStatusCodeResult(System.Net.HttpStatusCode.OK));
        }
コード例 #7
0
        public ResultViewModel <MessageEditViewModel> Post(MessageEditViewModel message)
        {
            ResultViewModel <MessageEditViewModel> result = new ResultViewModel <MessageEditViewModel>();

            try
            {
                if (!ModelState.IsValid)
                {
                    result.Successed = false;
                    result.Message   = "Invaild Model State";
                }
                else
                {
                    MessageEditViewModel m = messageService.Add(message);
                    result.Data      = m;
                    result.Successed = true;
                    result.Message   = "Message Add Successfully";
                    Hub.Clients.All.MessageRecived(new
                    {
                        UserName    = message.FullName,
                        PrefMessage = string.Join(" ", message.Text.Split(' ').Take(3)),
                    });
                }
            }
            catch (Exception e)
            {
                result.Successed = false;
                result.Message   = "Somting Wrong !";
            }
            return(result);
        }
コード例 #8
0
        public ActionResult Create(Message q)
        {
            bool   Status  = false;
            string message = "";

            //Model
            if (ModelState.IsValid)
            {
                Message p = q;

                Cs.Add(p);
                Cs.Commit();
                //   message = " Request";
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;

            //  return View(q);
            return(RedirectToAction("Create"));
        }
        public async Task <ActionResult> Create(Messages message)
        {
            var messages = _messageService.FindAllAsync();

            if (!ModelState.IsValid)
            {
                var resultMessage = new Messages {
                    MessageId = message.MessageId, MessageText = message.MessageText, MessageDate = message.MessageDate
                };

                return(View(resultMessage));
            }
            await _messageService.Add(message);

            return(RedirectToAction("Index"));
        }
コード例 #10
0
        public async Task InvalidMessageReturnsValidationError()
        {
            // Arrange
            var messageRepository = Mock.Of <IMessageRepository>();
            var messageService    = new MessageService(messageRepository, NullLogger <MessageService> .Instance);

            // Act
            var result = await messageService.Add(new MessageRequest
            {
                AddedBy  = "TestUser",
                Contents = null,
            });

            // Assert
            Assert.Equal(AddMessageResult.MissingProperties, result);
        }
コード例 #11
0
 public ActionResult SendMessage(Message data)
 {
     if (data.Text != null && data.ReceivedBy.Nick != string.Empty)
     {
         data.SenderId     = userDb.GetByName(HttpContext.User.Identity.Name).ID;
         data.ReceivederId = userDb.GetByName(data.ReceivedBy.Nick).ID;
         data.ReceivedBy   = null;
         msgDb.Add(data);
         ViewBag.Message = "Gönderim Başarılı!";
     }
     else
     {
         ViewBag.Message = "Lütfen Alanları Doldurunuz";
     }
     return(View());
 }
コード例 #12
0
        public async Task CanAddValidMessage()
        {
            // Arrange
            var messageRepository = Mock.Of <IMessageRepository>();
            var messageService    = new MessageService(messageRepository, NullLogger <MessageService> .Instance);

            // Act
            var result = await messageService.Add(new MessageRequest
            {
                AddedBy  = "TestUser",
                Contents = "Hello"
            });

            // Assert
            Assert.Equal(AddMessageResult.Ok, result);
        }
        public ActionResult Create(MessageModels msg)
        {
            MessageModelType messageS;

            Enum.TryParse("Satisfaction", out messageS);

            MessageModelType messageR;

            Enum.TryParse("Reclamation", out messageR);



            Message message = new Message();

            message.Date     = msg.Date;
            message.Contenu  = msg.Contenu;
            message.Received = false;
            if (msg.messagetype == messageS)
            {
                message.messageTypes = MessageType.Satisfaction;
            }
            else if (msg.messagetype == messageR)
            {
                message.messageTypes = MessageType.Reclamation;
            }
            else
            {
                message.messageTypes = MessageType.Probleme_Technique;
            }

            // user= US.Get(u=>u.Email.Equals(msg.userName));
            //user = US.Get(u => u.Email.Equals("*****@*****.**"));
            // user = US.GetById(1);
            message.UsersId = Convert.ToInt32(User.Identity.GetUserId());
            //  message.users = user;
            // Console.Out.WriteLine(message.users);
            //System.Diagnostics.Debug.WriteLine(message.users);

            MessageService ms = new MessageService();

            ms.Add(message);
            ms.Commit();


            return(RedirectToAction("Index"));
        }
コード例 #14
0
        public void ReturnProper_DeleteMessage_ResultFromCommitMethod()
        {
            // Arrange
            var messagesRepoMock = new Mock <IEfRepository <Message> >();
            var uowMock          = new Mock <ISaveContext>();

            messagesRepoMock.Setup(c => c.Delete(It.IsAny <Message>())).Verifiable();
            uowMock.Setup(u => u.Commit()).Returns(1);

            var messageService = new MessageService(messagesRepoMock.Object, uowMock.Object);

            // Act
            var result = messageService.Add(It.IsAny <Message>());

            // Assert
            Assert.That(result.Equals(1));
        }
コード例 #15
0
 public ActionResult SendToMail(Message item)
 {
     if (Session["oturum"] != null)
     {
         gelen             = (AppUser)Session["oturum"];
         ViewBag.AppUserID = gelen.ID;
     }
     else if (Session["admin"] != null)
     {
         gelen             = (AppUser)Session["admin"];
         ViewBag.AppUserID = gelen.ID;
     }
     if (gelen != null)
     {
         item.AppUserID = gelen.ID;
     }
     ms.Add(item);
     return(View());
 }
コード例 #16
0
        public ActionResult Create(MessageView message)
        {
            if (accountService.Get(a => a.Login == message.LoginDestinataire) != null)
            {
                Message msg = new Message();
                msg.AccountFromID = 1;
                msg.AccountToID   = accountService.Get(a => a.Login == message.LoginDestinataire).AccountID;
                msg.Text          = message.Text;
                //msg.From = accountService.GetById(1);
                //msg.To = accountService.GetById(message.AccountToID);

                messageService.Add(msg);
                messageService.Commit();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(Content("<script language='javascript' type='text/javascript'>alert('User " + message.LoginDestinataire + " not found');window.location.href='http://localhost:2014/message/Create';</script>"));
            }
        }
コード例 #17
0
        /// <summary>
        /// 添加投诉或建议
        /// </summary>
        /// <param name="input"></param>
        public GeneralResult Add(AddMessageInput input)
        {
            var result = new GeneralResult();

            try
            {
                bll.Add(input);
                result.State = 0;
                result.Msg   = "操作成功";
            }
            catch (RTException e)
            {
                result = RTExceptionHandle(e);
            }
            catch (Exception e1)
            {
                result = ExceptionHandle(e1);
            }
            return(result);
        }
コード例 #18
0
    public void SendAnswerToQuestion()
    {
        Message message = new Message();

        message.message     = AnswerTextBox.text;
        message.question_id = CurrentQuestion;

        StartCoroutine(MyMessageService.Add(
                           message,
                           delegate(Message m)
        {
            AnswerTextBox.text = "";

            if (AnswersCount < MAX_ANSWERS_COUNT - 1)
            {
                UpdateMessages();

                UIAnimator.SetBool("IsQuestionSlide", false);
                AskToQuestionButton.SetActive(false);
                GetQuestionButton.SetActive(true);

                AnswersCount++;
            }
            else
            {
                UIAnimator.SetBool("IsQuestionSlide", false);

                RemoveMessagesFromPanel();

                MyQuestionTextBox.gameObject.SetActive(true);
                SendMyQuestionButton.SetActive(true);
                OtherQuestionsButton.SetActive(false);
                AskToQuestionButton.SetActive(false);
                GetQuestionButton.SetActive(true);
                OtherUsersAnswersScrollView.SetActive(false);
            }
        }
                           )
                       );
    }
コード例 #19
0
        public void SendChatMessage(string sender, string email, string message, string clientName)
        {
            foreach (var connectionId in _connections.GetConnections(email))
            {
                Clients.Client(connectionId).addChatMessage(sender, email, message, clientName);
            }
            ClientService                   CS  = new ClientService();
            client                          cls = CS.Get(x => x.email.Equals(sender));
            client                          clr = CS.Get(x => x.email.Equals(email));
            ConversationUsersService        CUS = new ConversationUsersService();
            IEnumerable <conversation_user> conversationsuserslist = CUS.GetMany();
            ConversationService             COS = new ConversationService();
            IEnumerable <conversation>      conversationslist = COS.GetMany();
            conversation                    c0 = null;
            int s = 0;

            foreach (conversation c in conversationslist)
            {
                s = 0;
                foreach (conversation_user cu in conversationsuserslist)
                {
                    if (cu.Conversation_idConversation == c.idConversation && (cu.participants_idUser == cls.idUser || cu.participants_idUser == clr.idUser))
                    {
                        s++;
                    }
                }
                if (s > 1)
                {
                    c0 = c;
                    break;
                }
            }
            if (c0 == null)
            {
                c0 = new conversation
                {
                    startDate = DateTime.Now
                };
                conversation_user cu1 = new conversation_user
                {
                    conversation = c0,
                    Conversation_idConversation = c0.idConversation,
                    participants_idUser         = cls.idUser
                };
                conversation_user cu2 = new conversation_user
                {
                    conversation = c0,
                    Conversation_idConversation = c0.idConversation,
                    participants_idUser         = clr.idUser
                };
                c0.conversation_user.Add(cu1);
                c0.conversation_user.Add(cu2);
                COS.Add(c0);
                COS.Commit();
            }
            MessageService MS = new MessageService();
            message        m  = new message
            {
                content = message,
                conversation_idConversation = c0.idConversation,
                sendingDate   = DateTime.Now,
                sender_idUser = cls.idUser
            };
            message_user mu = new message_user
            {
                Message_idMessage = m.idMessage,
                receivers_idUser  = clr.idUser
            };

            m.message_user.Add(mu);
            MS.Add(m);
            MS.Commit();
        }
コード例 #20
0
 public ActionResult <int> Post([FromBody] MessageDto model)
 {
     return(_messageService.Add(model));
 }