コード例 #1
0
        public IHttpActionResult RemoveStudentFromParent(string parentId, string studentId)
        {
            Parent parent = parentsService.GetById(parentId);

            if (parent == null || studentsService.GetById(studentId) == null)
            {
                logger.Warn("Removing student from parent (not found in Db)");
                return(NotFound());
            }

            try
            {
                if (!parent.Children.Select(x => x.Id).Contains(studentId))
                {
                    throw new NullReferenceException("Parent is not linked to this student! Nothing to remove.");
                }
                else
                {
                    logger.Info("Removing student from parent");
                    Student child = parentsService.RemoveStudentFromParent(parentId, studentId);
                    return(Ok(child));
                }
            }
            catch (NullReferenceException e)
            {
                logger.Error(e.Message, "Removing subject from student");
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.Message)));
            }
        }