예제 #1
0
        public async Task SendMessageTest()
        {
            DatabaseSystem databaseSystem = new DatabaseSystem();
            Message        message        = new Message("unitTest1", "unitTest1", "unitTestMessage");
            Activity       activity       = new Activity();

            activity.ActivityId     = "99";
            activity.ActivityName   = "unitTest2";
            activity.HomeOwnerId    = "unitTest1";
            activity.ActivityDate   = "2020/02/02";
            activity.ActivityNote   = "unitTest";
            activity.NumberOfPeople = "3";

            await databaseSystem.InsertActivity(activity);

            Assert.IsTrue(await databaseSystem.SendMessage("99", message));
            await databaseSystem.Delete("99", "Activity");
        }
예제 #2
0
        public async Task GetChatDataTest()
        {
            DatabaseSystem databaseSystem = new DatabaseSystem();
            List <Message> messages       = new List <Message>();

            Message  message  = new Message("unitTest1", "unitTest1", "unitTestMessage");
            Activity activity = new Activity();

            activity.ActivityId     = "99";
            activity.ActivityName   = "unitTest2";
            activity.HomeOwnerId    = "unitTest1";
            activity.ActivityDate   = "2020/02/02";
            activity.ActivityNote   = "unitTest";
            activity.NumberOfPeople = "3";
            await databaseSystem.InsertActivity(activity);

            await databaseSystem.SendMessage("99", message);

            messages = await databaseSystem.GetChatData("99");

            await databaseSystem.Delete("99", "Activity");

            Assert.AreEqual("unitTest1", messages[0].MemberId);
        }
예제 #3
0
        public async Task <ActionResult> SendMessage(string memberId, string memberName, string activityId, string messageContent)
        {
            await InitializationModel();

            try
            {
                if (_activityHandler.IsParticipant(activityId, memberId))
                {
                    Message message = new Message(memberId, memberName, messageContent);
                    _activityHandler.SendMessage(activityId, memberId, memberName, messageContent);
                    await _databaseSystem.SendMessage(activityId, message);

                    return(Json(new { success = true, responseText = "發送成功", type = 0 }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = true, responseText = "很抱歉您非本活動的參加者故無法發言", type = 1 }, JsonRequestBehavior.AllowGet));
                }
            }
            catch
            {
                return(Json(new { success = false, responseText = "發送失敗", type = 1 }, JsonRequestBehavior.AllowGet));
            }
        }