public async Task <IActionResult> RemoveStudent(RemoveStudentRequest request)
        {
            var student = _context.Student.FirstOrDefault(s => s.IndexNumber == request.IndexNumber);

            if (student == null)
            {
                return(new BadRequestResult());
            }

            _context.Remove(student);
            await _context.SaveChangesAsync();

            return(new OkObjectResult(student));
        }
        public IActionResult RemoveStudent(RemoveStudentRequest request)
        {
            RemoveStudentResponse response;

            try
            {
                response = _dbService.RemoveStudent(request);
            }
            catch (Exception ex)
            {
                return(BadRequest("Something went wrong"));
            }

            return(Ok(response));
        }
        public void WhenUserProfileRemoveStudentFromClassRoom(string userprofileId, string removeUserProfileId, string classRoomId)
        {
            var mockUserProfileRepo = ScenarioContext.Current.Get <Mock <IUserProfileRepository> >();

            mockUserProfileRepo.Setup(it => it.UpsertUserProfile(It.IsAny <UserProfile>()));

            var mycourseCtrl = ScenarioContext.Current.Get <MyCourseController>();
            var body         = new RemoveStudentRequest
            {
                ClassRoomId         = classRoomId,
                RemoveUserProfileId = removeUserProfileId,
                UserProfileId       = userprofileId
            };

            mycourseCtrl.RemoveStudent(body);
        }
Exemple #4
0
        public void RemoveStudent(RemoveStudentRequest body)
        {
            var areArgumentsValid = body != null &&
                                    !string.IsNullOrEmpty(body.ClassRoomId) &&
                                    !string.IsNullOrEmpty(body.RemoveUserProfileId) &&
                                    !string.IsNullOrEmpty(body.UserProfileId);

            if (!areArgumentsValid)
            {
                return;
            }

            UserProfile userprofile;
            var         canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(body.UserProfileId, body.ClassRoomId, out userprofile);

            if (!canAccessToTheClassRoom)
            {
                return;
            }

            var isTeacherAccount = userprofile.Subscriptions.First(it => it.ClassRoomId == body.ClassRoomId).Role == UserProfile.AccountRole.Teacher;

            if (!isTeacherAccount)
            {
                return;
            }

            var selectedUserProfile = _userprofileRepo.GetUserProfileById(body.RemoveUserProfileId);

            if (selectedUserProfile == null)
            {
                return;
            }

            var selectedSubscription = selectedUserProfile.Subscriptions
                                       .Where(it => it.ClassRoomId.Equals(body.ClassRoomId))
                                       .Where(it => !it.DeletedDate.HasValue)
                                       .FirstOrDefault();

            if (selectedSubscription == null)
            {
                return;
            }

            selectedSubscription.DeletedDate = _dateTime.GetCurrentTime();
            _userprofileRepo.UpsertUserProfile(selectedUserProfile);
        }
        public RemoveStudentResponse RemoveStudent(RemoveStudentRequest request)
        {
            RemoveStudentResponse response;

            try
            {
                var student = _dbContext.Student.Where(s => s.IndexNumber == request.IndexNumber).Single();
                Console.WriteLine(student.FirstName);
                response = new RemoveStudentResponse
                {
                    IndexNumber = student.IndexNumber
                };

                _dbContext.Student.Remove(student);
                _dbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(response);
        }
 public async Task <IActionResult> RemoveStudent(RemoveStudentRequest request)
 {
     return(await _dbService.RemoveStudent(request));
 }