Exemplo n.º 1
0
        public async Task <IHttpActionResult> isDuplicateNameUpdate(Models.EvaluationQuestionModel model)
        {
            Boolean result = false;

            var nowEvaluation = _db.Evaluations.Where(p => p.id == model.id).FirstOrDefault();

            if (nowEvaluation == null || nowEvaluation.evaluationName == model.evaluationName)
            {
                result = true;
            }

            return(Json(new { result = result }));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> update(Models.EvaluationQuestionModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { error = true, message = Models.ErrorMessage.getErrorMessage(ModelState) }));
            }
            Boolean result = true;

            try
            {
                System.Web.HttpContext.Current.Application.Lock();

                var eval = _db.Evaluations.Where(p => p.id == model.id).FirstOrDefault();
                eval.evaluationName = model.evaluationName;
                eval.description    = model.description;

                _db.SaveChanges();

                var questions = from q in _db.Questions where q.evaluationID == eval.id select q;
                foreach (var ques in questions)
                {
                    //var choice = from ch in _db.Choice where ch.questionID == ques.id select ch;
                    //foreach (var choiceDelete in choice)
                    //{
                    //    _db.Choice.Remove(choiceDelete);
                    //}
                    _db.Questions.Remove(ques);
                }

                _db.SaveChanges();

                foreach (var q in model.questions)
                {
                    DAL.Question quest = new DAL.Question();
                    quest.question1    = q.value;
                    quest.evaluationID = model.id;

                    _db.Questions.Add(quest);
                    _db.SaveChanges();

                    //if (q.choices != null)
                    //{
                    //    List<DAL.Choice> chList = new List<DAL.Choice>();
                    //    foreach (var ch in q.choices)
                    //    {
                    //        DAL.Question ques = _db.Question.Where(p => p.question1 == q.value && p.evaluationID == model.id).FirstOrDefault();
                    //        DAL.Choice choice = new DAL.Choice();
                    //        choice.choiceName = ch.value;
                    //        choice.questionID = ques.id;
                    //        chList.Add(choice);
                    //    }

                    //    _db.Choice.AddRange(chList);
                    //    _db.SaveChanges();
                    //}
                }
                System.Web.HttpContext.Current.Application.UnLock();
            }
            catch (Exception e)
            {
                result = false;
            }

            return(Json(new { result = result }));
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> create(Models.EvaluationQuestionModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { error = true, message = Models.ErrorMessage.getErrorMessage(ModelState) }));
            }
            Boolean result = true;

            try
            {
                System.Web.HttpContext.Current.Application.Lock();

                Evaluation eval = new Evaluation();
                eval.evaluationName = model.evaluationName;
                eval.description    = model.description;

                _db.Evaluations.Add(eval);
                int isSave = _db.SaveChanges();
                if (isSave == 1)
                {
                    Evaluation e = _db.Evaluations.Where(p => p.evaluationName == model.evaluationName).FirstOrDefault();
                    List <UserTypeInEvaluation> utList = new List <UserTypeInEvaluation>();
                    foreach (var uts in model.UserTypes)
                    {
                        var ut = _db.UserTypes.Where(p => p.UserTypeName == uts.userTypeName).FirstOrDefault();
                        UserTypeInEvaluation usertype = new UserTypeInEvaluation();
                        usertype.userTypeid   = ut.UserTypeId;
                        usertype.evaluationid = e.id;
                        utList.Add(usertype);
                    }
                    _db.UserTypeInEvaluations.AddRange(utList);
                    _db.SaveChanges();

                    foreach (var q in model.questions)
                    {
                        DAL.Question quest = new DAL.Question();
                        quest.question1    = q.value;
                        quest.evaluationID = e.id;

                        _db.Questions.Add(quest);
                        _db.SaveChanges();

                        if (q.choices != null)
                        {
                            List <DAL.Choice> chList = new List <DAL.Choice>();
                            foreach (var ch in q.choices)
                            {
                                DAL.Question ques   = _db.Questions.Where(p => p.question1 == q.value && p.evaluationID == e.id).FirstOrDefault();
                                DAL.Choice   choice = new DAL.Choice();
                                choice.choiceName = ch.value;
                                choice.questionID = ques.id;
                                chList.Add(choice);
                            }

                            _db.Choices.AddRange(chList);
                            _db.SaveChanges();
                        }
                    }
                }
                System.Web.HttpContext.Current.Application.UnLock();
            }
            catch (Exception e)
            {
                return(Json(e.Message));
            }

            return(Json(new { result = result }));
        }