示例#1
0
        public DTO.Survey GetSurvey(string surveyName)
        {
            UnitOfWork uow = new UnitOfWork();

            Entities.Survey survey = uow.SurveyRepository.Get(s => s.Name == surveyName).SingleOrDefault();
            return(Mapper.Map <DTO.Survey>(survey));
        }
        public SurveyManagementServiceTests()
        {
            _guid            = Guid.NewGuid();
            _guid2           = Guid.NewGuid();
            _nonMatchingGuid = Guid.NewGuid();

            var survey1 = new Entities.Survey
            {
                Id = _guid
            };
            var survey2 = new Entities.Survey
            {
                Id = _guid2
            };
            var allSurveys = new List <Entities.Survey>()
            {
                survey1, survey2
            };
            var filteredSurveys = new List <Entities.Survey>()
            {
                survey1
            };

            _surveyRepository = new Mock <ISurveyRepository>();
            _surveyRepository.Setup(repo =>
                                    repo.Create(It.IsAny <Entities.Survey>())).ReturnsAsync(survey1);

            _surveyRepository.Setup(repo =>
                                    repo.Get(It.Is <Guid>(a => a.Equals(_guid)))).ReturnsAsync(new Entities.Survey
            {
                Id = _guid
            });

            _surveyRepository.Setup(repo =>
                                    repo.Get(It.Is <Guid>(a => a.Equals(_nonMatchingGuid)))).ReturnsAsync(null as Entities.Survey);

            _surveyRepository.Setup(repo =>
                                    repo.Update(It.IsAny <Entities.Survey>()));

            _surveyRepository.Setup(repo =>
                                    repo.List()).ReturnsAsync(allSurveys);

            _surveyRepository.Setup(repo =>
                                    repo.List(It.IsAny <Expression <Func <Entities.Survey, bool> > >())).ReturnsAsync(filteredSurveys);

            _surveyRepository.Setup(repo =>
                                    repo.Delete(It.IsAny <Entities.Survey>()));

            // Options Repository
            _optionsRepository = new Mock <ISurveyQuestionRepository>();
            _optionsRepository.Setup(repo =>
                                     repo.Delete(It.IsAny <Expression <Func <SurveyQuestion, bool> > >()));

            var logger = new Mock <ILogger>();

            logger.Setup(l => l.Error(It.IsAny <Exception>(), It.IsAny <string>()));
            logger.Setup(l => l.Warning(It.IsAny <string>()));

            _svc = new SurveyManagementService(_surveyRepository.Object, logger.Object);
        }
示例#3
0
        public void InsertSurvey(DTO.Survey survey)
        {
            UnitOfWork uow = new UnitOfWork();

            Entities.Survey eSurvey = Mapper.Map <Entities.Survey>(survey);
            uow.SurveyRepository.Insert(eSurvey);
            uow.Save();
        }
示例#4
0
 public void EditSurvey(Entities.Survey survey)
 {
     if (_surveyRepository.GetAllList(a => a.SurveyUrl.ToUpper().Contains(survey.SurveyUrl.ToUpper()) && a.Id != survey.Id).Any())
     {
         throw new UserFriendlyException($"Ya hay una encuesta con esta url: {survey.SurveyUrl}");
     }
     _surveyRepository.InsertOrUpdateAndGetId(survey);
 }
示例#5
0
        public Task <int> CreateSurveyAsync(Entities.Survey survey)
        {
            if (_surveyRepository.GetAllList(a => a.SurveyUrl.ToUpper().Contains(survey.SurveyUrl.ToUpper())).Any())
            {
                throw new UserFriendlyException($"Ya hay una encuesta con esta url: {survey.SurveyUrl}");
            }

            return(_surveyRepository.InsertOrUpdateAndGetIdAsync(survey));
        }
示例#6
0
        public void RemoveQuestion(Question question, Entities.Survey survey)
        {
            var questionAssignment = _surveyQuestionRepository.FirstOrDefault(a => a.QuestionId == question.Id && a.SurveyId == survey.Id);

            if (questionAssignment == null)
            {
                return;
            }
            _surveyQuestionRepository.Delete(questionAssignment);
        }
