Esempio n. 1
0
        public static DTO.poll ToApp(this poll poll)
        {
            DTO.poll pollDTO = null;

            if (poll != null)
            {
                pollDTO = new DTO.poll();

                pollDTO.poll_id          = poll.poll_id;
                pollDTO.poll_description = poll.poll_description;
                pollDTO.views            = poll.views;

                foreach (var item in poll.option)
                {
                    pollDTO.options.Add(new optionDTO()
                    {
                        option_id          = item.option_id,
                        option_description = item.option_description,
                        qty = item.qty
                    });
                }
            }

            return(pollDTO);
        }
Esempio n. 2
0
        public HttpResponseMessage Vote(long id, [FromBody] optionDTO optionDTO)
        {
            var httpResponseMessage = new HttpResponseMessage();

            try
            {
                var poll = new poll();

                poll.poll_id = id;
                poll.options.Add(optionDTO);

                var polls = pollBusiness.GetAll(poll);

                if (polls == null || polls.Count <= 0)
                {
                    httpResponseMessage = Request.CreateResponse(HttpStatusCode.NotFound);
                }
                else
                {
                    pollBusiness.Vote(poll);

                    httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, "Vote registered.");
                }
            }
            catch (BusinessException ex)
            {
                httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, ex.Message);
            }
            catch (Exception ex)
            {
                httpResponseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }

            return(httpResponseMessage);
        }
Esempio n. 3
0
        public static poll ToBd(this DTO.poll pollDTO)
        {
            poll poll = null;

            if (pollDTO != null)
            {
                poll = new poll();

                poll.poll_id          = pollDTO.poll_id;
                poll.poll_description = pollDTO.poll_description;
                poll.views            = pollDTO.views;

                foreach (var item in pollDTO.options)
                {
                    poll.option.Add(new option()
                    {
                        option_id          = item.option_id,
                        option_description = item.option_description,
                        qty = item.qty
                    });
                }
            }

            return(poll);
        }
Esempio n. 4
0
        /// <summary>
        /// Verilen pollid yi active/deactive yapar
        /// </summary>
        /// <param name="pollid">Anket Id</param>
        /// <param name="userid">Giris yapmis olan kullanici</param>
        /// <param name="authkey">Dogrulama keyi</param>
        /// <returns></returns>
        public string SetPersonnelToggleActivePoll(dynamic jsonData)
        {
            long   pollId  = jsonData.pollid;
            long   userId  = jsonData.userid;
            string authKey = jsonData.authkey;

            user loggedUser = DatabaseService.CheckUserAuth(userId, authKey);

            if (loggedUser == null)
            {
                return(Helper.GetResult(false, "0x0009"));
            }

            poll editPoll = EntityConnectionService.Poll.GetSingle(
                x => x.pollid.Equals(pollId) && x.ownerid.Equals(userId) && x.ownertype.Equals("P"));

            if (editPoll == null)
            {
                return(Helper.GetResult(false, "0x0012"));
            }

            editPoll.active = editPoll.active != "X" ? "X" : "";
            if (EntityConnectionService.Poll.Update(editPoll))
            {
                return(Helper.GetResult(true, true));
            }

            return(Helper.GetResult(false, "0x0019"));
        }
Esempio n. 5
0
        /// <summary>
        /// Verilen pollid yi active/deactive yapar
        /// </summary>
        /// <param name="pollid">Anket Id</param>
        /// <param name="ownerid">Anketi acan kullanicinin Id si</param>
        /// <param name="staffid">istegi atan kullanici</param>
        /// <param name="authkey">Dogrulama keyi</param>
        /// <returns></returns>
        public string SetCompanyToggleActivePoll(dynamic jsonData)
        {
            long   pollId  = jsonData.pollid;
            long   ownerid = jsonData.ownerid;
            long   staffid = jsonData.staffid;
            string authKey = jsonData.authkey;

            staff loggedUser = DatabaseService.CheckStaffAuth(staffid, authKey, ownerid);

            if (loggedUser == null)
            {
                return(Helper.GetResult(false, "0x0009"));
            }

            poll editPoll = EntityConnectionService.Poll.GetSingle(
                x => x.pollid.Equals(pollId) && x.ownerid.Equals(ownerid) && x.ownertype.Equals("C"));

            if (editPoll == null)
            {
                return(Helper.GetResult(false, "0x0012"));
            }

            editPoll.active = editPoll.active != "X" ? "X" : "";
            if (EntityConnectionService.Poll.Update(editPoll))
            {
                return(Helper.GetResult(true, true));
            }

            return(Helper.GetResult(false, "0x0019"));
        }
        public HttpResponseMessage PostPoll(JObject EmpData)
        {
            if (EmpData == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            try
            {
                dynamic json    = EmpData;
                poll    new_pol = new poll();
                new_pol.poll_description = json.poll_description;
                db.poll.Add(new_pol);
                db.SaveChanges();

                List <options> listStatus = new List <options>();
                foreach (var item in json.options)
                {
                    options statusNew = new options();
                    statusNew.option_description = item;
                    statusNew.poll_id            = new_pol.poll_id;
                    listStatus.Add(statusNew);
                }
                db.option.AddRange(listStatus);
                db.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.OK, new { poll_id = new_pol.poll_id }));
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao incluir"));
            }
        }
