Esempio n. 1
0
        public async Task <InstructorResponse> AddInstructorAsync(InstructorRequest request)
        {
            var response = new InstructorResponse {
                IsError = false
            };

            try
            {
                await _context.Instructors.AddAsync(new Instructor
                {
                    FirstName = request.FirstName,
                    LastName  = request.LastName,
                    Image     = request.Image
                });

                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                response.IsError      = true;
                response.ErrorMessage = e.Message;
            }

            return(response);
        }
        public async Task <IActionResult> AddInstructor([FromBody] InstructorRequest request)
        {
            var response = await _instructorsService.AddInstructorAsync(request);

            if (response.IsError)
            {
                return(BadRequest(response.ErrorMessage));
            }

            return(Ok(response));
        }