public FinaleSemesterGrade PostFinaleSemesterGrade(FinaleSemesterGradeDTO finaleSemesterGradeDto)
        {
            TeacherTeachSubjectToSchoolClassToStudentAtSemester teacherTeachSubjectToSchoolClassToStudentAtSemester = db.TeacherTeachSubjectToSchoolClassToStudentAtSemesterRepository.GetByID(finaleSemesterGradeDto.TeacherTeachSubjectToSchoolClassToStudentAtSemesterId);

            if (teacherTeachSubjectToSchoolClassToStudentAtSemester == null)
            {
                return(null);
            }

            // Ako vec postoji FinaleSemesterGrade za dati TeacherTeachSubjectToSchoolClassToStudentAtSemester vracamo null
            FinaleSemesterGrade check = db.FinaleSemesterGradeRepository.Get(x => x.TeacherTeachSubjectToSchoolClassToStudentAtSemester.Id == teacherTeachSubjectToSchoolClassToStudentAtSemester.Id).FirstOrDefault();

            if (check != null)
            {
                return(null);
            }
            FinaleSemesterGrade finaleSemesterGrade = new FinaleSemesterGrade();

            finaleSemesterGrade.Mark = finaleSemesterGradeDto.Mark;
            finaleSemesterGrade.Date = DateTime.Now;
            finaleSemesterGrade.TeacherTeachSubjectToSchoolClassToStudentAtSemester = teacherTeachSubjectToSchoolClassToStudentAtSemester;
            db.FinaleSemesterGradeRepository.Insert(finaleSemesterGrade);
            db.Save();

            logger.Info("Added new finale semester grade");
            Utilities.Utils.FinaleSemesterGradeMailSender(finaleSemesterGrade);

            return(finaleSemesterGrade);
        }