Esempio n. 7
0
 public bool commitInsertPoll(poll newPoll)
 {
     using (objPoll)
     {
         objPoll.polls.InsertOnSubmit(newPoll);
         objPoll.SubmitChanges();
         return(true);
     }
 }
Esempio n. 8
0
        public static string AddPoll(long ownerid, string ownerType, long crusr, string isPrivate, string isIpCheck, string isCookieCheck, string isPassword, string password, string fieldData, string isShowResult, PollModel poll)
        {
            poll newPoll = new poll
            {
                ownertype     = ownerType,
                ownerid       = ownerid,
                polltitle     = poll.PollTitle,
                crusr         = crusr,
                isprivate     = isPrivate,
                isipcheck     = isIpCheck,
                iscookiecheck = isCookieCheck,
                ispassword    = isPassword,
                password      = password,
                fielddata     = fieldData,
                isshowresult  = isShowResult,
                active        = "X",
                viewcount     = 0
            };

            List <answer> pollAnswers = new List <answer>();

            if (EntityConnectionService.Poll.Add(newPoll))
            {
                for (int i = 0; i < poll.Questions.Count; i++)
                {
                    question addQuestion = new question
                    {
                        ownerid      = ownerid,
                        ownertype    = ownerType,
                        pollid       = newPoll.pollid,
                        questionid   = poll.Questions[i].QuestionId,
                        content      = poll.Questions[i].Content,
                        questiontype = poll.Questions[i].QuestionType,
                    };
                    EntityConnectionService.Question.Add(addQuestion);

                    for (int j = 0; j < poll.Questions[i].Answers.Count; j++)
                    {
                        pollAnswers.Add(new answer
                        {
                            ownerid    = ownerid,
                            ownertype  = ownerType,
                            pollid     = newPoll.pollid,
                            questionid = addQuestion.questionid,
                            content    = poll.Questions[i].Answers[j].Content,
                            answertype = poll.Questions[i].Answers[j].AnswerType
                        });
                    }
                    EntityConnectionService.Answer.Add(pollAnswers.ToArray());
                    pollAnswers = new List <answer>();
                }
                return(Helper.GetResult(true, newPoll.pollid));
            }

            return(Helper.GetResult(false, "0x0010"));
        }
Esempio n. 9
0
        public void Vote()
        {
            poll poll = new poll();

            poll.poll_id = POLL_ID;
            poll.options.Add(new optionDTO()
            {
                option_id = OPTION_ID
            });

            pollBusiness.Vote(poll);

            Assert.IsNotNull(poll);
        }
Esempio n. 10
0
        public ActionResult UpdatePoll(int id)       //  Get : admin page , update a poll from the list of polls
        {
            ViewBag.Group = "Admin";
            poll loadPoll = pollObj.getPollByID(id);

            if (loadPoll == null)
            {
                return(View());
            }
            else
            {
                return(View(loadPoll));               // displays the poll will all the data that can be edited
            }
        }
Esempio n. 11
0
        public ActionResult DeletePoll(int id)            // get : admin page, delete a poll from a list of polls
        {
            ViewBag.Group = "Admin";
            poll loadPoll = pollObj.getPollByID(id);

            if (loadPoll == null)
            {
                return(View());
            }
            else
            {
                TempData["id"] = id;
                return(View(loadPoll));                      // loads the poll that has to be deleted, with a option to confirm delete
            }
        }