示例#7
0
        public Task RemoveQuestionAsync(Question question, Entities.Survey survey)
        {
            var questionAssignment = _surveyQuestionRepository.FirstOrDefault(a => a.QuestionId == question.Id && a.SurveyId == survey.Id);

            if (questionAssignment == null)
            {
                return(Task.CompletedTask);
            }
            return(_surveyQuestionRepository.DeleteAsync(questionAssignment));
        }
示例#8
0
 public void InsertSurveyResponse(Entities.SurveyReply c1, Entities.Survey c2)
 {
     using (WSqlCommand s1 = new WSqlCommand(dbconstring, "[dbo].[spInsertSurveyResponse]"))
     {
         s1.AddParameter("@surveyId", System.Data.SqlDbType.Int, c1.surveyId);
         s1.AddParameter("@repliedBy", System.Data.SqlDbType.NVarChar, c1.repliedBy);
         s1.AddParameter("@replyDate", System.Data.SqlDbType.Date, c2.surveyDate);
         s1.Execute();
     }
 }
 /// <summary>
 /// Maps a logic survey to an entity survey type
 /// </summary>
 /// <param name="logicSurvey"></param>
 /// <returns></returns>
 public static Entities.Survey MapSurvey(Logic.Objects.Survey logicSurvey)
 {
     Data.Entities.Survey contextSurvey = new Entities.Survey()
     {
         SurveyId          = logicSurvey.surveyID,
         EventTypeId       = logicSurvey.eventTypeID,
         SurveyDescription = logicSurvey.surveyDescription,
         IsActive          = logicSurvey.active
     };
     return(contextSurvey);
 }
 /// <summary>
 /// Maps context survey to a logic survey
 /// </summary>
 /// <param name="contextSurvey"></param>
 /// <returns></returns>
 public static Logic.Objects.Survey MapSurvey(Entities.Survey contextSurvey)
 {
     Logic.Objects.Survey logicSurvey = new Logic.Objects.Survey()
     {
         surveyID          = contextSurvey.SurveyId,
         eventTypeID       = contextSurvey.EventTypeId,
         surveyDescription = contextSurvey.SurveyDescription,
         active            = contextSurvey.IsActive,
         surveyQuestions   = contextSurvey.SurveyQuestionXref.Select(q => Mapper.MapQuestion(q.SurveyQuestion)).OrderBy(s => s.sortOrder).ToList(),
         removable         = contextSurvey.SurveyQuestionXref.Count == 0
     };
     return(logicSurvey);
 }
示例#11
0
 public static DAL.Survey SurveyDAL(Entities.Survey b)
 {
     return(new DAL.Survey()
     {
         SurveyId = b.SurveyId,
         SurveyIsWork = b.SurveyIsWork,
         SurveySeminar = b.SurveySeminar,
         SurveySubLearnId = b.SurveySubLearnId,
         SurveySubTodayId = b.SurveySubTodayId,
         SurveySubLearnedTxt = b.SurveySubLearnedTxt,
         SurveySubTodayTxt = b.SurveySubTodayTxt
     });
 }
示例#12
0
 protected void AddSurvey(object sender, EventArgs e)
 {
     Page.ClientScript.RegisterStartupScript(GetType(), "id", "toggle_forms('NewSurvey')", true);
     if (Page.IsValid)
     {
         DBHandler.DBHandler db = new DBHandler.DBHandler(con);
         Entities.Survey     s1 = new Entities.Survey()
         {
             surveyName         = ASurveyName.Value,
             surveyDate         = DateTime.Now.ToShortDateString(),
             surveyGeneratedBy  = Session["School"].ToString(),
             surveyGeneratedFor = DropDownList3.SelectedValue,
             type = Convert.ToInt32(RadioButtonList1.SelectedValue),
         };
         surveyid       = db.InsertSurvey(s1);
         Panel1.Visible = true;
         Panel2.Visible = false;
     }
 }
 protected void AddSurvey(object sender, EventArgs e)
 {
     Page.ClientScript.RegisterStartupScript(GetType(), "id", "toggle_forms('NewSurvey')", true);
     if (Page.IsValid)
     {
         DBHandler.DBHandler db = new DBHandler.DBHandler(con);
         Entities.Survey s1 = new Entities.Survey()
         {
             surveyName = ASurveyName.Value,
             surveyDate = DateTime.Now.ToShortDateString(),
             surveyGeneratedBy = Session["School"].ToString(),
             surveyGeneratedFor = DropDownList3.SelectedValue,
             type = Convert.ToInt32(RadioButtonList1.SelectedValue),
         };
         surveyid = db.InsertSurvey(s1);
         Panel1.Visible = true;
         Panel2.Visible = false;
     }
 }