Exemple #2
0
        public static void FinaleSemesterGradeMailSender(FinaleSemesterGrade grade)
        {
            Student     student     = grade.TeacherTeachSubjectToSchoolClassToStudentAtSemester.TeacherTeachSubjectToSchoolClassToStudent.Student;
            SchoolClass schoolClass = grade.TeacherTeachSubjectToSchoolClassToStudentAtSemester.TeacherTeachSubjectToSchoolClassToStudent.TeacherTeachSubjectToSchoolClass.SchoolClass;
            Teacher     teacher     = grade.TeacherTeachSubjectToSchoolClassToStudentAtSemester.TeacherTeachSubjectToSchoolClassToStudent.TeacherTeachSubjectToSchoolClass.TeacherTeachSubject.Teacher;
            Subject     subject     = grade.TeacherTeachSubjectToSchoolClassToStudentAtSemester.TeacherTeachSubjectToSchoolClassToStudent.TeacherTeachSubjectToSchoolClass.TeacherTeachSubject.Subject;
            Semester    semester    = grade.TeacherTeachSubjectToSchoolClassToStudentAtSemester.Semester;
            string      mailSubject = String.Format("Dodela ZAKLJUCNE semestralne ocene za ucenika {0} {1}", student.FirstName, student.LastName);
            string      body        = String.Format("<div>" +
                                                    "<h4>ZAKLJUCNA ocena!</h4>" +
                                                    "<p> Ucenik {0} {1} dobio je zakljucnu ocenu: {2} </p>" +
                                                    "<p> Predmet: {3} </p>" +
                                                    "<p> Semestar: {4} </p>" +
                                                    "<p> Predmetni nastavnik: {5} {6} </p>" +
                                                    "<hr>" +
                                                    "<p> Za sve dodatne informacije obratiti se razrednom staresini: {7} {8} </p>" +
                                                    "</div> ", student.FirstName, student.LastName, (int)grade.Mark, subject.Name, (int)semester.Name, teacher.FirstName, teacher.LastName, schoolClass.HeadTeacher.FirstName, schoolClass.HeadTeacher.LastName);
            string      FromMail   = ConfigurationManager.AppSettings["from"];
            string      emailTo    = student.Parent.Email;//"*****@*****.**";
            MailMessage mail       = new MailMessage();
            SmtpClient  SmtpServer = new SmtpClient(ConfigurationManager.AppSettings["smtpServer"]);

            mail.From = new MailAddress(FromMail);
            mail.To.Add(emailTo);
            mail.Subject           = mailSubject;
            mail.Body              = body;
            mail.IsBodyHtml        = true;
            SmtpServer.Port        = int.Parse(ConfigurationManager.AppSettings["smtpPort"]);
            SmtpServer.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["from"], ConfigurationManager.AppSettings["password"]);
            SmtpServer.EnableSsl   = bool.Parse(ConfigurationManager.AppSettings["smtpSsl"]);
            SmtpServer.Send(mail);
        }
        public IHttpActionResult DeleteFinaleSemesterGrade(int id)
        {
            FinaleSemesterGrade finaleSemesterGrade = service.DeleteFinaleSemesterGrade(id);

            if (finaleSemesterGrade == null)
            {
                return(NotFound());
            }

            return(Ok(finaleSemesterGrade));
        }
        public FinaleSemesterGrade GetFinaleSemesterGradeById(int id)
        {
            // FinaleSemesterGrade finaleSemesterGrade = db.FinaleSemesterGradeRepository.GetByID(id); // GenericRepository (GetByID(id)) pronalazi i FinaleGrades (i sve Grade) ako unesemo njihov ID (zbog nasledjivanja) i onda zapucava, moramo nekako proveravati tip!!
            FinaleSemesterGrade finaleSemesterGrade = db.FinaleSemesterGradeRepository.Get(x => x.GradeId == id).FirstOrDefault();

            if (finaleSemesterGrade == null)
            {
                return(null);
            }

            return(finaleSemesterGrade);
        }
        public FinaleSemesterGrade DeleteFinaleSemesterGrade(int id)
        {
            FinaleSemesterGrade finaleSemesterGrade = db.FinaleSemesterGradeRepository.GetByID(id);

            if (finaleSemesterGrade == null)
            {
                return(null);
            }

            db.FinaleSemesterGradeRepository.Delete(id);
            db.Save();
            logger.Info("Deleted finale semester grade (id:{0})", id);

            return(finaleSemesterGrade);
        }
        public IHttpActionResult PostFinaleSemesterGrade(FinaleSemesterGradeDTO finaleSemesterGradeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            FinaleSemesterGrade postedFinaleSemesterGrade = service.PostFinaleSemesterGrade(finaleSemesterGradeDto);

            if (postedFinaleSemesterGrade == null)
            {
                return(BadRequest());
            }

            return(Created("", postedFinaleSemesterGrade));
        }
        public bool PutFinaleSemesterGrade(int id, FinaleSemesterGradeDTO finaleSemesterGradeDto)
        {
            if (id != finaleSemesterGradeDto.GradeId)
            {
                return(false);
            }

            FinaleSemesterGrade checkFinaleSemesterGrade = db.FinaleSemesterGradeRepository.GetByID(id);

            if (checkFinaleSemesterGrade == null)
            {
                return(false);
            }
            checkFinaleSemesterGrade.Mark = finaleSemesterGradeDto.Mark;
            checkFinaleSemesterGrade.Date = DateTime.Now;
            checkFinaleSemesterGrade.TeacherTeachSubjectToSchoolClassToStudentAtSemester = db.TeacherTeachSubjectToSchoolClassToStudentAtSemesterRepository.GetByID(finaleSemesterGradeDto.TeacherTeachSubjectToSchoolClassToStudentAtSemesterId);

            db.FinaleSemesterGradeRepository.Update(checkFinaleSemesterGrade);
            db.Save();
            logger.Info("Updated finale semester grade (id:{0})", checkFinaleSemesterGrade.GradeId);

            return(true);
        }