Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] AdditionalQuestion model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var qId = await additionalQuestionRepository.AddAdditionalQuestion(model);

                    if (qId > 0)
                    {
                        return(Ok(qId));
                    }
                    else
                    {
                        return(NotFound(Message.MessageSomethingWentWrong));
                    }
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }

            return(BadRequest());
        }
        public async Task UpdateAdditionalQuestion(AdditionalQuestion model)
        {
            if (db != null)
            {
                //Delete that Question
                db.AdditionalQuestions.Update(model);

                //Commit the transaction
                await db.SaveChangesAsync();
            }
        }
        public async Task <int> AddAdditionalQuestion(AdditionalQuestion model)
        {
            if (db != null)
            {
                await db.AdditionalQuestions.AddAsync(model);

                await db.SaveChangesAsync();

                return(model.QuestionId);
            }

            return(0);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Put([FromBody] AdditionalQuestion model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // model.Qid = id;
                    await additionalQuestionRepository.UpdateAdditionalQuestion(model);

                    return(Ok(Message.UpdateSuccess));
                }
                catch (Exception ex)
                {
                    if (ex.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException")
                    {
                        return(NotFound());
                    }

                    return(BadRequest());
                }
            }

            return(BadRequest());
        }