Esempio n. 12
0
        public ActionResult UpdatePoll(int id, poll updPoll)      // Post : admin page, with the data that has been edited
        {
            ViewBag.Group = "Admin";
            if (ModelState.IsValid)
            {
                try
                {
                    pollObj.commitUpdatePoll(id, updPoll.question, updPoll.option1, updPoll.option2);   // data sent for updation
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View());
                }
            }

            return(View());
        }
        public ActionResult poll(int instance, string email)
        {
            ViewBag.choices = context.Choices.Where(x => x.InstanceId == instance).ToList();
            var         participants   = context.Participants.Where(x => x.InstanceId == instance).GroupBy(x => x.Participantsemail).ToList();
            List <poll> newpoll        = new List <poll>();
            int?        topchoicevalue = 0;
            var         topchoicename  = "";

            foreach (var item in participants)
            {
                poll newdata = new poll();
                newdata.Participantsemail = item.Key;
                newdata.participant       = context.Participants.Where(x => x.Participantsemail == item.Key && x.InstanceId == instance).ToList();
                newpoll.Add(newdata);
            }

            ViewBag.participants = newpoll;
            var choicesgroup = context.Participants.Where(x => x.InstanceId == instance).GroupBy(x => x.ChoiceId).ToList();

            foreach (var choices in choicesgroup)
            {
                int?totalrating = 0;
                var choicename  = "";
                foreach (var rating in choices)
                {
                    if (rating.Rating != null)
                    {
                        totalrating += rating.Rating;
                    }
                    choicename = rating.Choice.ChoiceName;
                }

                if (totalrating > topchoicevalue)
                {
                    topchoicevalue = totalrating;
                    topchoicename  = choicename;
                }
            }

            ViewBag.topchoicename = topchoicename;

            ViewBag.email = email;
            return(View());
        }
Esempio n. 14
0
        public ActionResult AddPoll(poll newPoll)   // Post : Admin Page, form is submitted and added to the database
        {
            newPoll.published = false;              // published vlaue is by default set to false.
            ViewBag.Group     = "Admin";
            if (ModelState.IsValid)
            {
                try
                {
                    pollObj.commitInsertPoll(newPoll);
                    return(RedirectToAction("Index"));         // redirects to list of all polls
                }
                catch
                {
                    return(View());
                }
            }

            return(View());
        }
Esempio n. 15
0
        public HttpResponseMessage Poll(poll poll)
        {
            var httpResponseMessage = new HttpResponseMessage();

            try
            {
                var poll_id = pollBusiness.Poll(poll);

                httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, new { poll_id = poll_id });
            }
            catch (BusinessException ex)
            {
                httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, ex.Message);
            }
            catch (Exception ex)
            {
                httpResponseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }

            return(httpResponseMessage);
        }
