Ejemplo n.º 1
0
        public async Task <ACMGenericResult <DispatchChannel> > GetDispatchChannel(string dispatchId)
        {
            var result = new ACMGenericResult <DispatchChannel>();

            try
            {
                AccountConfiguration accountConfiguration = await ViaMongoDB.GetAccountConfiguration();

                if (accountConfiguration.DispatchChannels == null)
                {
                    result.StatusCode = 204;
                    result.Value      = null;
                }
                else
                {
                    DispatchChannel dispatchChannel = accountConfiguration.DispatchChannels.Find(x => x.DispatchId == dispatchId);
                    if (dispatchChannel == default)
                    {
                        result.StatusCode = 204;
                        result.Value      = null;
                    }
                    else
                    {
                        result.StatusCode = 200;
                        result.Value      = dispatchChannel;
                    }
                }
            }
            catch (Exception)
            {
                result.StatusCode = 500;
                result.Value      = null;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <ACMGenericResult <DispatchChannel> > AddOrUpdateDispatchChannel(DispatchChannel dispatchChannel)
        {
            var result = new ACMGenericResult <DispatchChannel>();

            try
            {
                AccountConfiguration accountConfiguration = await ViaMongoDB.GetAccountConfiguration();

                if (accountConfiguration.DispatchChannels == null)
                {
                    accountConfiguration.DispatchChannels = new List <DispatchChannel> {
                        dispatchChannel
                    }
                }
                ;
                else
                {
                    int index = accountConfiguration.DispatchChannels.FindIndex(x => x.DispatchId == dispatchChannel.DispatchId);
                    if (index == -1)
                    {
                        accountConfiguration.DispatchChannels.Add(dispatchChannel);
                    }
                    else
                    {
                        accountConfiguration.DispatchChannels[index] = ToClone(dispatchChannel);
                    }
                }
                result.StatusCode = 200;
                result.Value      = (await ViaMongoDB.UpdateAccountConfiguration_DispatchChannels(accountConfiguration.DispatchChannels))
                                    .DispatchChannels?.Find(x => x.DispatchId == dispatchChannel.DispatchId);
            }
            catch (Exception)
            {
                result.StatusCode = 500;
                result.Value      = null;
            }
            return(result);
        }
Ejemplo n.º 3
0
        public async Task <List <DispatchChannel> > ConfigureDispatchChannels(List <Dispatch> dispatches, List <DeliveryPlan> deliveryPlans, List <Question> preFillQuestions)
        {
            List <DispatchChannel> dispatchChannels = new List <DispatchChannel>();

            foreach (Dispatch dispatch in dispatches)
            {
                DeliveryPlan         deliveryPlan   = deliveryPlans.Find(x => x.id == dispatch.DeliveryPlanId);
                List <StaticPrefill> staticPrefills = preFillQuestions
                                                      .Where(x => x.DisplayLocation?.Contains(dispatch.QuestionnaireName, StringComparer.InvariantCultureIgnoreCase) ?? false)?
                                                      .Select(x => new StaticPrefill {
                    Note = x.Note, PrefillValue = null, QuestionId = x.Id
                })?
                                                      .ToList() ?? new List <StaticPrefill>();
                DispatchChannel dispatchChannel = new DispatchChannel
                {
                    ChannelDetails = new ChannelDetails
                    {
                        Email = new Channel
                        {
                            IsValid    = deliveryPlan?.schedule?.Any(x => x.onChannel?.StartsWith("email") ?? false) ?? false ? true : false,
                            Vendorname = null
                        },
                        Sms = new Channel
                        {
                            IsValid    = deliveryPlan?.schedule?.Any(x => x.onChannel?.StartsWith("sms") ?? false) ?? false ? true : false,
                            Vendorname = null
                        }
                    },
                    DispatchId     = dispatch.Id,
                    DispatchName   = dispatch.Name + (dispatch.IsLive == true ? string.Empty : " [PAUSED]"),
                    StaticPrefills = staticPrefills,
                    Notify         = new Notify
                    {
                        D = null,
                        E = null,
                        F = null,
                        I = null,
                        W = null
                    }
                };
                dispatchChannels.Add(dispatchChannel);
            }

            AccountConfiguration accountConfiguration = await ViaMongoDB.GetAccountConfiguration();

            if (accountConfiguration.DispatchChannels == null)
            {
                accountConfiguration.DispatchChannels = dispatchChannels;
            }
            else
            {
                foreach (DispatchChannel dc in dispatchChannels)
                {
                    int index1 = accountConfiguration.DispatchChannels.FindIndex(x => x.DispatchId == dc.DispatchId);
                    if (index1 == -1)                                                                                   //Add new dispatch channel
                    {
                        accountConfiguration.DispatchChannels.Add(dc);
                    }
                    else                                                                                                //Update existing dispatch channel
                    {
                        accountConfiguration.DispatchChannels[index1].ChannelDetails.Email.IsValid = dc.ChannelDetails.Email.IsValid;
                        accountConfiguration.DispatchChannels[index1].ChannelDetails.Sms.IsValid   = dc.ChannelDetails.Sms.IsValid;

                        accountConfiguration.DispatchChannels[index1].DispatchName = dc.DispatchName;

                        foreach (StaticPrefill sp in dc.StaticPrefills)
                        {
                            int index2 = accountConfiguration.DispatchChannels[index1].StaticPrefills.FindIndex(x => x.QuestionId == sp.QuestionId);
                            if (index2 == -1)
                            {
                                accountConfiguration.DispatchChannels[index1].StaticPrefills.Add(sp);                   //Add new static prefill
                            }
                            else
                            {
                                accountConfiguration.DispatchChannels[index1].StaticPrefills[index2].Note = sp.Note;    //Update existing static prefill
                            }
                        }
                        accountConfiguration.DispatchChannels[index1].
                        StaticPrefills.RemoveAll(x => dc.StaticPrefills.All(y => y.QuestionId != x.QuestionId));        //Remove old static prefills

                        if (accountConfiguration.DispatchChannels[index1].Notify == default)
                        {
                            accountConfiguration.DispatchChannels[index1].Notify = dc.Notify;
                        }
                    }
                }
                accountConfiguration.DispatchChannels                                                                   //Remove old dispatch channels
                .RemoveAll(x => dispatchChannels.All(y => y.DispatchId != x.DispatchId));
            }
            return((await ViaMongoDB.UpdateAccountConfiguration_DispatchChannels(accountConfiguration.DispatchChannels)).DispatchChannels);
        }