Example #1
0
        public async Task <IHttpActionResult> SaveSpiritualGrowth([FromBody] SpiritualGrowthDTO spiritualGrowth)
        {
            if (ModelState.IsValid)
            {
                return(await Authorized(token =>
                {
                    try
                    {
                        _groupLeaderService.SaveSpiritualGrowth(spiritualGrowth)
                        .Concat(_groupLeaderService.SetApplied(token)).Wait();

                        _groupLeaderService.GetApplicationData(spiritualGrowth.ContactId).Subscribe((res) =>
                        {
                            if ((string)res["referenceContactId"] != "0")
                            {
                                _groupLeaderService.SendReferenceEmail(res).Subscribe(CancellationToken.None);
                            }
                            else
                            {
                                _groupLeaderService.SendNoReferenceEmail(res).Subscribe(CancellationToken.None);
                            }

                            if (((string)res["studentLeaderRequest"]).ToUpper() == "TRUE")
                            {
                                _groupLeaderService.SendStudentMinistryRequestEmail(res).Subscribe(CancellationToken.None);
                            }
                        });
                        return Ok();
                    }
                    catch (Exception e)
                    {
                        var apiError = new ApiErrorDto("Saving SpiritualGrowth failed:", e);
                        throw new HttpResponseException(apiError.HttpResponseMessage);
                    }
                }));
            }
            var errors    = ModelState.Values.SelectMany(val => val.Errors).Aggregate("", (current, err) => current + err.ErrorMessage);
            var dataError = new ApiErrorDto("Spiritual Growth Data Invalid", new InvalidOperationException("Invalid Spiritual Growth Data" + errors));

            throw new HttpResponseException(dataError.HttpResponseMessage);
        }
Example #2
0
        public void ShouldSendAnEmailToStudentMinistry()
        {
            const int    messageId     = 456;
            const int    templateId    = 2021;
            const int    hsmsContactId = 987;
            const int    contactId     = 13524;
            const string emailAddr     = "*****@*****.**";
            var          participant   = ParticipantMock();
            var          contact       = ContactMock(contactId);

            var referenceData = new Dictionary <string, object>
            {
                { "participant", participant },
                { "contact", contact }
            };

            _contactMock.Setup(m => m.GetContactEmail(hsmsContactId)).Returns(emailAddr);
            _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderForStudentsEmailTemplate")).Returns(templateId);
            _configWrapper.Setup(m => m.GetConfigIntValue("StudentMinistryContactId")).Returns(hsmsContactId);

            var mergeData     = new Dictionary <string, object>();
            var communication = SMCommunication(templateId, mergeData, emailAddr, hsmsContactId);

            _communicationRepository.Setup(m => m.GetTemplateAsCommunication(templateId, hsmsContactId, It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(communication);
            _communicationRepository.Setup(m => m.SendMessage(communication, false)).Returns(messageId);

            var result = _fixture.SendStudentMinistryRequestEmail(referenceData);

            result.Subscribe((n) =>
            {
                Assert.AreEqual(messageId, result);
            },
                             (err) =>
            {
                Assert.Fail(err.ToString());
            });
        }