Exemplo n.º 1
0
        public void AddForm_Test()
        {
            try
            {
                List <QuestionDTO> q = new List <QuestionDTO>();
                List <AnswerDTO>   a = new List <AnswerDTO>();
                a.Add(new AnswerDTO {
                    Answer = "a", AnswerID = 20
                });

                q.Add(new QuestionDTO {
                    QuestionID = 1, Question = "why?", Answers = a
                });

                FormDetailDTO f = new FormDetailDTO()
                {
                    Id        = 4,
                    Username  = "******",
                    Deadline  = "3",
                    Category  = "category1",
                    Title     = "Title1",
                    State     = "open",
                    NrVotes   = 100,
                    Questions = q
                };

                _formLogic.AddForm(f);
            }
            catch (Exception)
            {
                Assert.Pass();
            }
            Assert.Fail();
        }
Exemplo n.º 2
0
 public FormDetailDTO GetContentForm(int id)
 {
     try
     {
         FormDetailDTO formDTO = bl.FormLogic.GetContentForm(id);
         return(formDTO);
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 3
0
 public bool AddForm(FormDetailDTO formDTO)
 {
     try
     {
         bl.FormLogic.AddForm(formDTO);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        public bool AddForm(FormDetailDTO formDTO)
        {
            try
            {
                bl.FormLogic.AddForm(formDTO);
                return true;

            }
            catch(Exception ex)
            {
                return false;
            }
        }
Exemplo n.º 5
0
        public FormDetailDTO GetContentForm(int id)
        {
            FormDetailDTO formDTO = new FormDetailDTO();
            Form          f       = _dataAccess.FormRepository.FindFirstBy(form => form.FormID == id);

            formDTO.Title       = f.Title;
            formDTO.CreatedDate = f.CreatedDate.ToString();
            formDTO.Deadline    = f.Deadline.ToString();
            formDTO.State       = f.State;
            formDTO.Category    = GetCategory(f.CategoryID);
            formDTO.Questions   = GetAllQuestionFromForm(id);
            formDTO.Username    = GetUsername(f.UserID);
            formDTO.Id          = f.FormID;
            return(formDTO);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adaugare sondaj
        /// </summary>
        /// <param name="formDTO"></param>
        public void AddForm(FormDetailDTO formDTO)
        {
            CultureInfo provider = CultureInfo.InvariantCulture;

            // string format = "ddd MMM d HH:mm:ss GMT";
            if (string.IsNullOrWhiteSpace(formDTO.Category) || string.IsNullOrWhiteSpace(formDTO.Username) || formDTO.Questions.Capacity <= 1)
            {
                throw new MissingMemberException("Values cannot be null");
            }

            Form form = new Form()
            {
                CreatedDate = DateTime.Now, Deadline = DateTime.Now.AddDays(7 * Int32.Parse(formDTO.Deadline)), State = formDTO.State, Title = formDTO.Title
            };
            Question q;
            Answer   a;

            form.CategoryID = GetCategoryID(formDTO.Category);
            form.UserID     = GetUserID(formDTO.Username);
            form.NrVotes    = 0;

            _dataAccess.FormRepository.Add(form);

            // Adaugare intrebare
            int formID = GetFormID(form.Title, form.UserID, form.CreatedDate); //Preiau id-ul formului
            int questionID;

            foreach (QuestionDTO questionDTO in formDTO.Questions)
            {
                q         = new Question();
                q.FormID  = form.FormID;
                q.Content = questionDTO.Question;

                _dataAccess.QuestionRepository.Add(q);

                // Adaugare raspuns
                questionID = GetQuestionID(q.Content, formID);
                foreach (AnswerDTO answerDTO in questionDTO.Answers)
                {
                    a            = new Answer();
                    a.Content    = answerDTO.Answer;
                    a.NrVotes    = 0;
                    a.QuestionID = questionID;

                    _dataAccess.AnswerRepository.Add(a);
                }
            }
        }
Exemplo n.º 7
0
        public HttpResponseMessage Post([FromBody] FormDetailDTO formDTO)
        {
            HttpResponseMessage responseMessage;

            bool response = formModel.AddForm(formDTO);

            if (response)
            {
                responseMessage = Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                responseMessage = Request.CreateResponse(HttpStatusCode.ExpectationFailed);
            }

            return(responseMessage);
        }
Exemplo n.º 8
0
        public HttpResponseMessage GetForm(int id)
        {
            HttpResponseMessage responseMessage;
            JSendMessage        json;
            FormDetailDTO       formContent = formModel.GetContentForm(id);

            if (formContent != null)
            {
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, formContent);
            }
            else
            {
                json            = new JSendMessage("fail", "Poll not found");
                responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json);
            }

            return(responseMessage);
        }
Exemplo n.º 9
0
        public void AddForm(FormDetailDTO formDTO)
        {
            //add form
            CultureInfo provider = CultureInfo.InvariantCulture;
            // string format = "ddd MMM d HH:mm:ss GMT";

            Form form = new Form()
            {
                CreatedDate = DateTime.Now, Deadline = DateTime.Now.AddDays(7 * Int32.Parse(formDTO.Deadline)), State = formDTO.State, Title = formDTO.Title
            };
            Question q;
            Answer   a;

            form.CategoryID = GetCategoryID(formDTO.Category);
            form.UserID     = GetUserID(formDTO.Username);

            _dataAccess.FormRepository.Add(form);

            //add questions
            int formID = GetFormID(form.Title, form.UserID, form.CreatedDate); //preiau id-ul formului
            int questionID;

            foreach (QuestionDTO questionDTO in formDTO.Questions)
            {
                q         = new Question();
                q.FormID  = form.FormID;
                q.Content = questionDTO.Question;
                q.NrVotes = 0;

                _dataAccess.QuestionRepository.Add(q);

                //add answer
                questionID = GetQuestionID(q.Content, formID);
                foreach (AnswerDTO answerDTO in questionDTO.Answers)
                {
                    a            = new Answer();
                    a.Content    = answerDTO.Answer;
                    a.NrVotes    = 0;
                    a.QuestionID = questionID;

                    _dataAccess.AnswerRepository.Add(a);
                }
            }
        }
Exemplo n.º 10
0
        public HttpResponseMessage Post([FromBody] FormDetailDTO formDTO)
        {
            HttpResponseMessage responseMessage;
            JSendMessage        json;

            bool response = formModel.AddForm(formDTO);

            if (response)
            {
                json            = new JSendMessage("success", "Form successfully added");
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);
            }
            else
            {
                json            = new JSendMessage("fail", "Something bad happened");
                responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, json);
            }

            return(responseMessage);
        }
Exemplo n.º 11
0
        public void AddForm(FormDetailDTO formDTO)
        {
            //add form
            CultureInfo provider = CultureInfo.InvariantCulture;
            // string format = "ddd MMM d HH:mm:ss GMT";

            Form form = new Form() { CreatedDate = DateTime.Now, Deadline = DateTime.Now.AddDays(7 * Int32.Parse(formDTO.Deadline)), State = formDTO.State, Title = formDTO.Title };
            Question q;
            Answer a;
            form.CategoryID = GetCategoryID(formDTO.Category);
            form.UserID = GetUserID(formDTO.Username);

            _dataAccess.FormRepository.Add(form);

            //add questions
            int formID = GetFormID(form.Title, form.UserID, form.CreatedDate); //preiau id-ul formului
            int questionID;
            foreach (QuestionDTO questionDTO in formDTO.Questions)
            {
                q = new Question();
                q.FormID = form.FormID;
                q.Content = questionDTO.Question;
                q.NrVotes = 0;

                _dataAccess.QuestionRepository.Add(q);

                //add answer
                questionID = GetQuestionID(q.Content, formID);
                foreach (AnswerDTO answerDTO in questionDTO.Answers)
                {
                    a = new Answer();
                    a.Content = answerDTO.Answer;
                    a.NrVotes = 0;
                    a.QuestionID = questionID;

                    _dataAccess.AnswerRepository.Add(a);
                }
            }
        }
Exemplo n.º 12
0
        public FormDetailDTO GetContentForm(int id)
        {
            FormDetailDTO formDTO = new FormDetailDTO();
            Form f = _dataAccess.FormRepository.FindFirstBy(form => form.FormID == id);

            formDTO.Title = f.Title;
            formDTO.CreatedDate = f.CreatedDate.ToString();
            formDTO.Deadline = f.Deadline.ToString();
            formDTO.State = f.State;
            formDTO.Category = GetCategory(f.CategoryID);
            formDTO.Questions = GetAllQuestionFromForm(id);
            formDTO.Username = GetUsername(f.UserID);
            formDTO.Id = f.FormID;
            return formDTO;
        }