示例#1
0
        public async Task MakeLive()
        {
            var cmd    = new SurveyDefinitionMakeLiveCmd(survey.SurveyId);
            var result = await SurveyClient.MakeLive(cmd);

            if (result.Result == CommandSubmitExecutionResult.OK)
            {
                survey  = result.EntityQry;
                CanEdit = false;
                StateHasChanged();
            }
        }
        public async Task OnDeleteClick()
        {
            var cmd    = new SurveyDefinitionRemoveSurveyItemCmd(survey.SurveyId, section.SectionId);
            var result = await SurveyClient.DeleteSurveyItem(cmd);

            if (result.Result == CommandSubmitExecutionResult.OK)
            {
                UriHelper.NavigateTo($"editsurvey/");
            }
            else
            {
                ValidationMessage = result.Messages.FirstOrDefault();
            }
        }
示例#3
0
        protected override async Task OnParametersSetAsync()
        {
            if (Id != null)
            {
                _surveyId = Guid.Parse(Id);
                var survey = await SurveyClient.GetSurvey(_surveyId);

                SurveyName  = survey.Name;
                SurveyIntro = survey.Intro;
                var responses = await SurveyResponseClient.GetSurveyResponses(_surveyId);

                Responses = responses.ToList();
            }
        }
示例#4
0
        public async Task MoveItemDown(Guid surveyItemId)
        {
            var cmd    = new SurveyDefinitionMoveSurveyItemDownCmd(survey.SurveyId, surveyItemId);
            var result = await SurveyClient.MoveItemDown(cmd);

            string m = result.Messages.FirstOrDefault();

            Console.WriteLine($"Move down.... : {result.Result} - {m} ");
            if (result.Result == CommandSubmitExecutionResult.OK)
            {
                survey = result.EntityQry;
                StateHasChanged();
            }
        }
示例#5
0
        public async Task DeleteQuestion(SurveyQuestionEditDTO question)
        {
            var cmd    = new SurveyDefinitionRemoveSurveyItemCmd(survey.SurveyId, question.QuestionId);
            var result = await SurveyClient.DeleteSurveyItem(cmd);

            string m = result.Messages.FirstOrDefault();

            Console.WriteLine($"Delete Question : {result.Result} - {m} ");
            if (result.Result == CommandSubmitExecutionResult.OK)
            {
                survey = result.EntityQry;
                StateHasChanged();
            }
        }
示例#6
0
        public async Task OnSaveClick()
        {
            var cmd    = new SurveyDefinitionAddSectionCmd(_surveyId, SectionName, SectionIntro);
            var result = await SurveyClient.AddSection(cmd);

            if (result.Result == CommandSubmitExecutionResult.OK)
            {
                UriHelper.NavigateTo($"editsurvey/");
            }
            else
            {
                ValidationMessage = result.Messages.FirstOrDefault();
                Console.WriteLine(ValidationMessage);
            }
        }
示例#7
0
        public async Task OnSaveClick()
        {
            if (String.IsNullOrWhiteSpace(SurveyName))
            {
                ValidationMessage = "Survey Name is a required field";
                return;
            }

            var cmd    = new SurveyDefinitionCreateCmd(SurveyName, SurveyIntro);
            var result = await SurveyClient.AddSurvey(cmd);

            if (result.Result == CommandSubmitExecutionResult.OK)
            {
                UriHelper.NavigateTo("adminsurveydefinitions");
            }
        }
示例#8
0
 protected override async Task OnParametersSetAsync()
 {
     Console.WriteLine("Edit Survey Page : OnParametersSetAsync #1 ");
     if (Id != "")
     {
         Console.WriteLine("Get from server, no cache");
         _id    = Guid.Parse(Id);
         survey = await SurveyClient.GetSurvey(_id);
     }
     else
     {
         Console.WriteLine("Use cache");
         survey = SurveyClient.CachedSurvey;
     }
     CanEdit = (survey.Status == SurveyDefinitionStatusEnum.Edit);
 }
