Exemplo n.º 1
0
        public async Task <ActionResult> Delete(int?id)
        {
            if (!id.HasValue)
            {
                return(HttpNotFound());
            }

            try
            {
                var statusCode = await _gradeRepository.DeleteGrade(id.Value);

                if (statusCode == HttpStatusCode.NotFound)
                {
                    return(HttpNotFound());
                }

                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            catch (BadRequestException bre)
            {
                var errorString = GetErrorsFromAdycHttpExceptionToString(bre);

                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, errorString));
            }
        }
Exemplo n.º 2
0
        // ReSharper disable once UnusedMember.Global
        public void Delete(LessonDeleteRequest request)
        {
            Guard.IsTrue(lessonId => 0 < lessonId, request.LessonId);
            Guard.AgainstEmpty(request.Provider);
            Guard.AgainstEmpty(request.ProviderId);
            var existingUser = UserHelpers.GetExistingUser(request, UserRepository);

            Guard.IsTrue(eu => eu.IsNew == false, existingUser);

            Guard.AgainstEmpty(request.StudentProvider);
            Guard.AgainstEmpty(request.StudentProviderId);
            var existingStudent = UserHelpers.GetExistingUser(new LessonDeleteRequest {
                Provider = request.StudentProvider, ProviderId = request.StudentProviderId
            }, UserRepository);

            Guard.IsTrue(eu => eu.IsNew == false, existingStudent);
            Guard.IsTrue(es => es.IsStudent, existingStudent);

            var grade = GradeRepository.GetGrade(request.LessonId, request.StudentProvider, request.ProviderId);

            if (grade == null)
            {
                return;
            }

            if (existingUser.IsTeacher == false || request.Provider != grade.TeacherProvider || request.ProviderId != grade.TeacherProviderId)
            {
                throw new HttpError(HttpStatusCode.Unauthorized, "Unauthorized");
            }

            if (grade.IsDeleted)
            {
                return;
            }

            GradeRepository.DeleteGrade(grade.Id);
        }