Пример #1
0
        public IHttpActionResult AddStudentToParent(string parentId, string studentId)
        {
            Parent parent = parentsService.GetById(parentId);

            if (parent == null || studentsService.GetById(studentId) == null)
            {
                return(NotFound());
            }

            try
            {
                if (parent.Children.Select(x => x.Id).Contains(studentId))
                {
                    throw new Exception("Parent is already linked to this student!");
                }
                else
                {
                    logger.Info("Adding student to parent");
                    Student child = parentsService.AddStudentToParent(parentId, studentId);
                    return(Ok(child));
                }
            }
            catch (Exception e)
            {
                logger.Error(e, "Adding student to parent");
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e)));
            }
        }