Example #1
0
 public void DeleteBlockPoll(BlockPoll obj)
 {
     blockRepository.Delete(obj);
 }
Example #2
0
 public void UpdateBlockPoll(BlockPoll obj)
 {
     blockRepository.Update(obj);
 }
Example #3
0
        public ActionResult Surveys(SurveyViewModel model)
        {
            if (ModelState.IsValid)
            {
                //    string[] title = Request.Form.GetValues("Title");
                var      ti              = Request.QueryString["Title"];
                string[] listQuestion    = Request.Form.GetValues("question");
                string[] listAnwser      = Request.Form.GetValues("anwser1");
                string[] listCountAnwser = Request.Form.GetValues("count");

                string[] imagUrl  = Request.Form.GetValues("image_from_list");
                string[] member   = Request.Form.GetValues("people");
                string[] privacy  = Request.Form.GetValues("privacy");
                string[] priority = Request.Form.GetValues("priority");
                // string[] listMem = Request.Form.GetValues("count");
                //  string[] listCountAnwser = {"1", "2", "3","1","2","1","2","3","4"};
                List <string> listCountAnwsers = new List <string>(listCountAnwser);
                List <string> listQuestions    = new List <string>(listQuestion);
                List <string> listAnwsers      = new List <string>(listAnwser);

                // count number anwser of question
                List <int>            listCount        = new List <int>();
                List <List <string> > totalAnsertGroup = new List <List <string> >();
                for (int i = 0; i < (listCountAnwsers.Count) - 1; i++)
                {
                    if (Int32.Parse(listCountAnwsers[i]) > Int32.Parse(listCountAnwsers[i + 1]))
                    {
                        listCount.Add(Int32.Parse(listCountAnwsers[i]));
                    }
                }
                listCount.Add(Int32.Parse((listCountAnwsers[(listCountAnwsers.Count) - 1])));
                for (int i = 0; i < listCount.Count; i++)
                {
                    List <string> listAnwserGroup = new List <string>();
                    int           countAneser     = 0;
                    for (int j = 0; j < listAnwsers.Count; j++)
                    {
                        if (countAneser != listCount[i] && countAneser < listCount[i])
                        {
                            listAnwserGroup.Add(listAnwsers[j]);
                            countAneser++;
                            listAnwsers.Remove(listAnwsers[j]);
                            j = j - 1;
                        }
                    }
                    totalAnsertGroup.Add(listAnwserGroup);
                }
                Poll survey = new Poll();

                int number = totalAnsertGroup.Count;
                int ii     = 0;
                foreach (var content in listQuestions)
                {
                    if (ii < number)
                    {
                        survey.Description = model.Title;

                        //survey.CreateDate = (DateTime.Now);

                        survey.EndDate     = (model.EndDate);
                        survey.PublishDate = (model.PublishDate);
                        // int result = DateTime.Compare(survey.CreateDate.Value, survey.EndDate.Value);
                        int result1 = DateTime.Compare(survey.PublishDate.Value, survey.EndDate.Value);
                        //int result2 = DateTime.Compare(survey.CreateDate.Value, survey.PublishDate.Value);
                        //if (survey.CreateDate.ToString() == "")
                        //{
                        //    ModelState.AddModelError("StartDate", "Xin chon ngay hop ly.");
                        //}
                        //if ((result) < 0)
                        //{
                        //    ModelState.AddModelError("StartDate", "Xin chon ngay hop ly.");
                        //}
                        //else if ((result1) < 0)
                        //{
                        //    ModelState.AddModelError("StartDate", "Xin chon ngay hop ly.");
                        //}
                        //else if ((result2) < 0)
                        //{
                        //    ModelState.AddModelError("EndDate", "Xin chon ngay hop ly.");
                        //}
                        survey.Status = 1;

                        //   survey.Privacy = int.Parse(privacy[0]);
                        survey.Mode     = int.Parse(member[0]);
                        survey.Priority = int.Parse(priority[0]);
                        survey.ImageUrl = imagUrl[0];
                        survey.Question = content;
                        survey.Answer1  = listAnwser[0];
                        survey.Answer2  = listAnwser[1];
                        survey.Answer3  = listAnwser[2];
                        survey.Answer4  = listAnwser[3];
                        if (listAnwser.Length == 5)
                        {
                            survey.Answer5 = listAnwser[(listAnwser.Length) - 1];
                        }


                        PollService.AddPoll(survey);
                    }
                }
                int k = 0;
                // BlockPoll BlockPoll = new BlockPoll();

                string[] listBlock = Request.Form.GetValues("block");

                if (listBlock != null)
                {
                    List <string> listBlockrs = new List <string>(listBlock);
                    List <Block>  list        = new List <Block>();
                    foreach (var item in listBlockrs)
                    {
                        list.Add(blockService.FindBlockByName(item));
                    }
                    foreach (var obj in list)
                    {
                        BlockPoll BlockPoll = new BlockPoll();
                        BlockPoll.BlockId = obj.Id;
                        BlockPoll.PollId  = survey.Id;
                        BlockPollService.AddBlockPoll(BlockPoll);
                    }
                    int p = 0;
                    // List<User> listuUsers = userService.GetAllResident();
                    List <User> listAllUsers = userService.GetAllUsers();
                    User        curUser      = userService.FindById(int.Parse(User.Identity.GetUserId()));
                    foreach (var u in listAllUsers)
                    {
                        if (u.HouseId != null)
                        {
                            int kk = 0;
                            if (list.ElementAt(p).Id == BlockPollService.FindBlockIdByHouseId(u.HouseId.Value).BlockId&&
                                p < list.Count)
                            {
                                kk++;
                            }
                            if (kk == 1)
                            {
                                Console.WriteLine(u);
                                //notificationService.addNotification("", u.Id, SLIM_CONFIG.NOTIC_VERB_POLL, 2, null);
                                notificationService.addNotification(SLIM_CONFIG.NOTIC_TARGET_OBJECT_POLL, u.Id,
                                                                    SLIM_CONFIG.NOTIC_VERB_CREATE, curUser.Id, null);
                            }
                        }
                        else if (survey.Mode == 1)
                        {
                            int kk = 0;

                            if (u.HouseId.HasValue)
                            {
                                if (list.ElementAt(p).Id ==
                                    BlockPollService.FindBlockIdByHouseId(u.HouseId.Value).BlockId&& p < list.Count)
                                {
                                    kk++;
                                }
                            }
                            if (kk == 1 || kk == 0)
                            {
                                Console.WriteLine(u);
                                //notificationService.addNotification("", u.Id, SLIM_CONFIG.NOTIC_VERB_POLL, 2, null);
                                notificationService.addNotification(SLIM_CONFIG.NOTIC_TARGET_OBJECT_POLL, u.Id,
                                                                    SLIM_CONFIG.NOTIC_VERB_CREATE, curUser.Id, null);
                            }
                        }
                        else if (survey.Mode == 2 && SLIM_CONFIG.USER_ROLE_HOUSEHOLDER == u.RoleId)
                        {
                            int kk = 0;

                            if (u.HouseId.HasValue)
                            {
                                if (list.ElementAt(p).Id ==
                                    BlockPollService.FindBlockIdByHouseId(u.HouseId.Value).BlockId&& p < list.Count)
                                {
                                    kk++;
                                }
                            }
                            if (kk == 1 || kk == 0)
                            {
                                Console.WriteLine(u);
                                //notificationService.addNotification("", u.Id, SLIM_CONFIG.NOTIC_VERB_POLL, 2, null);
                                notificationService.addNotification(SLIM_CONFIG.NOTIC_TARGET_OBJECT_POLL, u.Id,
                                                                    SLIM_CONFIG.NOTIC_VERB_CREATE, curUser.Id, null);
                            }
                        }
                        else if ((survey.Mode == 3 && SLIM_CONFIG.USER_ROLE_HOUSEHOLDER == u.RoleId) ||
                                 (survey.Mode == 3 && SLIM_CONFIG.USER_ROLE_RESIDENT == u.RoleId))
                        {
                            int kk = 0;

                            if (u.HouseId.HasValue)
                            {
                                if (list.ElementAt(p).Id ==
                                    BlockPollService.FindBlockIdByHouseId(u.HouseId.Value).BlockId&& p < list.Count)
                                {
                                    kk++;
                                }
                            }
                            if (kk == 1 || kk == 0)
                            {
                                Console.WriteLine(u);
                                //notificationService.addNotification("", u.Id, SLIM_CONFIG.NOTIC_VERB_POLL, 2, null);
                                notificationService.addNotification(SLIM_CONFIG.NOTIC_TARGET_OBJECT_POLL, u.Id,
                                                                    SLIM_CONFIG.NOTIC_VERB_CREATE, curUser.Id, null);
                            }
                        }
                    }
                }
                else
                {
                    // List<User> listuUsers = userService.GetAllResident();
                    List <User> listAllUsers = userService.GetAllUsers();
                    User        curUser      = userService.FindById(int.Parse(User.Identity.GetUserId()));
                    foreach (var u in listAllUsers)
                    {
                        if (survey.Mode == 1)
                        {
                            Console.WriteLine(u);
                            //notificationService.addNotification("", u.Id, SLIM_CONFIG.NOTIC_VERB_POLL, 2, null);
                            notificationService.addNotification(SLIM_CONFIG.NOTIC_TARGET_OBJECT_POLL, u.Id, SLIM_CONFIG.NOTIC_VERB_CREATE, curUser.Id, null);
                        }
                        else if (survey.Mode == 2 && SLIM_CONFIG.USER_ROLE_HOUSEHOLDER == u.RoleId)
                        {
                            notificationService.addNotification(SLIM_CONFIG.NOTIC_TARGET_OBJECT_POLL, u.Id, SLIM_CONFIG.NOTIC_VERB_CREATE, curUser.Id, null);
                        }
                        else if ((survey.Mode == 3 && SLIM_CONFIG.USER_ROLE_HOUSEHOLDER == u.RoleId) ||
                                 (survey.Mode == 3 && SLIM_CONFIG.USER_ROLE_RESIDENT == u.RoleId))
                        {
                            notificationService.addNotification(SLIM_CONFIG.NOTIC_TARGET_OBJECT_POLL, u.Id, SLIM_CONFIG.NOTIC_VERB_CREATE, curUser.Id, null);
                        }
                    }
                }
            }
            ViewBag.Alert = "Tạo survey thành công!!";
            //  return View("Survey");
            return(RedirectToAction("ListPoll", new { alerts = "Tạo survey thành công!!" }));
        }
