Example #1
0
        public void ShouldGetReferenceData()
        {
            const int contactId             = 123456;
            const int refContactId          = 987654;
            var       contact               = ContactMock(contactId);
            var       participant           = ParticipantMock();
            var       studentLeaderInterest = "true";

            _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderFormId")).Returns(29);
            _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderFormReferenceContact")).Returns(1519);
            _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderStudentFieldId")).Returns(123);
            _participantRepository.Setup(m => m.GetParticipant(contactId)).Returns(participant);
            _contactMock.Setup(m => m.GetContactById(contactId)).Returns(contact);
            _formService.Setup(m => m.GetFormResponseAnswer(29, contactId, 123, null)).Returns(studentLeaderInterest);
            _formService.Setup(m => m.GetFormResponseAnswer(29, contactId, 1519, null)).Returns(refContactId.ToString());

            var res = _fixture.GetApplicationData(contactId);

            res.Subscribe((result) =>
            {
                Assert.AreEqual(participant, result["participant"]);
                Assert.AreEqual(contact, result["contact"]);
                Assert.AreEqual("987654", result["referenceContactId"]);
                Assert.AreEqual(studentLeaderInterest, result["studentLeaderRequest"]);
            },
                          (err) =>
            {
                Assert.Fail(err.ToString());
            });
        }
Example #2
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);
        }