public ActionResult Take(Int64 id, PollTakeFormModel model) { Poll poll = GetSession.Get <Poll>(id); if (poll != null && poll.Id == CurrentPollId) { try { Guid sessionId = Guid.NewGuid(); PollTaking pollTaking = new PollTaking() { Poll = poll, Employee = Portal.Helpers.EmployeesHelper.GetCurrentEmployee(), Department_id = CurrentPollDepartmentId.HasValue ? CurrentPollDepartmentId.Value : 0, Manager = CurrentPollManagerId.HasValue ? GetSession.Get <Employee>(CurrentPollManagerId.Value) : null, SessionId = sessionId }; GetSession.Save(pollTaking); Regex regex = new Regex(@"\[[0-9]+\]", RegexOptions.IgnoreCase); foreach (string key in Request.Form.AllKeys) { MatchCollection matches = regex.Matches(key); if (matches.Count > 0) { char[] charsToTrim = { '[', ']' }; long itemId = Convert.ToInt64(matches[0].Value.Trim(charsToTrim));; string value = this.Request.Form[key]; if (!String.IsNullOrWhiteSpace(value)) { PollItem item = GetSession.Get <PollItem>(itemId); EmployeePollItem employeePollItem = GetSession.QueryOver <EmployeePollItem>() .Where(epi => epi.Employee.Id == Portal.Helpers.EmployeesHelper.GetCurrentEmployee().Id&& epi.PollItem.Id == item.Id) .Take(1) .SingleOrDefault(); if (employeePollItem == null || (poll.AnonymousUser != null && poll.AnonymousUser.Id == EmployeesHelper.GetCurrentEmployee().Id)) { employeePollItem = GetSession.QueryOver <EmployeePollItem>() .Where(epi => epi.Employee.Id == Portal.Helpers.EmployeesHelper.GetCurrentEmployee().Id&& epi.PollItem.Id == item.Id && epi.SessionId == sessionId) .Take(1) .SingleOrDefault(); if (employeePollItem == null) { employeePollItem = new EmployeePollItem() { Employee = Portal.Helpers.EmployeesHelper.GetCurrentEmployee(), PollItem = item }; } } employeePollItem.PollTaking = pollTaking; // Irrelevant question if (key.ToLower().Contains("irrelevant")) { if (value.Equals("on", StringComparison.InvariantCultureIgnoreCase)) { employeePollItem.AnswerValue = -1; } } else { switch (item.Type) { case QuestionType.Open: employeePollItem.AnswerText = value; break; case QuestionType.Range: employeePollItem.AnswerValue = Convert.ToInt32(Convert.ToDecimal(value)); break; case QuestionType.Multiple: employeePollItem.AnswerValue = Convert.ToInt32(Convert.ToDecimal(value)); switch (employeePollItem.AnswerValue) { case 1: employeePollItem.Option1Count = 1; employeePollItem.Option2Count = 0; employeePollItem.Option3Count = 0; employeePollItem.Option4Count = 0; employeePollItem.Option5Count = 0; employeePollItem.Option6Count = 0; break; case 2: employeePollItem.Option1Count = 0; employeePollItem.Option2Count = 1; employeePollItem.Option3Count = 0; employeePollItem.Option4Count = 0; employeePollItem.Option5Count = 0; employeePollItem.Option6Count = 0; break; case 3: employeePollItem.Option1Count = 0; employeePollItem.Option2Count = 0; employeePollItem.Option3Count = 1; employeePollItem.Option4Count = 0; employeePollItem.Option5Count = 0; employeePollItem.Option6Count = 0; break; case 4: employeePollItem.Option1Count = 0; employeePollItem.Option2Count = 0; employeePollItem.Option3Count = 0; employeePollItem.Option4Count = 1; employeePollItem.Option5Count = 0; employeePollItem.Option6Count = 0; break; case 5: employeePollItem.Option1Count = 0; employeePollItem.Option2Count = 0; employeePollItem.Option3Count = 0; employeePollItem.Option4Count = 0; employeePollItem.Option5Count = 1; employeePollItem.Option6Count = 0; break; case 6: employeePollItem.Option1Count = 0; employeePollItem.Option2Count = 0; employeePollItem.Option3Count = 0; employeePollItem.Option4Count = 0; employeePollItem.Option5Count = 0; employeePollItem.Option6Count = 1; break; } break; } } employeePollItem.SessionId = sessionId; GetSession.Save(employeePollItem); } } } } catch { } Session["Poll_Id"] = null; Session["Poll_Department_Id"] = null; Session["Poll_Manager_Id"] = null; Session["Poll_LCID"] = null; return(View("TakeEnd", new PollTakeEndFormModel() { Poll = poll, IsRightToLeft = CurrentPollLCID.HasValue ? CultureHelper.IsRightToLeft(CurrentPollLCID.Value) : true })); } else { return(RedirectToAction("Index")); } }
public ActionResult TakeOptions(long id) { Poll item = GetSession.Get <Poll>(id); if (item != null) { if (item.AnonymousUser != null && item.AnonymousUser.Id == EmployeesHelper.GetCurrentEmployee().Id) { PollTakeOptionsFormModel model = new PollTakeOptionsFormModel() { Poll = item, IsRightToLeft = CurrentPollLCID.HasValue ? CultureHelper.IsRightToLeft(CurrentPollLCID.Value) : true }; // Cultures model.Cultures = new List <SelectListItem>(); IList <Poll> objects = GetSession.QueryOver <Poll>() .Where(x => x.Id == id || (x.Object != null && x.Object.Id == id)) .List(); foreach (Poll pollObject in objects) { model.Cultures.Add(new SelectListItem() { Value = pollObject.LCID.ToString(), Text = CultureHelper.GetNativeName(pollObject.LCID) }); } // Departments model.Departments = new List <SelectListItem>(); IList <Department> departments = GetSession.QueryOver <Department>().List(); foreach (Department department in departments) { model.Departments.Add(new SelectListItem() { Value = department.Id.ToString(), Text = department.Name }); } // Managers model.Managers = new List <SelectListItem>(); IList <Employee> managers = GetSession.QueryOver <Employee>() .Where(x => x.Manager == null) .List(); foreach (Employee manager in managers) { model.Managers.Add(new SelectListItem() { Value = manager.Id.ToString(), Text = manager.FullName }); } return(View("TakeOptions", model)); } else { CurrentPollId = item.Id; if (EmployeesHelper.GetCurrentEmployee().Department != null) { CurrentPollDepartmentId = EmployeesHelper.GetCurrentEmployee().Department.Id; } if (EmployeesHelper.GetCurrentEmployee().Manager != null) { CurrentPollManagerId = EmployeesHelper.GetCurrentEmployee().Manager.Id; } if (item.LCID > 0) { CurrentPollLCID = item.LCID; } return(RedirectToAction("TakeIntro", new { Id = CurrentPollId })); } } else { return(RedirectToAction("Take", new { Id = id })); } }
public ActionResult Take(Int64 id) { Poll item = GetSession.Get <Poll>(id); if (item != null) { bool answered = item.PollItems.Any(pi => pi.EmployeePollItems.Any(epi => epi.Employee.Id == Portal.Helpers.EmployeesHelper.GetCurrentEmployee().Id)); if (answered && !item.UserEditable && !(item.AnonymousUser != null && item.AnonymousUser.Id == EmployeesHelper.GetCurrentEmployee().Id)) { item.ReadOnly = true; } if (this.CurrentPollId == id) { return(View(new PollTakeFormModel() { Poll = item, IsRightToLeft = CurrentPollLCID.HasValue ? CultureHelper.IsRightToLeft(CurrentPollLCID.Value) : true })); } else { return(RedirectToAction("TakeOptions", new { Id = id })); } } else { return(RedirectToAction("Index")); } }