示例#14
0
        public int InsertSurvey(Entities.Survey c1)
        {
            int temp1;

            using (WSqlCommand s1 = new WSqlCommand(dbconstring, "[dbo].[spAddSurvey]"))
            {
                SqlParameter temp = s1.AddOutputParameter("@surveyId", System.Data.SqlDbType.Int);
                s1.AddParameter("@surveyName", System.Data.SqlDbType.NVarChar, c1.surveyName);
                s1.AddParameter("@surveyDate", System.Data.SqlDbType.Date, c1.surveyDate);
                s1.AddParameter("@generatedBy", System.Data.SqlDbType.NVarChar, c1.surveyGeneratedBy);
                s1.AddParameter("@generatedFor", System.Data.SqlDbType.NVarChar, c1.surveyGeneratedFor);
                s1.AddParameter("@type", System.Data.SqlDbType.Int, c1.type);
                s1.AddParameter("@isActive", System.Data.SqlDbType.Bit, c1.isActive);
                s1.Execute();
                temp1 = int.Parse(temp.Value.ToString());
            }

            return(temp1);
        }
示例#15
0
 public Task DeleteSurveyAsync(Entities.Survey survey)
 {
     DeleteRelations(survey.Id);
     DeleteAnswers(survey.Id);
     return(_surveyRepository.DeleteAsync(survey));
 }
示例#16
0
        protected void SubmitSurvey(object sender, EventArgs e)
        {
            if (Panel3.Visible == true)
            {
                foreach (GridViewRow row in GridView3.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        int                  questionid = int.Parse((row.FindControl("Label1") as Label).Text);
                        DropDownList         ddl        = row.FindControl("DropDownList4") as DropDownList;
                        int                  answer     = ddl.SelectedIndex;
                        DBHandler.DBHandler  db         = new DBHandler.DBHandler(con);
                        Entities.SurveyReply s1         = new Entities.SurveyReply()
                        {
                            surveyId   = s,
                            questionId = questionid,
                            answer     = answer,
                            repliedBy  = Session["School"].ToString(),
                        };
                        db.SurveyReply(s1);
                    }
                }

                DBHandler.DBHandler  db1 = new DBHandler.DBHandler(con);
                Entities.SurveyReply s2  = new Entities.SurveyReply()
                {
                    surveyId  = s,
                    repliedBy = Session["School"].ToString(),
                };
                Entities.Survey s3 = new Entities.Survey()
                {
                    surveyDate = DateTime.Now.ToShortDateString(),
                };

                db1.InsertSurveyResponse(s2, s3);

                Page.ClientScript.RegisterStartupScript(GetType(), "id", "toggle_forms('ShowSurvey')", true);
            }

            else if (Panel4.Visible == true)
            {
                foreach (GridViewRow row in GridView1.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        int                  questionid = int.Parse((row.FindControl("Label1") as Label).Text);
                        CheckBox             ddl        = row.FindControl("CheckBox1") as CheckBox;
                        int                  answer     = ddl.Checked ? 6 : 7;
                        DBHandler.DBHandler  db         = new DBHandler.DBHandler(con);
                        Entities.SurveyReply s1         = new Entities.SurveyReply()
                        {
                            surveyId   = s,
                            questionId = questionid,
                            answer     = answer,
                            repliedBy  = Session["School"].ToString(),
                        };
                        db.SurveyReply(s1);
                    }
                }

                DBHandler.DBHandler  db1 = new DBHandler.DBHandler(con);
                Entities.SurveyReply s2  = new Entities.SurveyReply()
                {
                    surveyId  = s,
                    repliedBy = Session["School"].ToString(),
                };
                Entities.Survey s3 = new Entities.Survey()
                {
                    surveyDate = DateTime.Now.ToShortDateString(),
                };

                db1.InsertSurveyResponse(s2, s3);

                Page.ClientScript.RegisterStartupScript(GetType(), "id", "toggle_forms('ShowSurvey')", true);
            }
        }
        protected void SubmitSurvey(object sender, EventArgs e)
        {
            if (Panel3.Visible == true)
            {
                foreach (GridViewRow row in GridView3.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        int questionid = int.Parse((row.FindControl("Label1") as Label).Text);
                        DropDownList ddl = row.FindControl("DropDownList4") as DropDownList;
                        int answer = ddl.SelectedIndex;
                        DBHandler.DBHandler db = new DBHandler.DBHandler(con);
                        Entities.SurveyReply s1 = new Entities.SurveyReply()
                        {
                            surveyId = s,
                            questionId = questionid,
                            answer = answer,
                            repliedBy = Session["School"].ToString(),
                        };
                        db.SurveyReply(s1);
                    }
                }

                DBHandler.DBHandler db1 = new DBHandler.DBHandler(con);
                Entities.SurveyReply s2 = new Entities.SurveyReply()
                {
                    surveyId = s,
                    repliedBy = Session["School"].ToString(),
                };
                Entities.Survey s3 = new Entities.Survey()
                {
                    surveyDate = DateTime.Now.ToShortDateString(),
                };

                db1.InsertSurveyResponse(s2, s3);

                Page.ClientScript.RegisterStartupScript(GetType(), "id", "toggle_forms('ShowSurvey')", true);

            }

            else if (Panel4.Visible == true)
            {
                foreach (GridViewRow row in GridView1.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        int questionid = int.Parse((row.FindControl("Label1") as Label).Text);
                        CheckBox ddl = row.FindControl("CheckBox1") as CheckBox;
                        int answer = ddl.Checked ? 6 : 7;
                        DBHandler.DBHandler db = new DBHandler.DBHandler(con);
                        Entities.SurveyReply s1 = new Entities.SurveyReply()
                        {
                            surveyId = s,
                            questionId = questionid,
                            answer = answer,
                            repliedBy = Session["School"].ToString(),
                        };
                        db.SurveyReply(s1);
                    }
                }

                DBHandler.DBHandler db1 = new DBHandler.DBHandler(con);
                Entities.SurveyReply s2 = new Entities.SurveyReply()
                {
                    surveyId = s,
                    repliedBy = Session["School"].ToString(),
                };
                Entities.Survey s3 = new Entities.Survey()
                {
                    surveyDate = DateTime.Now.ToShortDateString(),
                };

                db1.InsertSurveyResponse(s2, s3);

                Page.ClientScript.RegisterStartupScript(GetType(), "id", "toggle_forms('ShowSurvey')", true);

            }
        }
