コード例 #1
0
        public async Task <IActionResult> PostAsync(Transfer_Facility facility)
        {
            try
            {
                _logger.LogInformation($"Adding new facility.");
                var validCheck = new CheckerClass(_facilityRepository);
                validCheck.CheckFacility(facility);
                Inner_Facility transformedFacility = new Inner_Facility
                {
                    FacilityId          = 0,
                    FacilityAddress1    = facility.FacilityAddress1,
                    FacilityCity        = facility.FacilityCity,
                    FacilityName        = facility.FacilityName,
                    FacilityState       = facility.FacilityState,
                    FacilityZipcode     = facility.FacilityZipcode,
                    FacilityPhoneNumber = facility.FacilityPhoneNumber,
                };
                await _facilityRepository.AddFacilityAsync(transformedFacility);

                return(CreatedAtAction(nameof(GetByIdAsync), new { id = facility.FacilityId }, facility));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #2
0
        /// <summary> Updates one existing facility in the database
        /// <param name="facility"> Inner_Facility Object - represents the fields of a Facility in the database </param>
        /// <returns> no return </returns>
        /// </summary>
        public async Task UpdateFacilityAsync(Inner_Facility facility)
        {
            Data_Facility currentEntity = await _context.Facilities.FindAsync(facility.FacilityId);

            Data_Facility newEntity = Mapper.UnMapFacility(facility);

            _context.Entry(currentEntity).CurrentValues.SetValues(newEntity);
            await Save();
        }
コード例 #3
0
        /// <summary> Add one facility to the database
        /// <param name="facility"> Inner_Facility Object - represents the fields of a Facility in the database </param>
        /// <returns> Returns inputted (and formatted) Facility </returns>
        /// </summary>
        public async Task <Inner_Facility> AddFacilityAsync(Inner_Facility facility)
        {
            var newFacility = Mapper.UnMapFacility(facility);

            newFacility.FacilityId = (await GetFacilityAsync()).Max(p => p.FacilityId) + 1;
            _context.Facilities.Add(newFacility);
            await Save();

            return(Mapper.MapFacility(newFacility));
        }
コード例 #4
0
 public static Data_Facility UnMapFacility(Inner_Facility facility)
 {
     return(new Data_Facility
     {
         FacilityId = facility.FacilityId,
         FacilityAddress1 = facility.FacilityAddress1,
         FacilityCity = facility.FacilityCity,
         FacilityName = facility.FacilityName,
         FacilityPhoneNumber = facility.FacilityPhoneNumber,
         FacilityState = facility.FacilityState,
         FacilityZipcode = facility.FacilityZipcode,
     });
 }
コード例 #5
0
// ! ***********************************
// ! *********** Facility **************
// ! ***********************************
        public static Transfer_Facility MapFacility(Inner_Facility facility)
        {
            return(new Transfer_Facility
            {
                FacilityId = facility.FacilityId,
                FacilityAddress1 = facility.FacilityAddress1,
                FacilityCity = facility.FacilityCity,
                FacilityName = facility.FacilityName,
                FacilityPhoneNumber = facility.FacilityPhoneNumber,
                FacilityState = facility.FacilityState,
                FacilityZipcode = facility.FacilityZipcode
            });
        }
コード例 #6
0
        public void APIFacility_Behavior()
        {
            var            apiMapper = this.MakeMapper();
            Inner_Facility facility  = new Inner_Facility
            {
                FacilityId          = 1,
                FacilityName        = "Fake Facility Name",
                FacilityCity        = "Fake Facility City",
                FacilityAddress1    = "Fake address",
                FacilityPhoneNumber = 9215555555,
                FacilityState       = "Fake Facility State",
                FacilityZipcode     = 84912
            };
            var outcome = Mapper.MapFacility(facility);

            Assert.True(true);
            this.mockRepo.VerifyAll();
        }