示例#9
0
        public ActionResult TakeSecondarySurvey(SecondSurvey model)
        {
            if (ModelState.IsValid)
            {
                List <string> analysts = new List <string>();
                foreach (var item in db.Users.Select(s => new { s.Email, s.Id }).ToList())
                {
                    var roles = UserManager.GetRoles(item.Id);
                    if (roles.Contains("Analyst"))
                    {
                        analysts.Add(item.Email);
                    }
                }

                var selectedAnalyst = analysts[new Random().Next(analysts.Count)];

                MailHelper.SendMail(User.Identity.Name, "Welcome from Survey App", string.Format(@"Welcome to survey application...

Please start interacting with the Analyst, follow the link to start, http://primum.mobi/surveyapp/Analyst/AnalysisSurvey"));



                SurveyClient sc = db.TSurveyClient.Where(d => d.UserId == db.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Id).FirstOrDefault();
                if (sc != null)
                {
                    sc.Address   = model.Address;
                    sc.FirstName = model.FirstName;
                    sc.LastName  = model.LastName;
                    sc.Pincode   = model.Pincode;
                    sc.AnalystId = selectedAnalyst;
                }
                db.Entry(sc).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("AnalysisSurvey", "Analyst"));
            }
            return(View(model));
        }
示例#10
0
        protected void bSubmit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                XmlDocument xml = new XmlDocument();
                XmlNode     rootNode;
                XmlNode     node;
                string      surveyName = "";
                ContactForm contact    = new ContactForm();

                rootNode = xml.CreateElement("root");
                xml.AppendChild(rootNode);

                foreach (string key in Request.Form)
                {
                    string value = Request[key];

                    if (key.StartsWith(ControlClientID) && key != ControlClientID + "$" + bSubmit.ID)
                    {
                        if (key == ControlClientID + "$" + _surveyNameFieldName)
                        {
                            surveyName = value;
                        }
                        else
                        {
                            node           = xml.CreateElement(key.Replace(ControlClientID + "$", ""));
                            node.InnerText = value;

                            if (FieldMappings != null && FieldMappings.ContainsKey(key))
                            {
                                switch (FieldMappings[key])
                                {
                                case ContactFields.Name:
                                    contact.Name = (contact.Name + NAME_DELIMITER + value).TrimStart(' ');
                                    break;

                                case ContactFields.Company:
                                    contact.Company = value;
                                    break;

                                case ContactFields.Zip:
                                    contact.Zip = value;
                                    break;

                                case ContactFields.Phone:
                                    contact.Phone = value;
                                    break;

                                case ContactFields.Email:
                                    contact.Email = value;
                                    break;
                                }
                            }

                            rootNode.AppendChild(node);
                        }
                    }
                }

                OwensCorning.SurveyService.Data.SurveyForm form =
                    new OwensCorning.SurveyService.Data.SurveyForm()
                {
                    FormName = surveyName,
                    FormData = XElement.Load(xml.CreateNavigator().ReadSubtree())
                };

                using (SurveyClient client = new SurveyClient())
                {
                    client.SaveSurvey(form);
                }

                try
                {
                    //Horrible, needs to be fixed ASAP
                    string[] names = contact.Name.Split(NAME_DELIMITER);
                    ExactTargetService.Instance.Register(
                        new ExactTargetUser()
                    {
                        FirstName = names[0],
                        LastName  = names[1],
                        Company   = contact.Company,
                        Business  = string.Empty,    //EMBED THIS IN XML
                        Email     = contact.Email,
                        Phone     = contact.Phone
                                    //INTERESTS?
                    }
                        );
                }
                catch (Exception ex)
                {
                    log.Error("Failed saving survey to ExactTarget: " + ex.Message, ex);
                }

                try
                {
                    contact.FormData = form.FormData.ToString();
                    ContactFormService.PublishContactForm(contact);
                }
                catch (Exception ex)
                {
                    log.Error("Failed publishing survey to contact form web service: " + ex.Message, ex);
                }

                pForm.Visible     = false;
                pThankYou.Visible = true;
            }
        }
