Esempio n. 1
0
 /// <summary>
 /// Logic.AmenityComplex => Entity.AmenityComplex
 /// </summary>
 /// <param name="ac"></param>
 /// <returns></returns>
 public Entity.AmenityComplex MapAmenityComplextoE(Logic.AmenityComplex ac)
 {
     return(new Entity.AmenityComplex
     {
         AmenityComplexId = ac.AmenityComplexId,
         AmenityId = ac.AmenityId,
         ComplexId = ac.ComplexId
     });
 }
Esempio n. 2
0
        /// <summary>
        /// Create new single Amenities of Room in database by logic amenitycomplex object
        /// </summary>
        /// <param name="ac"></param>
        /// <returns></returns>
        public async Task <bool> CreateAmenityComplexAsync(Logic.AmenityComplex ac)
        {
            var amenityComplex = _map.MapAmenityComplextoE(ac);

            await _context.AddAsync(amenityComplex);

            await _context.SaveChangesAsync();

            _log.LogInformation("new amenity for complex: {AmenityComplexId} was added", ac.AmenityComplexId);

            return(true);
        }
Esempio n. 3
0
        public void AmenityComplexTest()
        {
            var acId1 = Guid.NewGuid();
            var amId  = Guid.NewGuid();
            var cId1  = Guid.NewGuid();

            var ac = new Logic.AmenityComplex
            {
                AmenityComplexId = acId1,
                AmenityId        = amId,
                ComplexId        = cId1
            };

            Assert.Equal(acId1, ac.AmenityComplexId);
            Assert.Equal(amId, ac.AmenityId);
            Assert.Equal(cId1, ac.ComplexId);
        }
Esempio n. 4
0
        public void AmenityComplextoETest()
        {
            var acId   = Guid.NewGuid();
            var amId   = Guid.NewGuid();
            var cId    = Guid.NewGuid();
            var mapper = new Mapper();

            var ac = new Logic.AmenityComplex
            {
                AmenityComplexId = acId,
                AmenityId        = amId,
                ComplexId        = cId
            };

            var eAc = mapper.MapAmenityComplextoE(ac);

            Assert.Equal(acId, eAc.AmenityComplexId);
            Assert.Equal(amId, eAc.AmenityId);
            Assert.Equal(cId, eAc.ComplexId);
        }
Esempio n. 5
0
        //PUT: api/complex/editcomplex
        public async Task <ActionResult> PutComplexAsync([FromBody] ApiComplex apiComplex)
        {
            var compAddr = new ApiComplexAddress()
            {
                AddressId     = apiComplex.Address.AddressId,
                StreetAddress = apiComplex.Address.StreetAddress,
                City          = apiComplex.Address.City,
                State         = apiComplex.Address.State,
                ZipCode       = apiComplex.Address.ZipCode,
                Country       = apiComplex.Address.Country,
            };

            var complex = new Logic.Complex()
            {
                ComplexId     = apiComplex.ComplexId,
                AddressId     = apiComplex.Address.AddressId,
                ProviderId    = apiComplex.ProviderId,
                ContactNumber = apiComplex.ContactNumber,
                ComplexName   = apiComplex.ComplexName
            };

            await _complexRepository.DeleteAmenityComplexAsync(complex.ComplexId);

            _log.LogInformation($"(API)old amenities for complex id: {apiComplex.ComplexId} is deleted");

            var amenityComplex = new Logic.AmenityComplex();

            try
            {
                await _complexRepository.UpdateComplexAsync(complex);

                _log.LogInformation("(API) complex is updated");

                var amenities = await _complexRepository.ReadAmenityListAsync();

                _log.LogInformation("(API) list of amenity is read");

                Guid amenityComplexId;
                amenityComplex.ComplexId = complex.ComplexId;

                foreach (var amenity in apiComplex.ComplexAmenity)
                {
                    foreach (var am in amenities)
                    {
                        if (am.AmenityType == amenity.AmenityType)
                        {
                            amenityComplex.AmenityId = am.AmenityId;

                            amenityComplexId = Guid.NewGuid();
                            amenityComplex.AmenityComplexId = amenityComplexId;
                        }
                    }

                    await _complexRepository.CreateAmenityComplexAsync(amenityComplex);

                    _log.LogInformation("(API)new list of amenity of complex is created");
                }

                //send ApiComplexAddress to Address service to update the address

                return(StatusCode(200));
            }
            catch (Exception ex)
            {
                _log.LogError($"(API){ex}: unable to update complex");
                return(StatusCode(500, ex.Message));
            }
        }
Esempio n. 6
0
        //Post: api/complex/PostComplex
        public async Task <ActionResult <ApiComplex> > PostComplexAsync([FromBody] ApiComplex apiComplex)
        {
            var compAddr = new ApiComplexAddress()
            {
                StreetAddress = apiComplex.Address.StreetAddress,
                City          = apiComplex.Address.City,
                State         = apiComplex.Address.State,
                ZipCode       = apiComplex.Address.ZipCode,
                Country       = apiComplex.Address.Country,
            };

            var addressId = (await _addressRequest.PostAddressAsync(compAddr)).AddressId;
            var complexId = Guid.NewGuid();

            var complex = new Logic.Complex()
            {
                ComplexId     = complexId,
                AddressId     = addressId,
                ProviderId    = apiComplex.ProviderId,
                ContactNumber = apiComplex.ContactNumber,
                ComplexName   = apiComplex.ComplexName
            };

            var amenityComplex = new Logic.AmenityComplex();

            try
            {
                await _complexRepository.CreateComplexAsync(complex);

                _log.LogInformation("(API)new complex in the database is inserted");

                var amenities = await _complexRepository.ReadAmenityListAsync();

                _log.LogInformation("(API)list of Amenity is found");

                amenityComplex.ComplexId = complex.ComplexId;

                foreach (var amenity in apiComplex.ComplexAmenity)
                {
                    foreach (var am in amenities)
                    {
                        if (am.AmenityType == amenity.AmenityType)
                        {
                            amenityComplex.AmenityId        = am.AmenityId;
                            amenityComplex.AmenityComplexId = Guid.NewGuid();
                        }
                    }

                    await _complexRepository.CreateAmenityComplexAsync(amenityComplex);

                    _log.LogInformation($"(API)a list of amenities for complex id: {complex.ComplexId} was created");
                }

                return(Created($"api/Complex/{complex.ComplexId}", apiComplex));
            }
            catch (Exception ex)
            {
                _log.LogError($"(API){ex}: unable to create complex");
                return(StatusCode(500, ex.Message));
            }
        }
Esempio n. 7
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);
        }