Example #4
0
 public void AddBlockPoll(BlockPoll obj)
 {
     blockRepository.Add(obj);
 }
Example #5
0
        public ActionResult UpdateSurvey(SurveyViewModel model)
        {
            string[]      listQuestion     = Request.Form.GetValues("question");
            string[]      listAnwser       = Request.Form.GetValues("anwser1");
            string[]      listCountAnwser  = Request.Form.GetValues("count");
            List <string> listCountAnwsers = new List <string>(listCountAnwser);
            List <string> listQuestions    = new List <string>(listQuestion);
            List <string> listAnwsers      = new List <string>(listAnwser);

            string[]   member    = Request.Form.GetValues("people");
            string[]   privacy   = Request.Form.GetValues("privacy");
            string[]   priority  = Request.Form.GetValues("priority");
            string[]   status    = Request.Form.GetValues("status");
            List <int> listCount = new List <int>();

            List <List <string> > totalAnsertGroup = new List <List <string> >();

            for (int i = 0; i < (listCountAnwsers.Count) - 1; i++)
            {
                if (Int32.Parse(listCountAnwsers[i]) > Int32.Parse(listCountAnwsers[i + 1]))
                {
                    listCount.Add(Int32.Parse(listCountAnwsers[i]));
                }
            }
            listCount.Add(Int32.Parse((listCountAnwsers[(listCountAnwsers.Count) - 1])));
            for (int i = 0; i < listCount.Count; i++)
            {
                List <string> listAnwserGroup = new List <string>();
                int           countAneser     = 0;
                for (int j = 0; j < listAnwsers.Count; j++)
                {
                    if (countAneser != listCount[i] && countAneser < listCount[i])
                    {
                        listAnwserGroup.Add(listAnwsers[j]);
                        countAneser++;
                        listAnwsers.Remove(listAnwsers[j]);
                        j = j - 1;
                    }
                }
                totalAnsertGroup.Add(listAnwserGroup);
            }
            //
            int  a   = 0;
            Poll obj = PollService.FindById(model.Id);

            if (listAnwser.Length == 2)
            {
                obj.Answer1 = listAnwser[0];
                obj.Answer2 = listAnwser[1];
            }
            else if (listAnwser.Length == 3)
            {
                obj.Answer1 = listAnwser[0];
                obj.Answer2 = listAnwser[1];
                obj.Answer3 = listAnwser[2];
            }
            else if (listAnwser.Length == 4)
            {
                obj.Answer1 = listAnwser[0];
                obj.Answer2 = listAnwser[1];
                obj.Answer3 = listAnwser[2];
                obj.Answer4 = listAnwser[3];
            }
            else if (listAnwser.Length == 5)
            {
                obj.Answer1 = listAnwser[0];
                obj.Answer2 = listAnwser[1];
                obj.Answer3 = listAnwser[2];
                obj.Answer4 = listAnwser[3];
                if (listAnwser.Length == 5)
                {
                    obj.Answer5 = listAnwser[(listAnwser.Length) - 1];
                }
            }



            obj.Description = model.Title;
            obj.Question    = listQuestion[0];

            obj.EndDate     = (model.EndDate);
            obj.PublishDate = (model.PublishDate);
            obj.Status      = int.Parse(status[0]);
            obj.Mode        = int.Parse(member[0]);

            obj.Priority = int.Parse(priority[0]);
            PollService.UpdatePoll(obj);
            string[] listBlock = Request.Form.GetValues("block");
            if (listBlock != null)
            {
                List <string> listBlockrs = new List <string>(listBlock);

                List <BlockPoll> listBlockPollsDb = BlockPollService.FindByPollId(model.Id);

                List <int> listEditBlock = new List <int>();
                List <int> listLoad      = new List <int>();

                foreach (var VARIABLE in listBlockrs)
                {
                    listEditBlock.Add(blockService.FindBlockByName(VARIABLE).Id);
                }
                foreach (var aa in listBlockPollsDb)
                {
                    listLoad.Add(aa.BlockId);
                }
                if (listEditBlock.Count < listLoad.Count)
                {
                    List <int> list3 = listLoad.Except(listEditBlock).ToList();
                    // number of check less than before, delete
                    List <int> list5 = listEditBlock.Intersect(listLoad).ToList();
                    if (list5.Count == 0)
                    {
                        // uncheck A, check B
                        foreach (var object1 in listLoad)
                        {
                            BlockPoll BlockPoll = BlockPollService.FIndBlockPollByBlockIdPollId(object1, model.Id);
                            BlockPollService.DeleteBlockPoll(BlockPoll);
                        }
                        foreach (var obj1 in listEditBlock)
                        {
                            BlockPoll blockPoll = new BlockPoll();
                            blockPoll.BlockId = obj1;
                            blockPoll.PollId  = model.Id;
                            BlockPollService.AddBlockPoll(blockPoll);
                        }
                    }
                    else if (list5.Count != 0)
                    {
                        foreach (var object1 in list3)
                        {
                            BlockPoll BlockPoll = BlockPollService.FIndBlockPollByBlockIdPollId(object1, model.Id);
                            BlockPollService.DeleteBlockPoll(BlockPoll);
                        }
                    }
                }
                else if (listEditBlock.Count >= listLoad.Count)
                {
                    List <int> list4 = listEditBlock.Except(listLoad).ToList();
                    // number of check more than before,
                    List <int> list5 = listEditBlock.Intersect(listLoad).ToList();
                    if (list5.Count == 0)
                    {
                        // uncheck A, check B
                        foreach (var object1 in listLoad)
                        {
                            BlockPoll BlockPoll = BlockPollService.FIndBlockPollByBlockIdPollId(object1, model.Id);
                            BlockPollService.DeleteBlockPoll(BlockPoll);
                        }
                        foreach (var obj1 in listEditBlock)
                        {
                            BlockPoll blockPoll = new BlockPoll();
                            blockPoll.BlockId = obj1;
                            blockPoll.PollId  = model.Id;
                            BlockPollService.AddBlockPoll(blockPoll);
                        }
                    }
                    else if (list5.Count != 0)
                    {
                        foreach (var obj1 in list4)
                        {
                            BlockPoll blockPoll = new BlockPoll();
                            blockPoll.BlockId = obj1;
                            blockPoll.PollId  = model.Id;
                            BlockPollService.AddBlockPoll(blockPoll);
                        }
                    }
                }
            }
            else
            {
                List <BlockPoll> listBlockPollsDb = BlockPollService.FindByPollId(model.Id);


                List <int> listLoad = new List <int>();


                foreach (var aa in listBlockPollsDb)
                {
                    listLoad.Add(aa.BlockId);
                }

                List <int> list3 = listLoad.ToList();
                // number of check less than before, delete
                foreach (var object1 in list3)
                {
                    BlockPoll BlockPoll = BlockPollService.FIndBlockPollByBlockIdPollId(object1, model.Id);
                    BlockPollService.DeleteBlockPoll(BlockPoll);
                }
            }

            List <int> aaa = new List <int>();

            aaa.Add(1);
            aaa.Add(2);
            List <int> aaa1 = new List <int>();

            aaa1.Add(2);
            aaa1.Add(3);
            aaa1.Add(4);
            List <int> asd = aaa1.Except(aaa).ToList();

            return(RedirectToAction("DetailSurvey", new { PollId = obj.Id, alert = "Cập nhật thành công!" }));
        }