예제 #1
0
 public ActionResult Index(string searchString)
 {
     if (!String.IsNullOrEmpty(searchString))
     {
         SearchController s = new SearchController();
         return(s.SearchOnDatabase(searchString));
     }
     else
     {
         if (AccountController.CheckPermission("Survey-Index"))
         {
             System.Web.HttpContext.Current.Session["action"] = "Survey-Index";
             UpdateList();
             var user = AccountController.GetUser();
             if (user.RoleName == "User")
             {
                 return(View(listSurvey.Where(x => x.UserId == user.Id && x.IsDeleted == false)));
             }
             else
             {
                 return(View(listSurvey));
             }
         }
         else
         {
             return(RedirectToAction("Index", "Home"));
         }
     }
 }
예제 #2
0
 public ActionResult Create([Bind(Include = "Id,FromId,ToId,Message,IsRead,IsDeleted,ModifiedDate,ModifiedUserId,DeletionDate,DeletionUserId,CreatedDate,CreatedUserId")] NotificationViewModel notificationViewModel)
 {
     if (ModelState.IsValid)
     {
         UpdateList();
         var user = listUser.Where(x => x.RoleName == "User" && x.IsDeleted == false);
         foreach (var item in user)
         {
             notificationViewModel.Id     = Guid.NewGuid();
             notificationViewModel.FromId = AccountController.GetUser().Id;
             notificationViewModel.ToId   = item.Id;
             notificationViewModel.AddNotification(notificationViewModel);
         }
         return(RedirectToAction("Index"));
     }
     ViewBag.FromId = new SelectList(listUser, "Id", "Username", notificationViewModel.FromId);
     ViewBag.ToId   = new SelectList(listUser, "Id", "Username", notificationViewModel.ToId);
     return(View(notificationViewModel));
 }
예제 #3
0
        public ActionResult Create([Bind(Include = "Id,SurveyTypeId,Title,UserId,UserName,Description,SurveyType,IsBlock,IsDeleted,ModifiedDate,ModifiedUserId,DeletionDate,DeletionUserId,CreatedDate,CreatedUserId")] SurveyViewModel surveyViewModel, string CreateSurvey)
        {
            QuestionsController q = new QuestionsController();

            if (ModelState.IsValid)
            {
                if (CreateSurvey == "Create Survey")
                {
                    surveyViewModel.Id     = Guid.NewGuid();
                    surveyViewModel.UserId = AccountController.GetUser().Id;
                    surveyViewModel.AddSurvey(surveyViewModel);
                    AccountController.RememberSurveyId(surveyViewModel.Id);
                    UpdateList();
                    AccountController.RememberSurvey(listSurvey.Find(x => x.Id == surveyViewModel.Id));
                    AccountController.ClearCount();

                    ViewBag.SurveyTypeId = new SelectList(listSurveyType, "Id", "Type");
                    ViewBag.UserId       = new SelectList(listUser, "Id", "Username");

                    ViewBag.QuestionTypeId = new SelectList(q.GetQuestionType(), "Id", "Type");
                    return(View(surveyViewModel));
                }
                else if (CreateSurvey == "Edit Survey")
                {
                    SurveyViewModel s = AccountController.GetSurvey();
                    s.Title          = surveyViewModel.Title;
                    s.Description    = surveyViewModel.Description;
                    s.SurveyTypeId   = surveyViewModel.SurveyTypeId;
                    s.ModifiedUserId = AccountController.GetUser().Id;
                    TemporaryEdit(s);
                }
            }
            UpdateList();
            ViewBag.QuestionTypeId = new SelectList(q.GetQuestionType(), "Id", "Type");
            ViewBag.SurveyTypeId   = new SelectList(listSurveyType, "Id", "Type");
            ViewBag.UserId         = new SelectList(listUser, "Id", "Username");
            return(View(surveyViewModel));
        }
예제 #4
0
        public ActionResult Mailbox()
        {
            UpdateList();
            List <NotificationViewModel> n = new List <NotificationViewModel>();
            var notif = listNotification.Where(x => x.ReceiverDeleted == false && x.IsRead == false && x.ToId == AccountController.GetUser().Id);

            //listNotification.Reverse();
            foreach (var item in notif)
            {
                if (item.Message.Length >= 30)
                {
                    item.Message = item.Message.Substring(0, 30) + "...";
                }
                n.Add(item);
            }
            ViewBag.Count = n.Count;
            if (n.Count > 3)
            {
                return(PartialView(n.OrderBy(x => x.CreatedDate).Take(3)));
            }
            else
            {
                return(PartialView(n.OrderBy(x => x.CreatedDate)));
            }
        }
