Ejemplo n.º 1
0
        /// <summary>
        /// Insertar Pregunta
        /// </summary>
        /// <param name="idQuestion"></param>
        /// <param name="idServiceDetail"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public Question InsertQuestion(Guid idQuestion, Guid idServiceDetail, string action)
        {
            Question returnQuestion = null;

            using (var transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    var questionCurent = _questionDao.GetOne(idQuestion);
                    int position       = -1;
                    var itemsUpdate    = new List <Question>();

                    switch (action)
                    {
                    case CService.LastQuestion:
                        position = -1;
                        break;

                    case CService.BeforeQuestion:
                        position    = questionCurent.Order;
                        itemsUpdate = _questionDao.GetQuestionBeforeOrder(questionCurent.IdServiceDetail,
                                                                          questionCurent.Order);
                        break;

                    case CService.AfterQuestion:
                        position    = questionCurent.Order + 1;
                        itemsUpdate = _questionDao.GetQuestionAfterOrder(questionCurent.IdServiceDetail,
                                                                         questionCurent.Order);
                        break;
                    }

                    foreach (var itemTemp in itemsUpdate)
                    {
                        itemTemp.Order = itemTemp.Order + 1;
                    }

                    returnQuestion = AddQuestion(idServiceDetail, position);

                    Context.Questions.Add(returnQuestion);
                    Context.SaveChanges();

                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                }
            }

            return(returnQuestion);
        }