示例#18
0
 public IHttpActionResult addSurvey([FromBody] Entities.Survey Survey)
 {
     return(Ok(BL.SelectorJob.addSurvey(Survey)));
 }
        public void Insert()
        {
            using (var session = FluentNHibernateConfiguration.InitFactory.sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var user = new Entities.Member { userName = "******", memberPassword = "******" };

                    var survey = new Entities.Survey { surveyDescription = "A Random Sample Survey. This is just a sample of how json can be used to render a survey.", surveyTitle = "Sample Survey", surveyQuestionList = new List<Entities.SurveyQuestion>() };
                    survey.surveyQuestionList.Add(new Entities.SurveyQuestion { surveyQuestionTitle = "What is your, favourite, color?", surveyQuestionType = 0, surveyQuestionOptionList = new List<Entities.SurveyQuestionOption>() });
                    survey.surveyQuestionList.ElementAt(0).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "White" });
                    survey.surveyQuestionList.ElementAt(0).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Yellow" });
                    survey.surveyQuestionList.ElementAt(0).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Blue" });
                    survey.surveyQuestionList.ElementAt(0).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Green" });
                    survey.surveyQuestionList.ElementAt(0).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Enter another color:", surveyQuestionOptionType = 2 });
                    survey.surveyQuestionList.Add(new Entities.SurveyQuestion { surveyQuestionTitle = "Who is the most hardworking person in our team?", surveyQuestionType = 0, surveyQuestionOptionList = new List<Entities.SurveyQuestionOption>() });
                    survey.surveyQuestionList.ElementAt(1).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "June" });
                    survey.surveyQuestionList.ElementAt(1).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://graph.facebook.com/weileng.peh/picture?type=large", surveyQuestionOptionTitleType = 2 });
                    survey.surveyQuestionList.ElementAt(1).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Hong Jing" });
                    survey.surveyQuestionList.ElementAt(1).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Xu Ai" });
                    survey.surveyQuestionList.ElementAt(1).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Wesley" });
                    survey.surveyQuestionList.Add(new Entities.SurveyQuestion { surveyQuestionTitle = "And the best phone is", surveyQuestionType = 0, surveyQuestionOptionList = new List<Entities.SurveyQuestionOption>() });
                    survey.surveyQuestionList.ElementAt(2).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Galaxy S 3" });
                    survey.surveyQuestionList.ElementAt(2).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Galaxy S 2" });
                    survey.surveyQuestionList.ElementAt(2).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Galaxy S" });
                    survey.surveyQuestionList.ElementAt(2).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "HTC One X" });
                    survey.surveyQuestionList.ElementAt(2).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Galaxy Nexus" });
                    survey.surveyQuestionList.ElementAt(2).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Motorola Droid Razr Maxx" });
                    survey.surveyQuestionList.Add(new Entities.SurveyQuestion { surveyQuestionTitle = "Who is the most hardworking person in our team? (You can choose more than 1 answer)", surveyQuestionType = 1, surveyQuestionOptionList = new List<Entities.SurveyQuestionOption>() });
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://graph.facebook.com/weileng.peh/picture?type=large", surveyQuestionOptionTitleType = 2 });
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "June" });
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "June" });
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "June" });
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "June" });
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "June" });
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "June" });
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "June" });
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "June" });
                    survey.surveyQuestionList.Add(new Entities.SurveyQuestion { surveyQuestionTitle = "How hardworking is June?", surveyQuestionType = 2, surveyQuestionOptionList = new List<Entities.SurveyQuestionOption>() });
                    survey.surveyQuestionList.ElementAt(4).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "Hardworkingness" , surveyQuestionOptionMaxText="Very Very Hardworking", surveyQuestionOptionMinText="Very Hardworking"});
                    survey.surveyQuestionList.Add(new Entities.SurveyQuestion { surveyQuestionTitle = "How young is this pretty young star? Numeric input.", surveyQuestionType = 3, surveyQuestionOptionList = new List<Entities.SurveyQuestionOption>() });
                    survey.surveyQuestionList.ElementAt(5).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://graph.facebook.com/weileng.peh/picture?type=large" });
                    survey.surveyQuestionList.Add(new Entities.SurveyQuestion { surveyQuestionTitle = "Or the birthday of this talented actor/singer? Date input.", surveyQuestionType = 4, surveyQuestionOptionList = new List<Entities.SurveyQuestionOption>() });
                    survey.surveyQuestionList.ElementAt(6).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://graph.facebook.com/197371292379/picture?type=large" });
                    survey.surveyQuestionList.Add(new Entities.SurveyQuestion { surveyQuestionTitle = "Which picture is the odd one out?", surveyQuestionType = 5, surveyQuestionOptionList = new List<Entities.SurveyQuestionOption>() });
                    survey.surveyQuestionList.ElementAt(7).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://graph.facebook.com/alexei.sourin/picture?type=square" , surveyQuestionOptionTitleType=2 });
                    survey.surveyQuestionList.ElementAt(7).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "test", surveyQuestionOptionTitleType = 0 });
                    survey.surveyQuestionList.ElementAt(7).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://graph.facebook.com/bengkoon.ng/picture?type=square", surveyQuestionOptionTitleType = 2 });
                    survey.surveyQuestionList.ElementAt(7).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://graph.facebook.com/bingsheng.he/picture?type=square", surveyQuestionOptionTitleType = 2 });
                    survey.surveyQuestionList.ElementAt(7).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://graph.facebook.com/limws.brandon/picture?type=square", surveyQuestionOptionTitleType = 2 });
                    survey.surveyQuestionList.Add(new Entities.SurveyQuestion { surveyQuestionTitle = "Please give your opinion of this survey in a single sentence.", surveyQuestionType = 6, surveyQuestionOptionList = new List<Entities.SurveyQuestionOption>() });
                    survey.surveyQuestionList.ElementAt(8).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://graph.facebook.com/197371292379/picture?type=large" });
                    survey.surveyQuestionList.Add(new Entities.SurveyQuestion { surveyQuestionTitle = "Opinon. In. A. Paragraph.", surveyQuestionType = 7, surveyQuestionOptionList = new List<Entities.SurveyQuestionOption>() });
                    survey.surveyQuestionList.ElementAt(9).surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://graph.facebook.com/197371292379/picture?type=large" });
                    var respondent = new Entities.Respondent { respondentIPAddress = "127.0.0.1", respondentSessionID = "randomid" };

                    var responseqn0 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 1 };
                    respondent.surveyQuestionResponseList.Add(responseqn0);
                    survey.surveyQuestionList.ElementAt(0).surveyQuestionResponseList.Add(responseqn0);
                    var responseqn1 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 3 };
                    respondent.surveyQuestionResponseList.Add(responseqn1);
                    survey.surveyQuestionList.ElementAt(1).surveyQuestionResponseList.Add(responseqn1);
                    var responseqn2 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 4 };
                    respondent.surveyQuestionResponseList.Add(responseqn2);
                    survey.surveyQuestionList.ElementAt(2).surveyQuestionResponseList.Add(responseqn2);
                    var responseqn30 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 2 };
                    var responseqn31 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 3 };
                    var responseqn32 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 6 };
                    respondent.surveyQuestionResponseList.Add(responseqn30);
                    respondent.surveyQuestionResponseList.Add(responseqn31);
                    respondent.surveyQuestionResponseList.Add(responseqn32);
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionResponseList.Add(responseqn30);
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionResponseList.Add(responseqn31);
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionResponseList.Add(responseqn32);
                    var responseqn4 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 2, responseStringValue = "100" };
                    respondent.surveyQuestionResponseList.Add(responseqn4);
                    survey.surveyQuestionList.ElementAt(4).surveyQuestionResponseList.Add(responseqn4);
                    var responseqn5 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 2, responseIntegerValue = 3, responseStringValue = "345" };
                    respondent.surveyQuestionResponseList.Add(responseqn5);
                    survey.surveyQuestionList.ElementAt(5).surveyQuestionResponseList.Add(responseqn5);
                    var responseqn6 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 2, responseStringValue = "09/05/2012" };
                    respondent.surveyQuestionResponseList.Add(responseqn6);
                    survey.surveyQuestionList.ElementAt(6).surveyQuestionResponseList.Add(responseqn6);
                    var responseqn7 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 1 };
                    respondent.surveyQuestionResponseList.Add(responseqn7);
                    survey.surveyQuestionList.ElementAt(7).surveyQuestionResponseList.Add(responseqn7);

                    survey.AddRespondent(respondent);

                    var respondent1 = new Entities.Respondent { respondentIPAddress = "127.0.0.1", respondentSessionID = "randomid1" };
                    var responseqn10 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 2 };
                    respondent1.surveyQuestionResponseList.Add(responseqn10);
                    survey.surveyQuestionList.ElementAt(0).surveyQuestionResponseList.Add(responseqn10);
                    var responseqn11 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 3 };
                    respondent1.surveyQuestionResponseList.Add(responseqn11);
                    survey.surveyQuestionList.ElementAt(1).surveyQuestionResponseList.Add(responseqn11);
                    var responseqn12 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 4 };
                    respondent1.surveyQuestionResponseList.Add(responseqn12);
                    survey.surveyQuestionList.ElementAt(2).surveyQuestionResponseList.Add(responseqn12);
                    var responseqn130 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 0 };
                    var responseqn131 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 5 };
                    var responseqn132 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 6 };
                    respondent1.surveyQuestionResponseList.Add(responseqn130);
                    respondent1.surveyQuestionResponseList.Add(responseqn131);
                    respondent1.surveyQuestionResponseList.Add(responseqn132);
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionResponseList.Add(responseqn130);
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionResponseList.Add(responseqn131);
                    survey.surveyQuestionList.ElementAt(3).surveyQuestionResponseList.Add(responseqn132);
                    var responseqn14 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 2, responseStringValue = "10" };
                    respondent1.surveyQuestionResponseList.Add(responseqn14);
                    survey.surveyQuestionList.ElementAt(4).surveyQuestionResponseList.Add(responseqn14);
                    var responseqn15 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 2, responseIntegerValue = 3, responseStringValue = "43" };
                    respondent1.surveyQuestionResponseList.Add(responseqn15);
                    survey.surveyQuestionList.ElementAt(5).surveyQuestionResponseList.Add(responseqn15);
                    var responseqn16 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 2, responseStringValue = "09/05/2012" };
                    respondent1.surveyQuestionResponseList.Add(responseqn16);
                    survey.surveyQuestionList.ElementAt(6).surveyQuestionResponseList.Add(responseqn16);
                    var responseqn17 = new Entities.SurveyQuestionResponse { responseIsAnswered = true, responseType = 1, responseIntegerValue = 0 };
                    respondent1.surveyQuestionResponseList.Add(responseqn17);
                    survey.surveyQuestionList.ElementAt(7).surveyQuestionResponseList.Add(responseqn17);

                    survey.AddRespondent(respondent1);

                    user.AddSurvey(survey);
                    session.SaveOrUpdate(user);
                    transaction.Commit();

                }

            }
            //Context.Response.Write(js.Serialize(survey));
        }
