Beispiel #1
0
        public IActionResult GetProgressRecordsForClassEntityAndWeek(string classEntityOwnerIdentityName, int weekId)
        {
            if (!_repo.ClassEntityExists(classEntityOwnerIdentityName) ||
                !_repo.WeekExists(weekId))
            {
                return(NotFound());
            }

            //var results = new List<CityWithoutPointsOfInterestDto>();
            var progressRecordsToReturn = _repo.GetAllProgressRecordsFromClassAndWeek(classEntityOwnerIdentityName, weekId);
            var results = _mapper.Map <IEnumerable <ProgressRecordDto> >(progressRecordsToReturn);


            return(Ok(results));
        }
Beispiel #2
0
        public IActionResult CreateClassEntity(
            [FromBody]  ClassEntityForCreationDto newClassEntityDto)
        {
            if (newClassEntityDto == null)
            {
                return(BadRequest());
            }

            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }


            if (_repo.ClassEntityExists(newClassEntityDto.OwnerIdentityName))
            {
                return(BadRequest("You already have a class."));
            }



            var finalClassEntity = _mapper.Map <Entities.ClassEntity>(newClassEntityDto);

            _repo.AddClassEntity(finalClassEntity);
            if (!_repo.Save())
            {
                return(StatusCode(500, $"A problem happened while handling your request to create a class for user {newClassEntityDto.OwnerIdentityName}."));
            }
            var createdClassEntityToReturn = _mapper.Map <ClassEntityDto>(finalClassEntity);

            return(CreatedAtAction("GetClassEntityByOwnerIdentityName", new
                                   { ownerIdentityName = createdClassEntityToReturn.OwnerIdentityName }, createdClassEntityToReturn));
        }
Beispiel #3
0
        public IActionResult CreateWeek(
            string ownerIdentityName,
            [FromBody]  WeekForCreationDto newWeekDto)
        {
            if (newWeekDto == null)
            {
                return(BadRequest());
            }

            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            if (!_repo.ClassEntityExists(ownerIdentityName))
            {
                return(NotFound());
            }

            var finalWeek = _mapper.Map <Entities.Week>(newWeekDto);

            //START: Might be able to replace this by defining student name as a Key value for EFCore
            var weeks = _repo.GetAllWeeksFromClass(ownerIdentityName);

            foreach (var s in weeks)
            {
                if (s.Number == finalWeek.Number)
                {
                    return(UnprocessableEntity("There is already a Week with that number. How did that happen?"));
                }
            }
            //STOP: Might be able to replace this by defining student name as a Key value for EFCore

            _repo.AddWeek(ownerIdentityName, finalWeek);
            if (!_repo.Save())
            {
                return(StatusCode(500, $"A problem happened while handling your request to create a week with number:  {newWeekDto.Number}."));
            }
            var weekToReturn = _mapper.Map <WeekDto>(finalWeek);

            return(CreatedAtAction("GetWeek", new
                                   { weekId = weekToReturn.Id }, weekToReturn));
        }
        public IActionResult CreateStudent(
            string ownerIdentityName,
            [FromBody]  StudentForCreationDto newStudentDto)
        {
            if (newStudentDto == null)
            {
                return(BadRequest());
            }

            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            if (!_repo.ClassEntityExists(ownerIdentityName))
            {
                return(NotFound());
            }

            var finalStudent = _mapper.Map <Entities.Student>(newStudentDto);

            //START: Might be able to replace this by defining student name as a Key value for EFCore
            var classStudents = _repo.GetAllStudentsFromClass(ownerIdentityName);

            foreach (var s in classStudents)
            {
                if (s.Name == finalStudent.Name)
                {
                    return(UnprocessableEntity("There is already a Student with that name in this Class"));
                }
            }
            //STOP: Might be able to replace this by defining student name as a Key value for EFCore

            _repo.AddStudent(ownerIdentityName, finalStudent);
            if (!_repo.Save())
            {
                return(StatusCode(500, $"A problem happened while handling your request to create a student with name:  {newStudentDto.Name}."));
            }
            var createdStudentToReturn = _mapper.Map <StudentDto>(finalStudent);

            return(CreatedAtAction("GetStudent", new
                                   { studentId = createdStudentToReturn.Id }, createdStudentToReturn));
        }
        public IActionResult CreateTrackedItem(
            string ownerIdentityName,
            [FromBody]  TrackedItemForCreationDto newTrackedItemDto)
        {
            if (newTrackedItemDto == null)
            {
                return(BadRequest());
            }

            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            if (!_repo.ClassEntityExists(ownerIdentityName))
            {
                return(NotFound());
            }

            var finalTrackedItem = _mapper.Map <Entities.TrackedItem>(newTrackedItemDto);

            //START: Might be able to replace this by defining student name as a Key value for EFCore
            var trackedItems = _repo.GetAllTrackedItemsFromClass(ownerIdentityName);

            foreach (var s in trackedItems)
            {
                if (s.Name == finalTrackedItem.Name)
                {
                    return(UnprocessableEntity("There is already a Tracked Item with that name in this Class"));
                }
            }
            //STOP: Might be able to replace this by defining student name as a Key value for EFCore

            _repo.AddTrackedItem(ownerIdentityName, finalTrackedItem);
            if (!_repo.Save())
            {
                return(StatusCode(500, $"A problem happened while handling your request to create a Tracked Item with name:  {newTrackedItemDto.Name}."));
            }
            var trackedItemToReturn = _mapper.Map <TrackedItemDto>(finalTrackedItem);

            return(CreatedAtAction("GetTrackedItem", new
                                   { trackedItemId = trackedItemToReturn.Id }, trackedItemToReturn));
        }