예제 #5
0
        public JsonResult SaveAnswers(string answer, string answers, string questionid, string ipaddress, string browser)
        {
            List <QuestionAnswerViewModel> q = AccountController.GetQuestionAnswer();
            RespondentViewModel            r = AccountController.GetRespondent();

            if (r == null)
            {
                r    = new RespondentViewModel();
                r.Id = Guid.NewGuid();
                if (AccountController.CheckUser())
                {
                    r.UserId       = AccountController.GetUser().Id;
                    r.IsRegistered = true;
                }
                r.IPAdress    = ipaddress;
                r.BrowserName = browser;
                r.SurveyId    = AccountController.GetSurveyId();
            }
            //q.Add(new QuestionViewModel{Id = new Guid(questionid)});

            //int i = r.Count - 1;
            if (r.Responses == null)
            {
                r.Responses = new List <ResponseViewModel>();
            }
            if (q == null)
            {
                q = new List <QuestionAnswerViewModel>();
            }
            if (answer != null)
            {
                QuestionAnswerViewModel qa = new QuestionAnswerViewModel
                {
                    Id         = Guid.NewGuid(),
                    QuestionId = new Guid(questionid),
                    Answer     = answer
                };
                q.Add(qa);
                AccountController.RememberQuestionAnswer(q);

                ResponseViewModel rs = new ResponseViewModel
                {
                    Id             = Guid.NewGuid(),
                    QuestionId     = new Guid(questionid),
                    ResponseAnswer = qa.Id,
                    RespondentId   = r.Id
                };
                r.Responses.Add(rs);
            }
            else if (answers != "")
            {
                string[] a = answers.Split(',');
                //UpdateList();
                //var type = listQuestion.Find(x=>x.Id==new Guid(questionid)).Type;
                //if (type == "Yes/No")
                //{
                //    answers = new List<string>();
                //}
                foreach (var item in a)
                {
                    if (item != "")
                    {
                        ResponseViewModel rs = new ResponseViewModel
                        {
                            Id             = Guid.NewGuid(),
                            QuestionId     = new Guid(questionid),
                            ResponseAnswer = new Guid(item),
                            RespondentId   = r.Id
                        };
                        r.Responses.Add(rs);
                    }
                }
            }
            AccountController.RememberRespondent(r);
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
예제 #6
0
        public ActionResult SearchOnDatabase(string searchString)
        {
            UserViewModel user = AccountController.GetUser();

            if (user.RoleName == "Admin")
            {
                var temp = db.Cities.Where(t => t.Name.Contains(searchString) && t.IsDeleted == false);
                if (temp != null)
                {
                    foreach (var item in temp)
                    {
                        listSearch.Add(new SearchViewModel
                        {
                            Id    = item.Id,
                            Name  = item.Name,
                            Table = "City",
                            Model = "Cities"
                        });
                    }
                }
                var temp2 = db.ImageTypes.Where(t => t.Type.Contains(searchString) && t.IsDeleted == false);
                if (temp2 != null)
                {
                    foreach (var item in temp2)
                    {
                        listSearch.Add(new SearchViewModel
                        {
                            Id    = item.Id,
                            Name  = item.Type,
                            Table = "Image Type",
                            Model = "ImageTypes"
                        });
                    }
                }
                var temp3 = db.Permissions.Where(t => t.Name.Contains(searchString) && t.IsDeleted == false);
                if (temp3 != null)
                {
                    foreach (var item in temp3)
                    {
                        listSearch.Add(new SearchViewModel
                        {
                            Id    = item.Id,
                            Name  = item.Name,
                            Table = "Permission",
                            Model = "Permissions"
                        });
                    }
                }
                var temp4 = db.QuestionTypes.Where(t => t.Type.Contains(searchString) && t.IsDeleted == false);
                if (temp4 != null)
                {
                    foreach (var item in temp4)
                    {
                        listSearch.Add(new SearchViewModel
                        {
                            Id    = item.Id,
                            Name  = item.Type,
                            Table = "Question Type",
                            Model = "QuestionTypes"
                        });
                    }
                }
                var temp5 = db.Roles.Where(t => t.Name.Contains(searchString) && t.IsDeleted == false);
                if (temp5 != null)
                {
                    foreach (var item in temp5)
                    {
                        listSearch.Add(new SearchViewModel
                        {
                            Id    = item.Id,
                            Name  = item.Name,
                            Table = "Role",
                            Model = "Roles"
                        });
                    }
                }
                var temp6 = db.SurveyTypes.Where(t => t.Type.Contains(searchString) && t.IsDeleted == false);
                if (temp6 != null)
                {
                    foreach (var item in temp6)
                    {
                        listSearch.Add(new SearchViewModel
                        {
                            Id    = item.Id,
                            Name  = item.Type,
                            Table = "Survey Type",
                            Model = "SurveyTypes"
                        });
                    }
                }
                var temp7 = db.Surveys.Where(t => t.Title.Contains(searchString) && t.IsDeleted == false);
                if (temp7 != null)
                {
                    foreach (var item in temp7)
                    {
                        listSearch.Add(new SearchViewModel
                        {
                            Id    = item.Id,
                            Name  = item.Title,
                            Table = "Survey",
                            Model = "Surveys"
                        });
                    }
                }
                var temp8 = db.Users.Where(t => t.Username.Contains(searchString) && t.IsDeleted == false);
                if (temp8 != null)
                {
                    foreach (var item in temp8)
                    {
                        listSearch.Add(new SearchViewModel
                        {
                            Id    = item.Id,
                            Name  = item.Username,
                            Table = "User",
                            Model = "Users"
                        });
                    }
                }
                var temp9 = db.Countries.Where(t => t.Name.Contains(searchString) && t.IsDeleted == false);

                if (temp9 != null)
                {
                    foreach (var item in temp9)
                    {
                        listSearch.Add(new SearchViewModel
                        {
                            Id    = item.Id,
                            Name  = item.Name,
                            Table = "Country",
                            Model = "Countries"
                        });
                    }
                }
            }
            else if (user.RoleName == "User")
            {
                var s = db.Surveys.Where(t => (t.Title.Contains(searchString) || t.Description.Contains(searchString)) && t.IsDeleted == false);
                if (s != null)
                {
                    foreach (var item in s)
                    {
                        listSearch.Add(new SearchViewModel
                        {
                            Id    = item.Id,
                            Name  = item.Title,
                            Table = "Survey",
                            Model = "Surveys"
                        });
                    }
                }
            }
            if (listSearch != null && listSearch.Count > 0)
            {
                System.Web.HttpContext.Current.Session["lists"] = listSearch;
                return(RedirectToAction("Index", "Search"));
            }
            else
            {
                return(RedirectToAction("NotFound", "Search"));
            }
        }