示例#20
0
 public void DeleteSurvey(Entities.Survey survey)
 {
     _surveyRepository.Delete(survey);
 }
        public void repeater(string formString, string elementString, string memberHash)
        {
            using (var session = FluentNHibernateConfiguration.InitFactory.sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    JObject jsonObject = JObject.Parse(formString);
                    var survey = new Entities.Survey { surveyTitle = jsonObject.SelectToken("name").ToString(), surveyDescription = jsonObject.SelectToken("description").ToString() };
                    JToken jToken;
                    jsonObject = JObject.Parse(elementString);
                    var questionList = jsonObject.SelectToken("elements").ToList();
                    foreach (var question in questionList)
                    {
                        switch (question.SelectToken("type").ToString())
                        {
                            case "number":
                                {
                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 3, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "" });
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                    break;
                                }
                            case "radio":
                                {
                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 0, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    foreach (var option in question.SelectToken("options").ToList())
                                    {
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = option.SelectToken("option").ToString() });
                                    }
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                    break;
                                }
                            case "checkbox":
                                {
                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 1, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    foreach (var option in question.SelectToken("options").ToList())
                                    {
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = option.SelectToken("option").ToString() });
                                    }
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                    break;
                                }
                            case "date":
                                {
                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 4, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "" });
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                    break;
                                }
                            case "slider":
                                {
                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 2, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "", surveyQuestionOptionMaxText = question.SelectToken("size_max") != null ? question.SelectToken("size_max").ToString() : "Max", surveyQuestionOptionMinText = question.SelectToken("size_min") !=null? question.SelectToken("size_min").ToString() : "Min" });
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                    break;
                                }
                            case "scaler":
                                {
                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 5, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    int size = Int32.Parse(question.SelectToken("scaleAmount").ToString()) == null ? 5 : Int32.Parse(question.SelectToken("scaleAmount").ToString());
                                    for (int i = 0; i < size; i++)
                                    {
                                        if (i == 0) surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("mintext")!=null?question.SelectToken("mintext").ToString():"Worst" });
                                        else if (i == (size - 1)) surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("maxtext")!=null?question.SelectToken("maxtext").ToString():"Best" });
                                        else surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "" });
                                    }
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                        break;
                                }

                            case "text":
                                {
                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 6, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "" });
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                    break;
                                }

                            case "textarea":
                                {
                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 7, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "" });
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                    break;
                                }
                            case "signature":
                                {

                                    break;
                                }
                            case "photo":
                                {

                                    break;
                                }
                            case "section":
                                {

                                    break;
                                }
                            case "img_checkbox":
                                {

                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 1, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    if (question.SelectToken("satisfactory_vUnsatisfactory")!=null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("satisfactory_vUnsatisfactory").ToString(), surveyQuestionOptionTitleType = 2 });
                                    if (question.SelectToken("satisfactory_Unsatisfactory") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("satisfactory_Unsatisfactory").ToString(), surveyQuestionOptionTitleType = 2 });
                                    if (question.SelectToken("satisfactory_Neutral") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("satisfactory_Neutral").ToString(), surveyQuestionOptionTitleType = 2 });
                                    if (question.SelectToken("satisfactory_Satisfactory")!=null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("satisfactory_Satisfactory").ToString(), surveyQuestionOptionTitleType = 2 });
                                    if (question.SelectToken("satisfactory_vSatisfactory")!=null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("satisfactory_vSatisfactory").ToString(), surveyQuestionOptionTitleType = 2 });
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                    break;
                                }
                            case "satisfactory":
                                {
                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 5, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    if (question.SelectToken("satisfactory_vUnsatisfactory") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("satisfactory_vUnsatisfactory").ToString(), surveyQuestionOptionTitleType = question.SelectToken("satisfactory_vUnsatisfactory").ToString().Contains("://") ?  2 :  1 });
                                    if (question.SelectToken("satisfactory_Unsatisfactory") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("satisfactory_Unsatisfactory").ToString(), surveyQuestionOptionTitleType = question.SelectToken("satisfactory_vUnsatisfactory").ToString().Contains("://") ? 2 : 1 });
                                    if (question.SelectToken("satisfactory_Neutral") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("satisfactory_Neutral").ToString(), surveyQuestionOptionTitleType = question.SelectToken("satisfactory_vUnsatisfactory").ToString().Contains("://") ? 2 : 1 });
                                    if (question.SelectToken("satisfactory_Satisfactory") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("satisfactory_Satisfactory").ToString(), surveyQuestionOptionTitleType = question.SelectToken("satisfactory_vUnsatisfactory").ToString().Contains("://") ? 2 : 1 });
                                    if (question.SelectToken("satisfactory_vSatisfactory") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("satisfactory_vSatisfactory").ToString(), surveyQuestionOptionTitleType = question.SelectToken("satisfactory_vUnsatisfactory").ToString().Contains("://") ? 2 : 1 });
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                    break;
                                }
                            case "img_radio":
                                {
                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 0, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    if ((question.SelectToken("img_radio_vUnsatisfactory") == null) && (question.SelectToken("img_radio_Neutral") == null) && (question.SelectToken("img_radio_vSatisfactory") == null))
                                    {
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://twocube1.elasticbeanstalk.com/images/faces_1.png", surveyQuestionOptionTitleType = 2 });
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://twocube1.elasticbeanstalk.com/images/faces_2.png", surveyQuestionOptionTitleType = 2 });
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://twocube1.elasticbeanstalk.com/images/faces_3.png", surveyQuestionOptionTitleType = 2 });
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://twocube1.elasticbeanstalk.com/images/faces_4.png", surveyQuestionOptionTitleType = 2 });
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = "http://twocube1.elasticbeanstalk.com/images/faces_5.png", surveyQuestionOptionTitleType = 2 });
                                    }
                                    if (question.SelectToken("img_radio_vUnsatisfactory") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("img_radio_vUnsatisfactory").ToString(), surveyQuestionOptionTitleType = 2 });
                                    if (question.SelectToken("img_radio_Unsatisfactory") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("img_radio_Unsatisfactory").ToString(), surveyQuestionOptionTitleType = 2 });
                                    if (question.SelectToken("img_radio_Neutral") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("img_radio_Neutral").ToString(), surveyQuestionOptionTitleType = 2 });
                                    if (question.SelectToken("img_radio_Satisfactory") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("img_radio_Satisfactory").ToString(), surveyQuestionOptionTitleType = 2 });
                                    if (question.SelectToken("img_radio_vSatisfactory") != null)
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = question.SelectToken("img_radio_vSatisfactory").ToString(), surveyQuestionOptionTitleType = 2 });
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                    break;
                                }
                            case "select":
                                {
                                    var surveyQuestion = new Entities.SurveyQuestion { surveyQuestionTitle = question.SelectToken("title").ToString(), surveyQuestionType = 10, surveyQuestionIsCompulsory = question.SelectToken("title").ToString() == "1" };
                                    foreach (var option in question.SelectToken("options").ToList())
                                    {
                                        surveyQuestion.surveyQuestionOptionList.Add(new Entities.SurveyQuestionOption { surveyQuestionOptionTitle = option.SelectToken("option").ToString() });
                                    }
                                    survey.surveyQuestionList.Add(surveyQuestion);
                                    break;
                                }

                        }
                    }
                    //var member = Member.GetById(session,1);
                    var member = Member.GetByHash(session, memberHash);
                    member.AddSurvey(survey);
                    session.SaveOrUpdate(member);
                    transaction.Commit();
                    HttpContext.Current.Response.Redirect("./../../viewsurveylist.htm");
                }

            }
        }