public IActionResult Delete(long id)
        {
            try
            {
                var checkLearners = _context.CourseSession.Where(x => x.id == id)
                                    .Include(x => x.LearnerSession)
                                    .FirstOrDefault();
                if (checkLearners == null)
                {
                    return(NotFound(_NotFound));
                }

                var learnersEnrolled = checkLearners.LearnerSession.Count();

                if (checkLearners.LearnerSession.Count() > 0)
                {
                    return(BadRequest(new GenericResult {
                        Response = false, Message = "Unable to delete! There are (" + learnersEnrolled + ") confirmed participant(s) for this session"
                    }));
                }

                var response = _courseSessionRepository.Delete(id);

                if (response == true)
                {
                    return(Ok(new GenericResult {
                        Response = response, Message = "Session has been successfully deleted"
                    }));
                }
                else
                {
                    return(NotFound(_NotFound));
                }
            } catch (Exception e) {
                return(BadRequest(e));
            }
        }
Example #2
0
        public async Task <bool> Delete(int id)
        {
            await courseSessionRepository.Delete(id, Session);

            return(true);
        }