Exemple #1
0
        /// <summary>
        /// Adds a customerQuestion to the database
        /// </summary>
        /// <param name="question">CustomerQuestion paramter</param>
        /// <returns>A bool</returns>
        public bool addCustomerQuestion(CustomerQuestion question)
        {
            try
            {
                var newQ = new CustomerQuestion()
                {
                    Question  = question.Question,
                    Downvotes = question.Downvotes,
                    Upvotes   = question.Upvotes,
                    Email     = question.Email,
                    Answer    = new Answer()
                    {
                        Answers = ""
                    },
                };


                _context.Add(newQ);
                _context.SaveChanges();

                return(true);
            }catch (Exception e)
            {
                //Exception should be logged
                Console.WriteLine(e);
                return(false);
            }
        }
        public IActionResult Post([FromBody] CustomerQuestion newQuestion)
        {
            if (ModelState.IsValid)
            {
                UnitOfWork unit = new UnitOfWork(context);

                unit.CustomerQuestion.Add(newQuestion);
                unit.Save();

                unit.Dispose();
                return(StatusCode(201));
            }

            return(StatusCode(400));
        }
Exemple #3
0
        public IActionResult Post([FromBody] CustomerQuestion question)
        {
            Console.WriteLine(ModelState);
            if (ModelState.IsValid)
            {
                var  db      = new FAQDB(_context);
                bool success = db.addCustomerQuestion(question);

                if (success)
                {
                    return(Ok());
                }
            }

            return(BadRequest("Something went wrong! Couldn't add the question"));
        }