Esempio n. 16
0
        public void Poll()
        {
            poll poll = new poll();

            poll.poll_description = $"Poll_{DateTime.Now}";
            poll.options.Add(new optionDTO()
            {
                option_description = "Opção 1"
            });
            poll.options.Add(new optionDTO()
            {
                option_description = "Opção 2"
            });
            poll.options.Add(new optionDTO()
            {
                option_description = "Opção 3"
            });

            var poll_id = pollBusiness.Poll(poll);

            Assert.IsTrue(poll_id > 0);
        }
    static void publish(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        // --- Create topic --- //

        /* Register type before creating topic */
        System.String type_name = pollTypeSupport.get_type_name();
        try {
            pollTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example poll",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create writer --- //

        /* To customize data writer QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DataWriter writer = publisher.create_datawriter(
            topic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        pollDataWriter poll_writer =
            (pollDataWriter)writer;

        // --- Write --- //

        /* Create data sample for writing */
        poll instance = pollTypeSupport.create_data();

        if (instance == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "pollTypeSupport.create_data error");
        }

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

        /*
         * instance_handle = poll_writer.register_instance(instance);
         */

        Random random = new Random();

        /* Main loop */
        const System.Int32 send_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            Console.WriteLine("Writing poll, count {0}", count);

            /* Modify the data to be sent here */
            instance.x = (short)random.Next();

            try {
                poll_writer.write(instance, ref instance_handle);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("write error {0}", e);
            }

            System.Threading.Thread.Sleep(send_period);
        }

        /*
         * try {
         *  poll_writer.unregister_instance(
         *      instance, ref instance_handle);
         * } catch(DDS.Exception e) {
         *  Console.WriteLine("unregister instance error: {0}", e);
         * }
         */

        // --- Shutdown --- //

        /* Delete data sample */
        try {
            pollTypeSupport.delete_data(instance);
        } catch (DDS.Exception e) {
            Console.WriteLine(
                "pollTypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
Esempio n. 18
0
        /// <summary>
        /// Guestin cevaplarini tablolara insert eder.
        /// </summary>
        /// <param name="pollid">Anket Id</param>
        /// <param name="ownerid">Anketi acan kullanicinin Id si</param>
        /// <param name="ownertype">Anketi acan kullanici type i</param>
        /// <param name="guestanswerdata">Kullanicinin cevaplari : [{QuestionId:'SoruId',AnswerId:'CevapId'}]</param>
        /// <param name="staffid">eger private anket ise doldurulur o an anketi yapan staffid sidir</param>
        /// <param name="authkey">eger private anket ise doldurulur o an anketi yapan authkey idir</param>
        /// <param name="fielddata">PollMaster da belirtilen field larin doldurulmus verisini alir database e basar.[{"FieldCode":"ad-soyad","FieldValue":"test"}]</param>
        /// <returns></returns>
        public string SetGuestAnswers(dynamic jsonData)
        {
            string             fieldData      = jsonData.fielddata;
            long               pollId         = jsonData.pollid;
            long               ownerId        = jsonData.ownerid;
            string             ownerType      = jsonData.ownertype;
            int                complateSecond = jsonData.complatesecond;
            string             ip             = jsonData.ip;
            List <GuestAnswer> answerList     = jsonData.guestanswerdata.ToObject <List <GuestAnswer> >();

            poll pollMaster =
                EntityConnectionService.Poll.GetSingle(x => x.pollid.Equals(pollId) && x.ownerid.Equals(ownerId) && x.ownertype.Equals(ownerType));

            if (pollMaster == null)
            {
                return(Helper.GetResult(false, "0x0012"));
            }

            if (pollMaster.active != "X")
            {
                return(Helper.GetResult(false, "0x0020"));
            }

            if (pollMaster.isipcheck == ("X"))
            {
                guest pollGuest = EntityConnectionService.Guest.GetSingle(x => x.ip == ip && x.ownerid == ownerId && x.ownertype == ownerType && x.pollid == pollId);
                if (pollGuest != null)
                {
                    return(Helper.GetResult(false, "0x0018"));
                }
            }

            if (pollMaster.isprivate == ("X"))
            {
                long   staffId = jsonData.staffid;
                string authKey = jsonData.authkey;

                staff loggedUser = DatabaseService.CheckStaffAuth(staffId, authKey, ownerId);
                if (loggedUser == null)
                {
                    return(Helper.GetResult(false, "0x0017"));
                }
            }

            guest guest = new guest
            {
                fielddata      = fieldData,
                pollid         = pollId,
                ownerid        = ownerId,
                ownertype      = ownerType,
                ip             = ip,
                complatesecond = complateSecond
            };

            if (!EntityConnectionService.Guest.Add(guest))
            {
                return(Helper.GetResult(false, "0x0013"));
            }

            List <guestanswer> guestanswers = new List <guestanswer>();

            for (int i = 0; i < answerList.Count; i++)
            {
                guestanswers.Add(new guestanswer()
                {
                    pollid     = pollId,
                    ownerid    = ownerId,
                    ownertype  = ownerType,
                    questionid = answerList[i].QuestionId,
                    answerid   = answerList[i].AnswerId,
                    guestid    = guest.guestid
                });
            }

            if (!EntityConnectionService.GuestAnswer.Add(guestanswers.ToArray()))
            {
                return(Helper.GetResult(false, "0x0014"));
            }

            return(Helper.GetResult(true, true));
        }
Esempio n. 19
0
        /// <summary>
        /// Verilen bilgilere ait anketin verisini dondurur.
        /// </summary>
        /// <param name="pollid">Anket idsi</param>
        /// <param name="ownerid">Anketi olusturan kullanici idsi</param>
        /// <param name="ownertype">Anketi olusturan kullanici type i</param>
        /// <returns></returns>
        public string GetPollData(dynamic jsonData)
        {
            long   pollId     = jsonData.pollid;
            long   ownerId    = jsonData.ownerid;
            string ownerType  = jsonData.ownertype;
            poll   pollMaster =
                EntityConnectionService.Poll.GetSingle(x => x.pollid.Equals(pollId) && x.ownerid.Equals(ownerId) && x.ownertype.Equals(ownerType));

            if (pollMaster == null)
            {
                return(Helper.GetResult(false, "0x0012"));
            }

            if (pollMaster.isipcheck == ("X"))
            {
                string ip        = jsonData.ip;
                guest  pollGuest = EntityConnectionService.Guest.GetSingle(x => x.ip == ip && x.ownerid == ownerId && x.ownertype == ownerType && x.pollid == pollId);
                if (pollGuest != null)
                {
                    return(Helper.GetResult(false, "0x0018"));
                }
            }

            if (pollMaster.isprivate == "X")
            {
                long   staffId = jsonData.staffid;
                string authKey = jsonData.authkey;

                staff loggedUser = DatabaseService.CheckStaffAuth(staffId, authKey, ownerId);
                if (loggedUser == null)
                {
                    return(Helper.GetResult(false, "0x0017"));
                }
            }
            pollMaster.viewcount++;
            EntityConnectionService.Poll.Update(pollMaster);

            List <question> questionList =
                EntityConnectionService.Question.GetList(
                    x =>
                    x.pollid.Equals(pollId) && x.ownerid.Equals(ownerId) && x.ownertype.Equals(ownerType)).ToList();

            PollModel poll = new PollModel();

            poll.PollId        = pollMaster.pollid;
            poll.IsPassword    = pollMaster.ispassword;
            poll.Password      = pollMaster.password;
            poll.PollTitle     = pollMaster.polltitle;
            poll.Questions     = new List <Question>();
            poll.Fields        = pollMaster.fielddata;
            poll.IsCookieCheck = pollMaster.iscookiecheck;
            poll.Active        = pollMaster.active;
            for (int i = 0; i < questionList.Count; i++)
            {
                Question localQuestion = new Question
                {
                    Content      = questionList[i].content,
                    QuestionId   = questionList[i].questionid,
                    QuestionType = questionList[i].questiontype,
                    Answers      = new List <Answer>()
                };

                List <answer> answerList =
                    EntityConnectionService.Answer.GetList(
                        x =>
                        x.pollid.Equals(pollId) && x.questionid.Equals(localQuestion.QuestionId) &&
                        x.ownerid.Equals(ownerId) && x.ownertype.Equals(ownerType)).ToList();

                for (int j = 0; j < answerList.Count; j++)
                {
                    Answer localAnswer = new Answer
                    {
                        AnswerId   = answerList[j].answerid,
                        Content    = answerList[j].content,
                        AnswerType = answerList[j].answertype
                    };
                    localQuestion.Answers.Add(localAnswer);
                }
                poll.Questions.Add(localQuestion);
            }

            return(Helper.GetResult(true, poll));
        }
Esempio n. 20
0
        public static AnalysePollData GetAnalizedPollDataModel(long ownerid, string ownerType, long pollId)
        {
            poll pollMaster =
                EntityConnectionService.Poll.GetSingle(x => x.pollid.Equals(pollId) && x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType));

            if (pollMaster == null)
            {
                return(null);
            }

            Stopwatch analyseStopwatch = new Stopwatch();

            analyseStopwatch.Start();

            List <question> questionList =
                EntityConnectionService.Question.GetList(
                    x =>
                    x.pollid.Equals(pollId) && x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType)).ToList();

            PollModel poll = new PollModel();

            poll.PollId    = pollMaster.pollid;
            poll.PollTitle = pollMaster.polltitle;
            poll.Questions = new List <Question>();
            poll.Fields    = pollMaster.fielddata;
            poll.Active    = pollMaster.active;
            for (int i = 0; i < questionList.Count; i++)
            {
                Question localQuestion = new Question
                {
                    Content      = questionList[i].content,
                    QuestionId   = questionList[i].questionid,
                    QuestionType = questionList[i].questiontype,
                    Answers      = new List <Answer>()
                };

                localQuestion.VoteCount =
                    EntityConnectionService.GuestAnswer.GetDataCount(
                        x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId) && x.questionid.Equals(localQuestion.QuestionId));

                List <answer> answerList =
                    EntityConnectionService.Answer.GetList(
                        x =>
                        x.pollid.Equals(pollId) && x.questionid.Equals(localQuestion.QuestionId) &&
                        x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType)).ToList();

                for (int j = 0; j < answerList.Count; j++)
                {
                    Answer localAnswer = new Answer
                    {
                        AnswerId   = answerList[j].answerid,
                        Content    = answerList[j].content,
                        AnswerType = answerList[j].answertype
                    };
                    localAnswer.VoteCount =
                        EntityConnectionService.GuestAnswer.GetDataCount(
                            x =>
                            x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.answerid.Equals(localAnswer.AnswerId) &&
                            x.questionid.Equals(localQuestion.QuestionId));
                    localQuestion.Answers.Add(localAnswer);
                }
                poll.Questions.Add(localQuestion);
            }

            AnalysePollData analysePoll = new AnalysePollData();

            analysePoll.GuestAnswers = new List <GuestAnswer>();
            var guestAnswerList = EntityConnectionService.GuestAnswer.GetList(
                x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId));

            for (int i = 0; i < guestAnswerList.Count; i++)
            {
                analysePoll.GuestAnswers.Add(new GuestAnswer()
                {
                    GuestId    = guestAnswerList[i].guestid,
                    AnswerId   = guestAnswerList[i].answerid,
                    QuestionId = guestAnswerList[i].questionid,
                });
            }
            analysePoll.Poll      = poll;
            analysePoll.GuestList =
                EntityConnectionService.Guest.GetDataPart(
                    x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId),
                    x => new { x.guestid, x.fielddata, x.crdat, x.crtim, x.complatesecond },
                    x => new { x.crdat, x.crtim }).ToList();

            int totalComplateSecond = 0;

            foreach (var guest in analysePoll.GuestList)
            {
                if (!string.IsNullOrEmpty(guest.complatesecond.ToString()))
                {
                    totalComplateSecond += int.Parse(guest.complatesecond.ToString());
                }
            }
            if (analysePoll.GuestList.Count > 0)
            {
                TimeSpan avarageTime = TimeSpan.FromSeconds(totalComplateSecond / analysePoll.GuestList.Count);
                analysePoll.AvarageComplateTime    = new DateTime(avarageTime.Ticks).ToStringHhmmss();
                analysePoll.AvarageComplateSeconds = (totalComplateSecond / analysePoll.GuestList.Count).ToString();
                analysePoll.TotalComplate          = analysePoll.GuestList.Count.ToString();
                analysePoll.TotalView       = pollMaster.viewcount.ToString();
                analysePoll.AnalyseDateTime = DateTime.Now.ToStringYyyyMMddHhmmss();
            }
            else
            {
                analysePoll.AvarageComplateTime    = "000000";
                analysePoll.AvarageComplateSeconds = "0";
                analysePoll.TotalComplate          = "0";
                analysePoll.TotalView       = "0";
                analysePoll.AnalyseDateTime = DateTime.Now.ToStringYyyyMMddHhmmss();
            }



            analyseStopwatch.Stop();
            analysePoll.AnalyseTime = string.Format("{0}:{1}:{2}.{3}", analyseStopwatch.Elapsed.Hours,
                                                    analyseStopwatch.Elapsed.Minutes, analyseStopwatch.Elapsed.Seconds,
                                                    analyseStopwatch.Elapsed.Milliseconds);

            Log.Info(string.Format("Analyse Time :{0}", analysePoll.AnalyseTime));
            return(analysePoll);
        }
