public IHttpActionResult AddLesson(LessonModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var service = new LessonService();

                int id = service.Add(BindingManager.ToLessonEntity(model));
                if (id == 0)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResponseType.Error, Description = "Entity was not created."
                    }));
                }

                return(Ok(new ResponseModel()
                {
                    Result = ResponseType.Success
                }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(InternalServerError(ex));
            }
        }
        public ActionResult Add(LessonEditViewModel Lesson)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            LessonService.Add(Lesson);
            return(RedirectToAction("Lesson"));
        }
Пример #3
0
        // POST: api/lesson
        public HttpResponseMessage Post([FromBody] Lesson value)
        {
            HttpResponseMessage msg = new HttpResponseMessage(HttpStatusCode.Conflict);

            using (ILessonService ls = new LessonService(WebApiApplication.connection))
            {
                ls.Add(Mapper.Map <BLL.Objects.Lesson>(value));
                msg.StatusCode = HttpStatusCode.OK;
            }
            return(msg);
        }
Пример #4
0
        public ActionResult CreateTraining(TrainingModel t, LessonModel[] l, QuestionModel[] q, AnswerModel[] a)
        {
            Training lastTraining = new Training();

            lastTraining = ts.GetLastAdded();
            Lesson lastLesson = new Lesson();

            lastLesson = ls.GetLastAdded();
            Question lastQuestion = new Question();

            lastQuestion = qs.GetLastAdded();
            foreach (var itema in a)
            {
                Answer an = new Answer();
                an.questionId  = lastQuestion.questionId + itema.questionNumber;
                an.description = itema.description;
                if (itema.isTrue == 0)
                {
                    an.isTrue = true;
                }
                else
                {
                    an.isTrue = false;
                }

                an.editorId = 1;
                ans.Add(an);
            }

            // ADD QUESTIONS

            foreach (var itemq in q)
            {
                Question qu = new Question();
                qu.lessonId    = lastLesson.lessonId + itemq.lessonNumber;
                qu.title       = itemq.title;
                qu.description = itemq.description;
                qu.editorId    = 1;
                qu.dateAdded   = DateTime.Now;
                qs.Add(qu);
            }
            foreach (var item in l)
            {
                // ADD A LESSON
                Lesson le = new Lesson();
                le.trainingId    = lastTraining.trainingId + 1;
                le.title         = item.title;
                le.description   = item.description;
                le.estimatedTime = item.estimatedTime;
                le.dateAdded     = DateTime.Now;
                le.editorId      = 1;
                ls.Add(le);
            }


            //ADD A TRAINING SESSION
            Training tr = new Training();

            tr.title         = t.title;
            tr.description   = t.description;
            tr.estimatedTime = t.estimatedTime;
            tr.dateAdded     = DateTime.Now;
            tr.editorId      = 1;
            //tr.categoryId = 1;
            tr.difficultyValue       = t.difficultyValue;
            tr.difficultyDescription = t.difficultyDescription;
            ts.Add(tr);
            ts.Commit();
            ls.Commit();
            qs.Commit();
            ans.Commit();



            return(RedirectToAction("Training"));
        }