コード例 #1
0
        /// <summary>
        /// Update existed single amenity info in the database by logic amenity object
        /// </summary>
        /// <param name="amenity"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">list of complex not found</exception>
        public async Task <bool> UpdateAmenityAsync(Logic.Amenity amenity)
        {
            try
            {
                var eAmenity = await _context.Amenity.FindAsync(amenity.AmenityId);

                if (amenity.AmenityType != null)
                {
                    eAmenity.AmenityType = amenity.AmenityType;
                }
                if (amenity.Description != null)
                {
                    eAmenity.Description = amenity.Description;
                }

                await _context.SaveChangesAsync();

                _log.LogInformation("amenity: {amenity.AmenityId} {amenity.AmenityType} was updated"
                                    , amenity.AmenityId, amenity.AmenityType);

                return(true);
            }
            catch (ArgumentException ex)
            {
                _log.LogWarning(ex, "Unable to update the amenity.");
                throw;
            }
        }
コード例 #2
0
 /// <summary>
 /// Logic.Amenity => Entity.Amenity
 /// All properties are mapped. Logic.amenity has no Lists
 /// </summary>
 /// <param name="amenity"></param>
 /// <returns></returns>
 public Entity.Amenity MapAmenitytoE(Logic.Amenity amenity)
 {
     return(new Entity.Amenity
     {
         AmenityId = amenity.AmenityId,
         AmenityType = amenity.AmenityType,
         Description = amenity.Description
     });
 }
コード例 #3
0
        /// <summary>
        /// Create new single Amenity in database by logic amenity object
        /// </summary>
        /// <param name="amenity"></param>
        /// <returns></returns>
        public async Task <bool> CreateAmenityAsync(Logic.Amenity amenity)
        {
            var newAmenity = _map.MapAmenitytoE(amenity);

            await _context.AddAsync(newAmenity);

            await _context.SaveChangesAsync();

            _log.LogInformation("new Amenity: {amenity.AmenityType} was added", amenity.AmenityType);

            return(true);
        }
コード例 #4
0
        public void AmenityTest()
        {
            var aId     = Guid.NewGuid();
            var amenity = new Logic.Amenity
            {
                AmenityId   = aId,
                AmenityType = "fridge",
                Description = "to freeze items"
            };

            Assert.Equal(aId, amenity.AmenityId);
            Assert.Equal("fridge", amenity.AmenityType);
            Assert.Equal("to freeze items", amenity.Description);
        }
コード例 #5
0
        public void AmenitytoETest()
        {
            var amId   = Guid.NewGuid();
            var mapper = new Mapper();
            var a      = new Logic.Amenity
            {
                AmenityId   = amId,
                AmenityType = "Fridge",
                Description = "To freeze items"
            };

            var ea = mapper.MapAmenitytoE(a);

            Assert.Equal(amId, ea.AmenityId);
            Assert.Equal("Fridge", ea.AmenityType);
            Assert.Equal("To freeze items", ea.Description);
        }
コード例 #6
0
        /// <summary>
        /// Delete existed single amenity info in the database by logic amenity object
        /// </summary>
        /// <param name="amenity"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException">Unable to delete the amenity</exception>
        public async Task <bool> DeleteAmenityAsync(Logic.Amenity amenity)
        {
            try
            {
                var dAmenity = await _context.Amenity.FindAsync(amenity.AmenityId);

                _context.Remove(dAmenity);

                await _context.SaveChangesAsync();

                _log.LogInformation("amenity: {dAmenity.AmenityId} {dAmenity.AmenityType} is deleted", dAmenity.AmenityId, dAmenity.AmenityType);

                return(true);
            }
            catch (InvalidOperationException ex)
            {
                _log.LogWarning(ex, "Unable to delete the amenity.");
                throw;
            }
        }
コード例 #7
0
        //DELETE: api/amenity/deleteAmenity
        public async Task <ActionResult> DeleteAmenityAsync([FromBody] ApiAmenity apiAmenity)
        {
            var amenity = new Logic.Amenity()
            {
                AmenityId   = apiAmenity.AmenityId,
                AmenityType = apiAmenity.AmenityType,
                Description = apiAmenity.Description
            };

            try
            {
                await _complexRepository.DeleteAmenityAsync(amenity);

                _log.LogInformation("amenity: {amenity.AmenityType} is deleted", amenity.AmenityType);

                return(StatusCode(201));
            }
            catch (Exception ex)
            {
                _log.LogError("{ex}, unable to delete amenity", ex);
                return(StatusCode(500, ex.Message));
            }
        }
コード例 #8
0
        public async void PutComplexAsyncTest()
        {
            var cId     = Guid.NewGuid();
            var aId     = Guid.NewGuid();
            var pId     = Guid.NewGuid();
            var amId    = Guid.NewGuid();
            var address = new ApiComplexAddress
            {
                AddressId     = aId,
                StreetAddress = "test ave",
                City          = "dallas",
                State         = "TX",
                Country       = "USA",
                ZipCode       = "76010"
            };
            var amenity = new Logic.Amenity
            {
                AmenityId   = amId,
                AmenityType = "name",
                Description = "description"
            };
            var amenities = new List <Logic.Amenity>
            {
                amenity
            };
            var apiComplex = new ApiComplex
            {
                ComplexId      = cId,
                Address        = address,
                ProviderId     = pId,
                ComplexName    = "Liv+",
                ContactNumber  = "1234567890",
                ComplexAmenity = amenities
            };
            var complex = new Logic.Complex
            {
                ComplexId     = cId,
                AddressId     = aId,
                ProviderId    = pId,
                ComplexName   = "Liv+",
                ContactNumber = "1234567890"
            };
            var ac = new Logic.AmenityComplex
            {
                AmenityComplexId = Guid.NewGuid(),
                AmenityId        = amId,
                ComplexId        = cId
            };
            var complexRepo = new Mock <IRepository>();
            var logger      = new Mock <ILogger <ComplexController> >();
            var rss         = new Mock <IRoomServiceSender>();
            var ar          = new Mock <IAddressRequest>();
            var rr          = new Mock <IRoomRequest>();
            var res         = true;

            complexRepo.Setup(r => r.DeleteAmenityComplexAsync(cId))
            .Returns(Task.FromResult(res));
            complexRepo.Setup(r => r.UpdateComplexAsync(complex))
            .Returns(Task.FromResult(res));
            complexRepo.Setup(c => c.ReadAmenityListAsync())
            .Returns(Task.FromResult(amenities));
            complexRepo.Setup(p => p.CreateAmenityComplexAsync(ac))
            .Returns(Task.FromResult(res));

            //act
            var controller = new ComplexController(complexRepo.Object, logger.Object, rss.Object, ar.Object, rr.Object);
            var model      = Assert.IsAssignableFrom <StatusCodeResult>(await controller.PutComplexAsync(apiComplex));

            //assert
            Assert.IsAssignableFrom <StatusCodeResult>(model);
        }