示例#1
0
        public ActionResult deleteRequest(int id)
        {
            MessageViewModels response = new MessageViewModels();
            User u = userService.findById(id);

            if (u == null || u.Status == 1)
            {
                response.StatusCode = 2;
            }
            var poll       = u.UserAnswerPolls.ToList();
            var notiObject = u.NotificationObjects.ToList();

            foreach (var ntObj in notiObject)
            {
                var notiChange = ntObj.NotificationChanges.ToList();
                ntObj.NotificationChanges = null;
                foreach (var ntChange in notiChange)
                {
                    notificationService.DeleteNotiChangeById(ntChange.ID);
                }
                ntObj.User = null;
                var notiObj = notificationService.FindNotiObjectById(ntObj.ID);
                notificationService.DeleteNotiObject(notiObj);
                notiChange = null;
                notiObj    = null;
            }
            try
            {
                foreach (var p in poll)
                {
                    var answer = userAnswerPollService.FindById(u.Id, p.PollId);
                    answer.User   = null;
                    answer.Poll   = null;
                    answer.Answer = null;
                    if (null != answer)
                    {
                        userAnswerPollService.DeleteUserAnswer(answer);
                    }
                }
                poll       = null;
                notiObject = null;

                u.HouseId = null;
                u.RoleId  = SLIM_CONFIG.USER_ROLE_RESIDENT;
                u.Status  = SLIM_CONFIG.USER_STATUS_DELETE;
                userService.updateUser(u);
                response.Data = u.Id;
            }
            catch (Exception e1)
            {
                response.Data = u.Id;
                return(Json(response));
            }
            return(Json(response));
        }
示例#2
0
        public ActionResult DeleteSurvey(int PollId)
        {
            Poll obj = PollService.FindById(PollId);
            //List<Question> questions = questionService.FindByPollId(obj.Id);
            //foreach (var itemQuestion in questions)
            //{
            //    List<Answer> answers = answerService.FindByQuestionId(itemQuestion.Id);
            //    foreach (var itemAnswer in answers)
            //    {
            //        answerService.DeleteAnswer(itemAnswer);
            //    }
            //    questionService.DeleteQuestion(itemQuestion);
            //}
            List <UserAnswerPoll> listUserAnswerPolls = userAnswerService.GetListUserAnswerPollsByPollId(obj.Id);

            if (listUserAnswerPolls != null)
            {
                foreach (var item in listUserAnswerPolls)
                {
                    userAnswerService.DeleteUserAnswer(item);
                }
            }

            List <BlockPoll> listBlockPolls = BlockPollService.FindByPollId(obj.Id);

            if (listBlockPolls != null)
            {
                foreach (var item1 in listBlockPolls)
                {
                    BlockPollService.DeleteBlockPoll(item1);
                }
            }
            PollService.DeletePoll(obj);

            return(RedirectToAction("ListPoll"));
        }