示例#11
0
        async Task AddQuestion()
        {
            CommandSubmitResult <SurveyEditDTO> result = null;

            switch ((QuestionTypeEnum)QuestionTypeId)
            {
            case QuestionTypeEnum.Text:
                var cmd = new SurveyDefinitionTextQuestionAddToSectionCmd(survey.SurveyId, section.SectionId, QuestionText, QuestionHelp);
                result = await SurveyClient.AddTextQuestion(cmd);

                break;

            case QuestionTypeEnum.Rating:
                //int min = int.Parse(RatingMin);
                var cmd1 = new SurveyDefinitionAddRatingQuestionToSectionCmd(
                    survey.SurveyId,
                    section.SectionId,
                    RatingMin,
                    RatingMax,
                    QuestionText,
                    QuestionHelp);
                result = await SurveyClient.AddRatingQuestion(cmd1);

                break;

            case QuestionTypeEnum.MultiChoice:
                var cmd2 = new SurveyDefinitionMultiOptionQuestionAddToSectionCmd(survey.SurveyId, section.SectionId, QuestionText, QuestionHelp);
                result = await SurveyClient.AddMultiOptionQuestion(cmd2);

                if (result.Result == CommandSubmitExecutionResult.OK)
                {
                    Guid addedQId = result.UpdatedId;
                    foreach (var item in Options)
                    {
                        var cmd3 = new AddOptionToMultiOptionQuestionCmd(survey.SurveyId, addedQId, item.Text, item.Value);
                        result = await SurveyClient.AddOptionToMultiOptionQuestion(cmd3);
                    }
                }
                break;

            case QuestionTypeEnum.SingleChoice:
                var cmd4 = new SurveyDefinitionSingleOptionQuestionAddToSectionCmd(survey.SurveyId, section.SectionId, QuestionText, QuestionHelp);
                result = await SurveyClient.AddSingleOptionQuestion(cmd4);

                if (result.Result == CommandSubmitExecutionResult.OK)
                {
                    Guid addedQId = result.UpdatedId;
                    foreach (var item in Options)
                    {
                        var cmd5 = new AddOptionToSingleOptionQuestionCmd(survey.SurveyId, addedQId, item.Text, item.Value);
                        result = await SurveyClient.AddOptionToSingleOptionQuestionCmd(cmd5);
                    }
                }
                break;
            }
            if (result.Result == CommandSubmitExecutionResult.OK)
            {
                UriHelper.NavigateTo($"editsurvey/");
            }
            else
            {
                ValidationMessage = result.Messages.FirstOrDefault();
                Console.WriteLine(ValidationMessage);
            }
        }
示例#12
0
 protected override async Task OnInitAsync()
 {
     surveys = await SurveyClient.GetSurveys();
 }