Esempio n. 21
0
        public static string PollExportExcel(long ownerid, string ownerType, long pollId)
        {
            Log.Info("GetData Started");

            poll pollMaster = EntityConnectionService.Poll.GetSingle(
                x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId));

            if (pollMaster == null)
            {
                return(Helper.GetResult(false, "0x0012"));
            }

            IList <guest> guestList = EntityConnectionService.Guest.GetList(
                x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId));

            IList <guestanswer> guestAnswers = EntityConnectionService.GuestAnswer.GetList(
                x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId));

            IList <question> pollQuestions = EntityConnectionService.Question.GetList(
                x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId))
                                             .OrderBy(x => x.questionid)
                                             .ToList();

            IList <answer> pollAnswers = EntityConnectionService.Answer.GetList(
                x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId));

            Log.Info("GetData Ended");
            Log.Info("Export Started!");

            string base64Data;

            DataTable dataTable = new DataTable();                                                            //verileri kaydetmek icin datatable

            List <dynamic> fieldList = JsonConvert.DeserializeObject <List <dynamic> >(pollMaster.fielddata); //Bu anketin tum alanlarini parcala

            List <object> headerParams = new List <object>();                                                 //basliklar icin headerparameters

            Log.Info("Header Creating!");
            for (int i = 0; i < fieldList.Count; i++)                                     //tum alanlar icinde don ve kolonlari belirle
            {
                dataTable.Columns.Add(fieldList[i].FieldCode.ToString(), typeof(string)); //kolonlarin adlari
                headerParams.Add(fieldList[i].FieldTitle.ToString());                     //kolonlarin icerikleri
            }

            for (int i = 0; i < pollQuestions.Count; i++)                                      //tum sorular icinde don ve kolonlari belirle
            {
                dataTable.Columns.Add(pollQuestions[i].questionid.ToString(), typeof(string)); //kolonlarin adlari
                headerParams.Add(pollQuestions[i].content);                                    //kolonlarin icerikleri
            }
            dataTable.Rows.Add(headerParams.ToArray());                                        //basliklari tabloya ekle

            Log.Info("Header Created!");

            Log.Info("Guests Creating!");
            for (int i = 0; i < guestList.Count; i++)
            {
                long guestId = guestList[i].guestid; //anket yapilan kisinin idsi
                Log.Info(string.Format("Start:{0}", guestId));

                List <guestanswer> localGuestAnswers =
                    guestAnswers.Where(
                        x => x.guestid.Equals(guestId)).ToList();
                List <object> guestData = new List <object>();
                for (int j = 0; j < dataTable.Columns.Count; j++)
                {
                    if (j < fieldList.Count)
                    {
                        //field icin burasi
                        List <dynamic> guestFieldData = JsonConvert.DeserializeObject <List <dynamic> >(guestList[i].fielddata); //anket yapilan kisinin sadece alanlari
                        for (int k = 0; k < guestFieldData.Count; k++)                                                           //bu anketi yapan kullanicinin alanlarini almak icin don
                        {
                            if (dataTable.Columns[j].ColumnName == guestFieldData[k].FieldCode.ToString())                       //bu alanin kodu kolonun koduna esitse yani veri buraya gelmeli ise
                            {
                                guestData.Add(guestFieldData[k].FieldValue.ToString());                                          //bulunan veriyi anket yapilan kullanicinin verilerinin icine ekle.
                                break;                                                                                           //ilgili alan bulundugu icin donguden cikilabilir.
                            }
                        }
                    }
                    else
                    {
                        //soru icin burasi

                        localGuestAnswers =
                            localGuestAnswers.Where(x => x.questionid.ToString() == (dataTable.Columns[j].ColumnName)).ToList();
                        string cellData = string.Empty;

                        for (int k = 0; k < localGuestAnswers.Count; k++)
                        {
                            answer cellAnswer =
                                pollAnswers.FirstOrDefault(x => x.answerid.Equals(localGuestAnswers[k].answerid));
                            if (cellAnswer != null)
                            {
                                cellData += cellAnswer.content + ",";
                            }
                            guestAnswers.Remove(localGuestAnswers[k]);
                        }

                        cellData = cellData.Trim(',');
                        guestData.Add(cellData);
                    }
                }

                dataTable.Rows.Add(guestData.ToArray());//tum satirlari datatable a ekle

                Log.Info(string.Format("End:{0}", guestId));
            }
            Log.Info("Guests Created!");
            Log.Info("Ms Creating!");
            using (MemoryStream memoryStream = new MemoryStream())
            {
                IWorkbook       wb    = new XSSFWorkbook();
                ISheet          sheet = wb.CreateSheet("Sheet1");
                ICreationHelper cH    = wb.GetCreationHelper();

                var font = wb.CreateFont();
                font.FontHeightInPoints = 11;
                font.FontName           = "Calibri";
                font.Boldweight         = (short)NPOI.SS.UserModel.FontBoldWeight.Bold;

                for (int i = 0; i < dataTable.Rows.Count; i++)
                {
                    IRow row = sheet.CreateRow(i);
                    for (int j = 0; j < dataTable.Columns.Count; j++)
                    {
                        ICell cell = row.CreateCell(j);
                        if (i == 0)
                        {
                            cell.CellStyle.SetFont(font);
                        }
                        cell.SetCellValue(cH.CreateRichTextString(dataTable.Rows[i].ItemArray[j].ToString()));
                    }
                }
                wb.Write(memoryStream);
                base64Data = Convert.ToBase64String(memoryStream.ToArray());
            }

            Log.Info("Export Ended");

            return(Helper.GetResult(true, base64Data));
        }