public ActionResult DeleteConfirmed(int id) { Models.Survey survey = db.Surveys .Where(p => p.SurveyID == id) .Include(q => q.Questions).Include(q => q.Questions.Select(o => o.QuestionOptions)) .SingleOrDefault(); foreach (var item in survey.Questions.ToList()) { db.Questions.Remove(item); } db.Surveys.Remove(survey); try { db.SaveChanges(); } catch (Exception) { db = new SurveyEntities(); var disableSurvey = db.Surveys.Find(survey.SurveyID); if (!disableSurvey.Status.Value) { disableSurvey.Status = true; } else { disableSurvey.Status = false; } db.Entry(disableSurvey).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (ModelState.IsValid) { curentUserId = User.Identity.Name; var survey = new Models.Survey { ApplicationUserId = curentUserId, Answer1 = Input.Answer1, Answer2 = Input.Answer2, Answer3 = Input.Answer3, Answer4 = Input.Answer4, Answer5 = Input.Answer5, Answer6 = Input.Answer6, Answer7 = Input.Answer7 }; _context.ApplicationUsers.Where(u => u.Email == survey.ApplicationUserId).FirstOrDefault().Survey = survey; _context.ApplicationUsers.Where(u => u.Email == survey.ApplicationUserId).FirstOrDefault().Completed = true; _context.Surveys.Add(survey); } await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public Task <Models.Survey> Map(Data.Entities.Survey survey) { var surveyModel = new Models.Survey() { Id = survey.Id, Name = survey.Name, Questions = survey.SurveyQuestions.Select(sq => new Question() { Id = sq.Question.Id, Body = sq.Question.Body, MinimumValueAccepted = sq.Question.MinimumValueAccepted, Order = sq.Question.Order, Title = sq.Question.Title, Answers = sq.Question.QuestionAnswers.Select(qa => new Answer() { Id = qa.Answer.Id, Body = qa.Answer.Body, Value = qa.Answer.Value } ).ToList() }).ToList() }; return(Task.FromResult(surveyModel)); }
public ActionResult Create(Models.Survey survey) { _collection.InsertOne(survey); var list = GetAllSurveys(); return(View("Index", list)); }
private Models.Survey ConvertToSurvey(OqtaneSurvey objOqtaneSurvey) { if (objOqtaneSurvey == null) { return(new Models.Survey()); } // Create new Object Models.Survey objAddSurvey = new Models.Survey(); objAddSurvey.SurveyId = objOqtaneSurvey.SurveyId; objAddSurvey.ModuleId = objOqtaneSurvey.ModuleId; objAddSurvey.SurveyName = objOqtaneSurvey.SurveyName; objAddSurvey.CreatedBy = objOqtaneSurvey.CreatedBy; objAddSurvey.CreatedOn = objOqtaneSurvey.CreatedOn; objAddSurvey.ModifiedBy = objOqtaneSurvey.ModifiedBy; objAddSurvey.ModifiedOn = objOqtaneSurvey.ModifiedOn; if (objOqtaneSurvey.UserId != null) { objAddSurvey.UserId = objOqtaneSurvey.UserId.Value; } // Create new Collection objAddSurvey.SurveyItem = new List <SurveyItem>(); foreach (OqtaneSurveyItem objOqtaneSurveyItem in objOqtaneSurvey.OqtaneSurveyItem) { // Create new Object Models.SurveyItem objAddSurveyItem = new SurveyItem(); objAddSurveyItem.Id = objOqtaneSurveyItem.Id; objAddSurveyItem.ItemLabel = objOqtaneSurveyItem.ItemLabel; objAddSurveyItem.ItemType = objOqtaneSurveyItem.ItemType; objAddSurveyItem.ItemValue = objOqtaneSurveyItem.ItemValue; objAddSurveyItem.Position = objOqtaneSurveyItem.Position; objAddSurveyItem.Required = objOqtaneSurveyItem.Required; objAddSurveyItem.SurveyChoiceId = objOqtaneSurveyItem.SurveyChoiceId; // Create new Collection objAddSurveyItem.SurveyItemOption = new List <SurveyItemOption>(); foreach (OqtaneSurveyItemOption objOqtaneSurveyItemOption in objOqtaneSurveyItem.OqtaneSurveyItemOption) { // Create new Object Models.SurveyItemOption objAddSurveyItemOption = new SurveyItemOption(); objAddSurveyItemOption.Id = objOqtaneSurveyItemOption.Id; objAddSurveyItemOption.OptionLabel = objOqtaneSurveyItemOption.OptionLabel; // Add to Collection objAddSurveyItem.SurveyItemOption.Add(objAddSurveyItemOption); } // Add to Collection objAddSurvey.SurveyItem.Add(objAddSurveyItem); } return(objAddSurvey); }
public Models.Survey Put(int id, [FromBody] Models.Survey Survey) { if (ModelState.IsValid && Survey.ModuleId == _entityId) { Survey = ConvertToSurvey(_SurveyRepository.UpdateSurvey(Survey)); _logger.Log(LogLevel.Information, this, LogFunction.Update, "Survey Updated {Survey}", Survey); } return(Survey); }
public ActionResult Create(Models.Survey survey) { if (ModelState.IsValid) { if (Request.Form["Template"] != null) { var model = new Models.Survey(); model.EndDate = survey.EndDate; model.SurveyTitle = survey.SurveyTitle; model.TimeLimit = survey.TimeLimit; //int userID = db.Users.Where(t => t.UserEmailID.Equals(User.Identity.Name)).FirstOrDefault().UserID; model.UserID = survey.UserID; foreach (var item in db.Questions.Where(t => t.SurveyID == survey.SurveyID).ToList()) { Question q = new Question(); q.QuestionIndex = item.QuestionIndex; q.QuestionText = item.QuestionText; q.OptionCount = item.OptionCount; q.QuestionTypeID = item.QuestionTypeID; q.SurveyID = model.SurveyID; foreach (var itm in db.QuestionOptions.Where(o => o.QuestionID == item.QuestionID).ToList()) { QuestionOption qo = new QuestionOption(); qo.IsSurveyLogicText = itm.IsSurveyLogicText; qo.QuestionID = q.QuestionID; qo.QuestionOptionText = itm.QuestionOptionText; qo.SurveyLogicText = itm.SurveyLogicText; q.QuestionOptions.Add(qo); } model.Questions.Add(q); } db.Surveys.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } if (survey.SurveyID == 0) { db.Surveys.Add(survey); } else { db.Entry(survey).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserID = new SelectList(db.Users, "UserID", "UserEmailID", survey.UserID); return(View(survey)); }
public SurveyDetailsViewModel() { SaveCommand = new Command(() => { var newSurvey = new Models.Survey() { Name = this.Name, FavoriteFood = this.FavoriteFood }; MessagingCenter.Send(this, "SaveSurvey", newSurvey); }); }
public ActionResult SurveyResponse(int responseID) { var alreadyFilled = db.ResponseAnswers.Where(t => t.SurveyResponseID == responseID).Any(); if (!alreadyFilled) { ViewBag.ResponseID = responseID; var response = db.SurveyResponses.Find(responseID); Models.Survey survey = db.Surveys.Find(response.SurveyID); return(View(survey)); } return(RedirectToAction("SurveyList")); }
public Models.Survey Get(int id) { var objSurvey = _SurveyRepository.GetSurvey(id); Models.Survey Survey = ConvertToSurvey(objSurvey); if (Survey != null && Survey.ModuleId != _entityId) { Survey = null; } return(Survey); }
// GET: Surveys/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.Survey survey = db.Surveys.Find(id); if (survey == null) { return(HttpNotFound()); } return(View(survey)); }
public IActionResult Result(string Name, string Locations, string Languages, string Comments) { Models.Survey info = new Models.Survey(Name, Locations, Languages, Comments); TryValidateModel(info); if (ModelState.IsValid) { return(View("result", info)); } else { return(View("index")); } }
public IActionResult Result(string firstname, string message, string location, string language) { Models.Survey info = new Models.Survey(firstname, language, location, message); TryValidateModel(info); if (ModelState.IsValid) { return(View("result", info)); } else { return(View("index")); } }
public Models.Survey Post([FromBody] Models.Survey Survey) { if (ModelState.IsValid && Survey.ModuleId == _entityId) { // Get User var User = _users.GetUser(this.User.Identity.Name); // Add User to Survey object Survey.UserId = User.UserId; Survey = ConvertToSurvey(_SurveyRepository.CreateSurvey(Survey)); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Survey Added {Survey}", Survey); } return(Survey); }
// Utility #region private IEnumerable<Models.Survey> ConvertToSurveys(List<OqtaneSurvey> colOqtaneSurveys) private IEnumerable <Models.Survey> ConvertToSurveys(List <OqtaneSurvey> colOqtaneSurveys) { List <Models.Survey> colSurveyCollection = new List <Models.Survey>(); foreach (var objOqtaneSurvey in colOqtaneSurveys) { // Convert to Survey Models.Survey objAddSurvey = ConvertToSurvey(objOqtaneSurvey); // Add to Collection colSurveyCollection.Add(objAddSurvey); } return(colSurveyCollection); }
internal static Client.Models.Survey ToSurvey(this Models.Survey survey) { if (survey == null) { throw new ArgumentNullException(nameof(survey)); } return(new Client.Models.Survey() { CreatedOn = survey.CreatedOn, Questions = survey.Questions.Select(q => q.ToQuestion()).ToList(), SlugName = survey.SlugName, Title = survey.Title }); }
public void Post([FromBody] Models.Survey Survey) { if (ModelState.IsValid && Survey.ModuleId == _entityId) { // Get User var User = _users.GetUser(this.User.Identity.Name); // Add User to Survey object Survey.UserId = User.UserId; bool boolResult = _SurveyRepository.CreateSurveyAnswers(Survey); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Survey Answers Added {Survey}", Survey); } }
public async Task GetSurveyReturnsTitle() { string slugName = "slug-name"; var surveyModel = new Models.Survey { Title = "title" }; var mock = new Mock <IAzureBlobContainer <Models.Survey> >(); mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable(); var target = new SurveyManagementService(null, null, (containerName) => mock.Object); var survey = await target.GetSurveyAsync(slugName); Assert.AreEqual("title", survey.Title); }
public async Task GetSurveyByTenantAndSlugNameReturnsCreatedOn() { string slugName = "slug-name"; var expectedDate = new DateTime(2000, 1, 1); var surveyModel = new Models.Survey { CreatedOn = expectedDate }; var mock = new Mock <IAzureBlobContainer <Models.Survey> >(); mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable(); var target = new SurveyManagementService(null, null, (containerName) => mock.Object); var survey = await target.GetSurveyAsync(slugName); Assert.AreEqual(expectedDate, survey.CreatedOn); }
public async Task <IActionResult> UpdateAsync(Guid id, Models.Survey survey) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var isExistingSurvey = await _surveyManagementService.UpdateExistingSurvey(id, survey); if (!isExistingSurvey) { _logger.Warning("UpdateAsync - Survey id {id} not found", id); return(NotFound()); } return(Ok()); }
public async Task GetSurveyFiltersBySlugName() { string slugName = "slug-name"; var mock = new Mock <IAzureBlobContainer <Models.Survey> >(); var surveyModel = new Models.Survey { SlugName = slugName }; mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable(); var target = new SurveyManagementService(null, null, (containerName) => mock.Object); var survey = await target.GetSurveyAsync(slugName); Assert.IsNotNull(survey); mock.Verify(); Assert.AreEqual(surveyModel.SlugName, survey.SlugName); }
public async Task GetSurveyReturnsWithQuestionsFilteredBySlugName() { string slugName = "slug-name"; var mock = new Mock <IAzureBlobContainer <Models.Survey> >(); var question = new Models.Question { Type = Enum.GetName(typeof(QuestionType), QuestionType.SimpleText) }; var questions = new[] { question }; var surveyModel = new Models.Survey { Questions = questions }; mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable(); var target = new SurveyManagementService(null, null, (containerName) => mock.Object); var survey = await target.GetSurveyAsync(slugName); Assert.AreEqual(1, survey.Questions.Count); }
public OqtaneSurvey UpdateSurvey(Models.Survey objExistingSurvey) { try { var ExistingSurvey = _db.OqtaneSurvey .Where(x => x.SurveyId == objExistingSurvey.SurveyId) .FirstOrDefault(); ExistingSurvey.SurveyName = objExistingSurvey.SurveyName; _db.SaveChanges(); return(ExistingSurvey); } catch { DetachAllEntities(); throw; } }
public void Delete(int id) { var objSurvey = _SurveyRepository.GetSurvey(id); Models.Survey Survey = ConvertToSurvey(objSurvey); if (Survey != null && Survey.ModuleId == _entityId) { // Delete all Survey Items if (Survey.SurveyItem != null) { foreach (var item in Survey.SurveyItem) { bool boolDeleteSurveyItemResult = _SurveyRepository.DeleteSurveyItem(item.Id); if (boolDeleteSurveyItemResult) { _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Survey Item Deleted {item.Id}", item.Id); } else { _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Error: Survey Item *NOT* Deleted {item.Id}", item.Id); } } } bool boolResult = _SurveyRepository.DeleteSurvey(id); if (boolResult) { _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Survey Deleted {id}", id); } else { _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Error: Survey *NOT* Deleted {id}", id); } } }
public OqtaneSurvey CreateSurvey(Models.Survey NewSurvey) { try { OqtaneSurvey objSurvey = new OqtaneSurvey(); objSurvey.SurveyId = 0; objSurvey.ModuleId = NewSurvey.ModuleId; objSurvey.SurveyName = NewSurvey.SurveyName; objSurvey.UserId = NewSurvey.UserId; objSurvey.CreatedOn = DateTime.Now; _db.OqtaneSurvey.Add(objSurvey); _db.SaveChanges(); return(objSurvey); } catch { DetachAllEntities(); throw; } }
public void Post([FromBody] Models.Survey Survey) { if (ModelState.IsValid && Survey.ModuleId == _entityId) { // Get User if (this.User.Identity.IsAuthenticated) { var User = _users.GetUser(this.User.Identity.Name); // Add User to Survey object Survey.UserId = User.UserId; } else { // The AnonymousCookie was passed by the Client Survey.UserId = null; } bool boolResult = _SurveyRepository.CreateSurveyAnswers(Survey); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Survey Answers Added {Survey}", Survey); } }
// GET: Surveys/Create public ActionResult Create(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.Survey survey = db.Surveys.Find(id); if (survey == null) { survey = new Models.Survey(); survey.EndDate = DateTime.Now; ViewBag.isTemplate = true; } else { ViewBag.isTemplate = survey.UserID.HasValue; } int userID = db.Users.Where(t => t.UserEmailID.Equals(User.Identity.Name)).FirstOrDefault().UserID; survey.UserID = userID; return(View(survey)); }
// Survey Answers #region public bool CreateSurveyAnswers(Models.Survey paramDTOSurvey) public bool CreateSurveyAnswers(Models.Survey paramDTOSurvey) { try { List <SurveyAnswer> SurveyAnswers = new List <SurveyAnswer>(); foreach (var SurveyItem in paramDTOSurvey.SurveyItem) { // Delete possible existing answer List <OqtaneSurveyAnswer> ExistingAnswers; if (paramDTOSurvey.UserId != null) { ExistingAnswers = _db.OqtaneSurveyAnswer .Where(x => x.SurveyItemId == SurveyItem.Id) .Where(x => x.UserId == paramDTOSurvey.UserId) .ToList(); } else { ExistingAnswers = _db.OqtaneSurveyAnswer .Where(x => x.SurveyItemId == SurveyItem.Id) .Where(x => x.AnonymousCookie == paramDTOSurvey.AnonymousCookie) .ToList(); } if (ExistingAnswers != null) { _db.OqtaneSurveyAnswer.RemoveRange(ExistingAnswers); _db.SaveChanges(); } // Save Answer if (SurveyItem.ItemType != "Multi-Select Dropdown") { OqtaneSurveyAnswer NewSurveyAnswer = new OqtaneSurveyAnswer(); NewSurveyAnswer.AnswerValue = SurveyItem.AnswerValueString; if (SurveyItem.AnswerValueDateTime != null) { NewSurveyAnswer.AnswerValueDateTime = Convert.ToDateTime(SurveyItem.AnswerValueDateTime); } NewSurveyAnswer.SurveyItemId = SurveyItem.Id; if (paramDTOSurvey.UserId != null) { NewSurveyAnswer.UserId = paramDTOSurvey.UserId; } else { NewSurveyAnswer.AnonymousCookie = paramDTOSurvey.AnonymousCookie; } _db.OqtaneSurveyAnswer.Add(NewSurveyAnswer); _db.SaveChanges(); } if (SurveyItem.AnswerValueList != null) { foreach (var item in SurveyItem.AnswerValueList) { OqtaneSurveyAnswer NewSurveyAnswerValueList = new OqtaneSurveyAnswer(); NewSurveyAnswerValueList.AnswerValue = item; NewSurveyAnswerValueList.SurveyItemId = SurveyItem.Id; if (paramDTOSurvey.UserId != null) { NewSurveyAnswerValueList.UserId = paramDTOSurvey.UserId; } else { NewSurveyAnswerValueList.AnonymousCookie = paramDTOSurvey.AnonymousCookie; } _db.OqtaneSurveyAnswer.Add(NewSurveyAnswerValueList); _db.SaveChanges(); } } } return(true); } catch { DetachAllEntities(); throw; } }
public async Task <Models.Survey> UpdateSurveyAsync(Models.Survey Survey) { return(await PutJsonAsync <Models.Survey>(CreateAuthorizationPolicyUrl($"{Apiurl}/{Survey.ModuleId}", Survey.ModuleId), Survey)); }
public async Task CreateSurveyAnswersAsync(Models.Survey Survey) { await PostJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}", Survey.ModuleId), Survey); }