示例#13
0
        public List <_TwilioMSGViewModel> GetAllMessages()
        {
            // Twilio request of list of messages
            TwilioRestClient   client  = new TwilioRestClient(AuthTwilio.ACCOUNT_SID, AuthTwilio.AUTH_TOKEN);
            MessageListRequest request = new MessageListRequest();
            DateTime           today   = DateTime.Now;

            request.DateSent = today;
            var messages = client.ListMessages(request);
            List <_TwilioMSGViewModel> msg;

            msg = messages.Messages.Select(s => new _TwilioMSGViewModel()
            {
                Body     = s.Body,
                From     = s.From,
                To       = s.To,
                Sid      = s.Sid,
                DateSent = s.DateSent
            }).ToList();

            // Takes Msg looks into Active Campaigns for Keyword, assigns SurveyClient to Campaign
            List <string> TwilioSid = msg.Select(t => t.Sid).ToList();
            List <_TwilioMSGViewModel> newMessages;
            List <_TwilioMSGViewModel> newSurveyClient;

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                List <TwilioMSG> previousMessages = db.TwilioMSGs.Where(m => TwilioSid.Contains(m.TwiilioMSGSid)).ToList();
                newMessages = msg.Where(m => !previousMessages.Any(m2 => m2.TwiilioMSGSid == m.Sid)).ToList();
                if (newMessages.Count != 0)
                {
                    using (ApplicationDbContext context = new ApplicationDbContext())
                    {
                        foreach (_TwilioMSGViewModel element in newMessages)
                        {
                            TwilioMSG dbModel = context.TwilioMSGs.Create();
                            dbModel.TwilioMSGBody = element.Body;
                            dbModel.TwilioMSGFrom = element.From;
                            dbModel.TwilioMSGTo   = element.To;
                            dbModel.TwiilioMSGSid = element.Sid;
                            dbModel.TwilioMSGDate = element.DateSent;
                            context.TwilioMSGs.Add(dbModel);
                        }
                        context.SaveChanges();
                    }
                    List <Campaign>            activeCampaings = db.Campaigns.Where(c => c.CampaignActive == true).ToList();
                    List <string>              activeKeywords  = activeCampaings.Select(k => k.CampaignKeyword).ToList();
                    List <_TwilioMSGViewModel> MsgWithKeywords = newMessages.Where(c => activeKeywords.Contains(c.Body)).ToList();
                    if (MsgWithKeywords.Count != 0)
                    {
                        List <string>       activePhoneNumbers    = db.SurveyClients.Select(p => p.SurveyClientPhone).ToList();
                        List <SurveyClient> previousSurveyClients = db.SurveyClients.Where(s => activePhoneNumbers.Contains(s.SurveyClientPhone)).ToList();
                        newSurveyClient = MsgWithKeywords.Where(q => !previousSurveyClients.Any(q2 => q2.SurveyClientPhone == q.From)).ToList();
                        if (newSurveyClient.Count != 0)
                        {
                            foreach (_TwilioMSGViewModel SClient in newSurveyClient)
                            {
                                using (ApplicationDbContext context = new ApplicationDbContext())
                                {
                                    SurveyClient dbClient = context.SurveyClients.Create();
                                    dbClient.SurveyClientPhone = SClient.From;
                                    context.SurveyClients.Add(dbClient);
                                    context.SaveChanges();
                                }
                                using (ApplicationDbContext context = new ApplicationDbContext())
                                {
                                    SurveyClientControl SCdb = context.SurveyClientControls.Create();
                                    SCdb.SurveyClientId        = context.SurveyClients.Where(x => x.SurveyClientPhone == SClient.From).FirstOrDefault().SurveyClientId;
                                    SCdb.SurveyClientControlId = context.SurveyClients.Where(x => x.SurveyClientPhone == SClient.From).FirstOrDefault().SurveyClientId;
                                    SCdb.SurveyClientPhone     = SClient.From;
                                    SCdb.CampaignId            = context.Campaigns.Where(y => y.CampaignKeyword == SClient.Body).FirstOrDefault().CampaignId;
                                    SCdb.Questions             = context.Questions.Where(q => q.CampaignId == SCdb.CampaignId).ToList();
                                    context.SurveyClientControls.Add(SCdb);
                                    context.SaveChanges();
                                }
                                using (ApplicationDbContext questionDb = new ApplicationDbContext())
                                {
                                    SurveyClientControl dbQuestions = questionDb.SurveyClientControls.Include(s => s.Questions).Where(q => q.SurveyClientPhone == SClient.From).FirstOrDefault();
                                    if (dbQuestions.Questions.Count != 0)
                                    {
                                        foreach (var element in dbQuestions.Questions)
                                        {
                                            using (ApplicationDbContext progressDb = new ApplicationDbContext())
                                            {
                                                Progress dbProgress = progressDb.ProgressSwitches.Create();
                                                dbProgress.ProgressSwitch        = false;
                                                dbProgress.QuestionId            = element.QuestionId;
                                                dbProgress.SurveyClientControlId = dbQuestions.SurveyClientControlId;
                                                progressDb.ProgressSwitches.Add(dbProgress);
                                                progressDb.SaveChanges();
                                            }

                                            using (ApplicationDbContext currentQuestionDb = new ApplicationDbContext())
                                            {
                                                CurrentQuestion dbCQuestion = currentQuestionDb.CurrentQuestionSwitches.Create();
                                                dbCQuestion.CurrentQuestionSwitch = false;
                                                dbCQuestion.QuestionId            = element.QuestionId;
                                                dbCQuestion.SurveyClientControlId = dbQuestions.SurveyClientControlId;
                                                currentQuestionDb.CurrentQuestionSwitches.Add(dbCQuestion);
                                                currentQuestionDb.SaveChanges();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // If Msg does not includes a Keyword, is considered as san Answer and it comes here
                    else
                    {
                        using (ApplicationDbContext questionsCompare = new ApplicationDbContext())
                        {
                            List <SurveyClientControl> SurveyClients = questionsCompare.SurveyClientControls.ToList();
                            List <string> Questions             = questionsCompare.Questions.Select(q => q.QuestionBody).ToList();
                            List <_TwilioMSGViewModel> leftMsgs = newMessages.Where(m => !Questions.Contains(m.Body)).ToList();
                            if (leftMsgs.Count != 0)
                            {
                                foreach (var MsgElement in leftMsgs)
                                {
                                    if (MsgElement.From != "+18324101832")
                                    {
                                        using (ApplicationDbContext LogResponse = new ApplicationDbContext())
                                        {
                                            List <int> Progress_QuestionId      = LogResponse.ProgressSwitches.Where(d => d.ProgressSwitch == true).Select(c => c.QuestionId).ToList();
                                            int        Last_Progress_QuestionId = Progress_QuestionId.LastOrDefault();
                                            Response   AddResponse = LogResponse.Responses.Create();
                                            AddResponse.ResponseBody          = MsgElement.Body;
                                            AddResponse.QuestionId            = Last_Progress_QuestionId;
                                            AddResponse.SurveyClientControlId = SurveyClients.Where(b => b.SurveyClientPhone == MsgElement.From).FirstOrDefault().SurveyClientControlId;
                                            LogResponse.Responses.Add(AddResponse);
                                            LogResponse.SaveChanges();
                                            break;
                                        }
                                    }
                                }
                                using (ApplicationDbContext StatusChangeCurrentQuestion = new ApplicationDbContext())
                                {
                                    foreach (var ClientElement in leftMsgs)
                                    {
                                        List <int> Progress_QuestionId      = StatusChangeCurrentQuestion.ProgressSwitches.Where(d => d.ProgressSwitch == true).Select(c => c.QuestionId).ToList();
                                        List <int> Current_Switches_False   = StatusChangeCurrentQuestion.CurrentQuestionSwitches.Where(c => c.CurrentQuestionSwitch == false).Select(d => d.QuestionId).ToList();
                                        int        Last_Progress_QuestionId = Progress_QuestionId.LastOrDefault();
                                        if (Progress_QuestionId.Count != 0 && Current_Switches_False.Count != 0 && ClientElement.From != "+18324101832")
                                        {
                                            SurveyClientControl CurrentClient = SurveyClients.Where(q => q.SurveyClientPhone == ClientElement.From).FirstOrDefault();
                                            CurrentQuestion     CurrentStatus = StatusChangeCurrentQuestion.CurrentQuestionSwitches.Where(c => c.QuestionId == Last_Progress_QuestionId && c.SurveyClientControlId == CurrentClient.SurveyClientControlId).FirstOrDefault();
                                            CurrentStatus.CurrentQuestionSwitch = true;
                                            StatusChangeCurrentQuestion.SaveChanges();
                                            break;
                                        }
                                        if (Progress_QuestionId.Count != 0 && Current_Switches_False.Count != 0 && ClientElement.From == "+18324101832")
                                        {
                                            SurveyClientControl CurrentClient = SurveyClients.Where(q => q.SurveyClientPhone == ClientElement.To).FirstOrDefault();
                                            CurrentQuestion     CurrentStatus = StatusChangeCurrentQuestion.CurrentQuestionSwitches.Where(c => c.QuestionId == Last_Progress_QuestionId && c.SurveyClientControlId == CurrentClient.SurveyClientControlId).FirstOrDefault();
                                            CurrentStatus.CurrentQuestionSwitch = true;
                                            StatusChangeCurrentQuestion.SaveChanges();
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                // If Not new message, system will send questions to Survey Clients
                else
                {
                    List <SurveyClientControl> SurveyClientsReady;
                    using (ApplicationDbContext serviceReady = new ApplicationDbContext())
                    {
                        SurveyClientsReady = serviceReady.SurveyClientControls.Include(s => s.Questions).Include(s => s.ProgressSwitches).Include(s => s.CurrentQuestionSwitches).Where(q => q.BlackList == false).ToList();
                        foreach (var ClientElement in SurveyClientsReady)
                        {
                            List <int> ProgressIds        = ClientElement.ProgressSwitches.Where(o => o.ProgressSwitch == false).Select(p => p.QuestionId).ToList();
                            List <int> ProgressTrue       = ClientElement.ProgressSwitches.Where(p => p.ProgressSwitch == true).Select(z => z.QuestionId).ToList();
                            List <int> CurrentQuestionIds = ClientElement.CurrentQuestionSwitches.Where(q => q.CurrentQuestionSwitch == true).Select(r => r.CurrentQuestionId).ToList();
                            if (ProgressIds.Count != 0 && CurrentQuestionIds.Count != 0 && ProgressTrue.Count == CurrentQuestionIds.Count)
                            {
                                Question         Question_Filter_Progress = ClientElement.Questions.Where(q => ProgressIds.Contains(q.QuestionId)).FirstOrDefault();
                                TwilioRestClient clientSendMsg            = new TwilioRestClient(AuthTwilio.ACCOUNT_SID, AuthTwilio.AUTH_TOKEN);
                                clientSendMsg.SendSmsMessage("832-410-1832", ClientElement.SurveyClientPhone, Question_Filter_Progress.QuestionBody);
                                using (ApplicationDbContext changeProgress = new ApplicationDbContext())
                                {
                                    Progress ProgressChangeStatus = changeProgress.ProgressSwitches.Where(i => i.QuestionId == Question_Filter_Progress.QuestionId).FirstOrDefault();
                                    ProgressChangeStatus.ProgressSwitch = true;
                                    changeProgress.SaveChanges();
                                }
                            }
                            else
                            {
                                if (ProgressTrue.Count == 0 && CurrentQuestionIds.Count == 0)
                                {
                                    Question         Question_Filter_Progress = ClientElement.Questions.Where(q => ProgressIds.Contains(q.QuestionId)).FirstOrDefault();
                                    TwilioRestClient clientSendMsg            = new TwilioRestClient(AuthTwilio.ACCOUNT_SID, AuthTwilio.AUTH_TOKEN);
                                    clientSendMsg.SendSmsMessage("832-410-1832", ClientElement.SurveyClientPhone, Question_Filter_Progress.QuestionBody);
                                    using (ApplicationDbContext changeProgress = new ApplicationDbContext())
                                    {
                                        Progress ProgressChangeStatus = changeProgress.ProgressSwitches.Where(i => i.QuestionId == Question_Filter_Progress.QuestionId).FirstOrDefault();
                                        ProgressChangeStatus.ProgressSwitch = true;
                                        changeProgress.SaveChanges();
                                    }
                                }
                            }
                            if (ProgressIds.Count == 0 && ClientElement.BlackList == false)
                            {
                                Campaign Coupon;
                                using (ApplicationDbContext lastMsg = new ApplicationDbContext())
                                {
                                    Coupon = lastMsg.Campaigns.Where(q => q.CampaignId == ClientElement.CampaignId).FirstOrDefault();
                                }
                                TwilioRestClient clientSendMsg = new TwilioRestClient(AuthTwilio.ACCOUNT_SID, AuthTwilio.AUTH_TOKEN);
                                clientSendMsg.SendMessage("832-410-1832", ClientElement.SurveyClientPhone, "Thank you for Participating", new string[] { Coupon.CampaignGift });
                                ClientElement.BlackList = true;
                                serviceReady.SaveChanges();
                            }
                        }
                    }
                }
            }
            return(msg);
        }