コード例 #1
0
        public IActionResult Post(PostSurveyDTO postSurveyDTO)
        {
            Survey surveySuccessfullyCreated = _surveyService.CreateSurvey(postSurveyDTO.surveyQuestions, postSurveyDTO.surveyAnswers, postSurveyDTO.appointmentId);

            if (surveySuccessfullyCreated == null)
            {
                return(BadRequest("Failed to post survey"));
            }
            return(Ok("Survey posted successfully"));
        }
コード例 #2
0
        public async Task <IActionResult> CreateSurvey([FromBody] Model.Input.Survey survey)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.ToString()));
            }

            var result = await _surveyService.CreateSurvey(survey);

            return(Ok(result));
        }
コード例 #3
0
 public ActionResult <IEnumerable <SurveyDto> > Get()
 {
     using (IScope scope = tracer.BuildSpan("creating survey").StartActive(finishSpanOnDispose: true))
     {
         List <SurveyDto> survey = new List <SurveyDto>();
         for (int i = 0; i < random.Next(1, 10); i++)
         {
             var newSurvey = service.CreateSurvey();
             survey.Add(CreateDto(newSurvey));
         }
         if (!survey.Any())
         {
             return(NoContent());
         }
         return(Ok(survey));
     }
 }
コード例 #4
0
        public ActionResult Create(string surveyName, SurveyParameter[] surveyParameters)
        {
            try
            {
                db.CreateSurvey(surveyName, surveyParameters);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                return(new JsonResult()
                {
                    Data = new { Status = "Error", Message = ex.Message }
                });
            }

            return(new JsonResult()
            {
                Data = new { Status = "Ok" }
            });
        }
コード例 #5
0
        public void CreateSurvey()
        {
            Assert.IsNotNull(surveyService);

            var surveyInputModel = new Model.Input.Survey
            {
                Title         = SurveyTitle,
                Description   = SurveyDescription,
                StartDateTime = SurveyStartDateTime,
                EndDateTime   = SurveyEndDateTime
            };

            var surveyOutputModel = surveyService.CreateSurvey(surveyInputModel).Result;

            Assert.IsNotNull(surveyOutputModel);
            Assert.IsTrue(surveyOutputModel.Id > 0);
            Assert.AreEqual(SurveyTitle, surveyOutputModel.Title);
            Assert.AreEqual(SurveyDescription, surveyOutputModel.Description);
            Assert.AreEqual(SurveyStartDateTime, surveyOutputModel.StartDateTime);
            Assert.AreEqual(SurveyEndDateTime, surveyOutputModel.EndDateTime);
        }
