Example #1
0
        private void SubmitHomework(Text textForHomework, Teacher currentTeacher, Guid currentTeacherId,
                                    Guid currentTextId, DateTime?submissionDate, string homeworkTitle, string homeworkDescription)
        {
            var questions = _fileManager.ParseQuestions(Server.MapPath("~/TemporaryFiles/Homeworks"), currentTeacherId,
                                                        currentTextId);

            if (questions == null || questions.Count == 0)
            {
                TempData["msg"] = "<script>alert('יש להוסיף שאלות לשיעורי הבית');</script>";
                return;
            }
            if (submissionDate == null)
            {
                TempData["msg"] = "<script>alert('לא הוכנס תאריך הגשה לשיעורי הבית');</script>";
                return;
            }

            var homework = new Homework()
            {
                Text        = textForHomework,
                Text_Id     = currentTextId,
                Questions   = questions,
                Deadline    = (DateTime)submissionDate,
                Created_By  = currentTeacher,
                Teacher_Id  = currentTeacherId,
                Title       = homeworkTitle,
                Description = homeworkDescription
            };

            // Add Homework to relevant tables in DB:
            var currentClass   = GetClass(Session["CurrentClass"].ToString());
            var currentClassId = currentClass.Id;

            try
            {
                _classService.GetById(currentClassId).Homeworks.Add(homework);
                foreach (var student in _classService.GetById(currentClassId).Students)
                {
                    student.Homeworks.Add(homework);
                }

                _homeworkService.Add(homework);
            }
            catch (Exception e)
            {
                TempData["msg"] = "<script>alert('אירעה תקלה בהוספת שיעורי הבית');</script>";
                return;
            }

            _fileManager.ClearTemporaryQuestions(Server.MapPath("~/TemporaryFiles/Homeworks"), currentTeacherId,
                                                 currentTextId);
            TempData.Clear();
            TempData["msg"] = "<script>alert('שיעורי הבית נוספו בהצלחה, כעת התלמידים יוכלו לראות אותם');</script>";
        }
        public async Task <IActionResult> Add(AddHomeworkDto homeworkDto)
        {
            try
            {
                await _homeworkService.Add(homeworkDto);

                return(Ok("Ödev Oluşturuldu. Şimdi Ödev İçeriğini Belirleyebilirsiniz"));
            }
            catch
            {
                return(BadRequest("Ödev Oluşturma İşlemi Başarısız"));
            }
        }