public async Task <ActionResult <Hospital> > PostHospital(Hospital hospital)
        {
            Core.Models.Hospital addedHospital = await _repository.PostHospitalAsync(Mapper.MapHospital(hospital));

            if (addedHospital == null)
            {
                return(BadRequest($"Unable to add new hospital."));
            }
            return(CreatedAtAction("GetHospital", new { id = hospital.Id }, hospital));
        }
        public async Task <ActionResult <Hospital> > GetHospital(int id)
        {
            Core.Models.Hospital hospital = await _repository.GetHospitalAsync(id);

            if (hospital == null)
            {
                return(NotFound());
            }
            return(Ok(Mapper.MapHospital(hospital)));
        }
        public async Task <IActionResult> PutHospital(int id, Hospital hospital)
        {
            if (id != hospital.Id)
            {
                return(BadRequest());
            }
            Core.Models.Hospital updatedHospital = await _repository.PutHospitalAsync(id, Mapper.MapHospital(hospital));

            if (updatedHospital == null)
            {
                return(BadRequest($"Hospital with ID {id} was not found."));
            }

            return(Ok($"Hospital with ID {id} was successfully updated."));
        }
Beispiel #4
0
        /// <summary>
        /// Update a hospital
        /// </summary>
        /// <param name="id"></param>
        /// <param name="hospital"></param>
        /// <returns>Returns the hospital after updated</returns>
        public async Task <Core.Models.Hospital> PutHospitalAsync(int id, Core.Models.Hospital hospital)
        {
            var hospitalExists = await _dbContext.Hospitals.FindAsync(id);

            if (hospitalExists == null)
            {
                _logger.LogInformation($"Unable to update hospital with id {id} because it was not found.");
                return(null);
            }
            _logger.LogInformation($"Updating hospital with id {id}.");
            _dbContext.Entry(hospitalExists).CurrentValues.SetValues(hospital);
            await _dbContext.SaveChangesAsync();

            return(hospital);
        }
 public static Hospital MapHospital(Core.Models.Hospital hospital)
 {
     return(hospital is null ? null : new Hospital
     {
         Id = hospital.Id,
         Name = hospital.Name,
         Address = hospital.Address,
         City = hospital.City,
         State = hospital.State,
         Zip = hospital.Zip,
         Phone = hospital.Phone,
         Website = hospital.Website,
         AggMedicalStaffRating = hospital.AggMedicalStaffRating,
         AggClericalStaffRating = hospital.AggClericalStaffRating,
         AggFacilityRating = hospital.AggFacilityRating,
         AggOverallRating = hospital.AggOverallRating,
         Reviews = hospital.Reviews.Select(MapReview).ToList()
     });
 }
Beispiel #6
0
        /// <summary>
        /// Adds a new Hospital to the DB.
        /// </summary>
        /// <param name="hospital"></param>
        /// <returns>The hospital that was added</returns>
        public async Task <Core.Models.Hospital> PostHospitalAsync(Core.Models.Hospital hospital)
        {
            var newHospital = new Hospital
            {
                Name    = hospital.Name,
                Address = hospital.Address,
                City    = hospital.City,
                State   = hospital.State,
                Zip     = hospital.Zip,
                Phone   = hospital.Phone,
                Website = hospital.Website
            };

            _logger.LogInformation($"Added hospital with name {hospital.Name} to DB.");

            _dbContext.Hospitals.Add(newHospital);
            await _dbContext.SaveChangesAsync();

            return(Mapper.MapHospital(newHospital));
        }