示例#1
0
        public IActionResult CreateDentist([FromBody] Dentist dentist)
        {
            try
            {
                if (dentist.IsObjectNull())
                {
                    _logger.LogError("Dentist object sent from client is null.");
                    return(BadRequest("Dentist Object is null"));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid dentist object sent from client.");
                    return(BadRequest("Invalid model object"));
                }

                _repository.Dentist.CreateDentist(dentist);

                return(CreatedAtRoute("DentistById", new { id = dentist.Id }, dentist));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside CreateDentist action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
示例#2
0
        public IActionResult UpdateDentist(int id, [FromBody] Dentist dentist)
        {
            try
            {
                if (dentist.IsObjectNull())
                {
                    _logger.LogError("dentist object sent from client is null.");
                    return(BadRequest("dentist object is null"));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid dentist object sent from client.");
                    return(BadRequest("Invalid model object"));
                }

                var dbDentist = _repository.Dentist.GetDentistById(id);

                if (dbDentist.IsEmptyObject())
                {
                    _logger.LogError($"Dentist with id: {id}, hasn't been found in db.");
                    return(NotFound());
                }

                _repository.Dentist.UpdateDentist(dbDentist, dentist);
                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateDentist action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }