Esempio n. 1
0
        public ActionResult <object> Save([FromBody] LessonPlanComment lessonPlanComment)
        {
            try
            {
                Init();
                StringBuilder sbError = new StringBuilder("");

                if (!ModelState.IsValid)
                {
                    Response.StatusCode = 400;
                    return((string)"Failed getting level id");
                }
                else
                {
                    var isSaved = _lessonPlanCommentService.Save(lessonPlanComment, ref sbError);
                    if (isSaved == null)
                    {
                        Response.StatusCode = 400;
                        return((string)"level save failed " + sbError.ToString());
                    }
                    else
                    {
                        return(Ok(isSaved));
                    }
                }
            }
            catch (Exception er)
            {
                return(Error(er));
            }
        }
        public LessonPlanComment Save(LessonPlanComment lessonPlanComment, string modifiedBy, ref bool dbFlag)
        {
            using (var connection = GetConnection())
            {
                if (lessonPlanComment.LessonPlanCommentId == null || lessonPlanComment.LessonPlanCommentId == Guid.Empty)
                {
                    lessonPlanComment.LessonPlanCommentId = Guid.NewGuid();
                    var update = @"
                                INSERT INTO LessonPlanComment
                                   (LessonPlanCommentID
                                   ,LessonPlanId
                                   ,TeacherId
                                   ,Comment  
                                   ,lastmodifiedBy
                                    )
                             VALUES
                                   (
                                    @LessonPlanCommentID , 
                                    @LessonPlanId , 
                                    @TeacherId , 
                                    @Comment , 
                                    @modifiedBy
                                   ) 
                                ";
                    var id     = connection.Execute(update,
                                                    new
                    {
                        LessonPlanCommentID = lessonPlanComment.LessonPlanCommentId,
                        LessonPlanId        = lessonPlanComment.LessonPlanId,
                        TeacherId           = lessonPlanComment.TeacherId,
                        Comment             = lessonPlanComment.Comment,
                        modifiedBy          = modifiedBy
                    });

                    return(lessonPlanComment);
                }
                else
                {
                    var update = @"         UPDATE LessonPlanComment
					                        SET  Comment = @Comment  , 
                                            LastModifiedDate = NOW() ,
                                            LastModifiedBy	 = @modifiedBy
					                        WHERE   LessonPlanCommentId = @id 
AND ISDeleted IS NULL
                                ";
                    var id     = connection.Execute(update,
                                                    new
                    {
                        id         = lessonPlanComment.LessonPlanCommentId,
                        Comment    = lessonPlanComment.Comment,
                        modifiedBy = modifiedBy
                    });

                    return(lessonPlanComment);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Only a teacher can save his on staff
        /// </summary>
        /// <param name="lessonPlanComment"></param>
        /// <param name="sbError"></param>
        /// <returns></returns>
        public LessonPlanCommentDto Save(LessonPlanComment lessonPlanComment, ref StringBuilder sbError)
        {
            if (lessonPlanComment == null)
            {
                sbError.Append("Fill in all required fields");
                return(null);
            }

            bool dbFlag = false;

            var lessonPlan = _uofRepository.LessonPlanRepository.GetByLessonPlanID(lessonPlanComment.LessonPlanId, ref dbFlag);

            if (lessonPlan == null)
            {
                sbError.Append("Lesson Plan does not exist");
                return(null);
            }

            if (string.IsNullOrEmpty(lessonPlanComment.Comment))
            {
                sbError.Append("comment is required");
                return(null);
            }

            if (lessonPlanComment.LessonPlanCommentId != null && lessonPlanComment.LessonPlanCommentId != Guid.Empty)
            {
                var comment = _uofRepository.LessonPlanCommentRepository.GetByLessonPlanCommentID((Guid)lessonPlanComment.LessonPlanCommentId, ref dbFlag);

                if (comment == null)
                {
                    sbError.Append("lesson plan comment does not exist required");
                    return(null);
                }
                else
                {
                    if (comment.TeacherId != _user.TeacherID)
                    {
                        sbError.Append("lesson plan comment does not belong to you");
                        return(null);
                    }
                }
            }
            else
            {
                lessonPlanComment.TeacherId = _user.TeacherID;
            }

            var save = _uofRepository.LessonPlanCommentRepository.Save(lessonPlanComment, _user.Username, ref dbFlag);

            var lessonComment = _uofRepository.LessonPlanCommentRepository.GetListByLessonPlanID(save.LessonPlanId, _user.TeacherID, ref dbFlag)?.FirstOrDefault(c => c.LessonPlanCommentId == save.LessonPlanCommentId);


            return(lessonComment);
        }