Ejemplo n.º 1
0
        public IActionResult Edit(int id, [FromBody] EditCreateStudentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("You request contains invalid data!"));
            }
            if (model.StudentParent == null || String.IsNullOrEmpty(model.StudentParent.Email))
            {
                return(BadRequest("Please enter a parent email!"));
            }

            int?schoolId = Convert.ToInt32(GetSchoolIdForCurrentUser());

            var studentEditingResult = ds.EditStudent(model, schoolId);

            if (studentEditingResult == ObjectManipulationResult.ErrorOccured)
            {
                return(BadRequest("Error occured while editing the student"));
            }
            else if (studentEditingResult == ObjectManipulationResult.Exists)
            {
                return(BadRequest("Student with ExternalId - " + model.ExternalId + " alredy exists!"));
            }

            return(Ok());
        }
Ejemplo n.º 2
0
        public IActionResult Create([FromBody] EditCreateStudentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (model.StudentParent == null || String.IsNullOrEmpty(model.StudentParent.Email))
            {
                return(BadRequest("Please enter a parent email!"));
            }

            if (String.IsNullOrEmpty(model.ExternalId))
            {
                model.ExternalId = Guid.NewGuid().ToString();
            }

            var studenCreattingResult = ds.CreateStudent(model, GetSchoolIdForCurrentUser());

            if (studenCreattingResult == ObjectManipulationResult.ErrorOccured)
            {
                return(BadRequest("Error occured while creating the student"));
            }
            else if (studenCreattingResult == ObjectManipulationResult.Exists)
            {
                return(BadRequest("Student with ExternalId - " + model.ExternalId + " alredy exists!"));
            }

            return(Ok("Student created!"));
        }