コード例 #6
0
        public ActionResult CreateSurvey(FormCollection fc, int id = 0)
        {
            string responseMessage = "";


            int?     DaysOpen;
            bool?    Active;
            string   Name = "";
            int      QuestionGroupId;
            DateTime?OpenDate;

            int?   StudentStatusId = null, programId = null, termId = null, StudentgroupId = null;
            string sessionId = "";

            string[][] selectedStudents = null;
            if (fc["id"] != null)
            {
                id = Convert.ToInt32(fc["id"]);
            }
            else
            {
                id = 0;
            }

            // Populating Survey Table Parameters
            #region Survey Table Params
            Name            = fc["txtSurveyName"];
            QuestionGroupId = Convert.ToInt32(fc["ddlSurveyQuestionGroup"]);
            if (string.IsNullOrEmpty(fc["txtSurveyStartDate"]))
            {
                OpenDate = null;
            }
            else
            {
                OpenDate = DateTime.Parse(fc["txtSurveyStartDate"]).Date;
            }

            if (string.IsNullOrEmpty(fc["DaysToOpen"]))
            {
                DaysOpen = null;
            }
            else
            {
                DaysOpen = Convert.ToInt32(fc["DaysToOpen"]);
            }

            if (string.IsNullOrEmpty(fc.Get("chkBoxActive")))
            {
                Active = false;
            }
            else
            {
                Active = Convert.ToBoolean(fc.Get("chkBoxActive").Contains("true"));
            }
            #endregion

            //Populating Survey Student Selection Params
            #region Survey Students
            //will come from Student Selection Survey Page
            //Checking whether come back from Student Selection Survey or not
            if (
                Session["StudentStatusId"] != null &
                Session["ProgramsId"] != null &
                Session["TermsId"] != null &
                Session["StudentGroupsId"] != null &
                Session["SessionsId"] != null)
            {
                StudentStatusId  = Convert.ToInt32(Session["StudentStatusId"]);
                programId        = Convert.ToInt32(Session["ProgramsId"]);
                termId           = Convert.ToInt32(Session["TermsId"]);
                StudentgroupId   = Convert.ToInt32(Session["StudentGroupsId"]);
                sessionId        = Session["SessionsId"] as string;
                selectedStudents = (string[][])Session["selectedStudents"];
            }
            #endregion

            try
            {
                if (!string.IsNullOrEmpty(Name))
                {
                    if (id != 0)
                    {
                        Survey newSurvey = new Survey()
                        {
                            SurveyId        = id,
                            Name            = Name,
                            QuestionGroupId = QuestionGroupId,
                            OpenDate        = OpenDate,
                            DaysOpen        = DaysOpen,
                            Active          = Active.HasValue ? Active.Value : false
                        };
                        if (selectedStudents != null)
                        {
                            newSurvey.Students = new List <SurveyStudent>()
                            {
                                new SurveyStudent()
                            };
                            foreach (string[] student in selectedStudents)
                            {
                                newSurvey.Students.Add(new SurveyStudent()
                                {
                                    StudentNo    = Convert.ToInt32(student[0]),
                                    EnrollmentId = Convert.ToInt32(student[3])
                                });
                            }
                        }
                        service.UpdateSurvey(newSurvey, StudentStatusId, programId, termId, StudentgroupId, sessionId);
                    }
                    else
                    {
                        Survey newSurvey = new Survey()
                        {
                            Name            = Name,
                            QuestionGroupId = QuestionGroupId,
                            OpenDate        = OpenDate,
                            DaysOpen        = DaysOpen,
                            Active          = Active.HasValue ? Active.Value : false,
                            Students        = new List <SurveyStudent>()
                            {
                                new SurveyStudent()
                            }
                        };
                        if (selectedStudents != null)
                        {
                            newSurvey.Students = new List <SurveyStudent>()
                            {
                                new SurveyStudent()
                            };
                            foreach (string[] student in selectedStudents)
                            {
                                newSurvey.Students.Add(new SurveyStudent()
                                {
                                    StudentNo    = Convert.ToInt32(student[0]),
                                    EnrollmentId = Convert.ToInt32(student[3])
                                });
                            }
                        }

                        service.CreateSurvey(newSurvey, StudentStatusId, programId, termId, StudentgroupId, sessionId);
                    }


                    return(RedirectToAction("MasterSurvey"));
                }
                else
                {
                    responseMessage = "Survey Name should not be Empty";
                    prepareCreateSurveyViewData(name: Name, questionGroupId: QuestionGroupId, openDate: OpenDate, daysOpen: DaysOpen, active: Active, responseMessage: responseMessage);
                    return(View());
                }
            }
            catch (Exception error)
            {
                if (null != error.InnerException)
                {
                    responseMessage = error.InnerException.Message;
                }
                else
                {
                    responseMessage = error.Message;
                }

                prepareCreateSurveyViewData(name: Name, questionGroupId: QuestionGroupId, openDate: OpenDate, daysOpen: DaysOpen, active: Active, responseMessage: responseMessage);
                return(View());
            }
            finally
            {
                Session.Remove("StudentStatusId");
                Session.Remove("ProgramsId");
                Session.Remove("TermsId");
                Session.Remove("StudentGroupsId");
                Session.Remove("SessionsId");
                Session.Remove("selectedStudents");
                Session.Remove("name");
                Session.Remove("groupId");
                Session.Remove("startDate");
                Session.Remove("daysToOpen");
                Session.Remove("Active");
                Session.Remove("id");
            }
        }