Esempio n. 1
0
        //GET: api/complex/{complexId}
        public async Task <ActionResult <ApiComplex> > GetComplexByIdAsync([FromRoute] Guid complexId)
        {
            try
            {
                var lcomplex = await _complexRepository.ReadComplexByIdAsync(complexId);

                _log.LogInformation("a complex with Id: {complexId} was found", complexId);

                var aId     = lcomplex.AddressId;
                var address = await _addressRequest.GetAddressAsync(aId);

                var apiComplex = new ApiComplex
                {
                    ComplexId      = lcomplex.ComplexId,
                    Address        = address,
                    ProviderId     = lcomplex.ProviderId,
                    ComplexName    = lcomplex.ComplexName,
                    ContactNumber  = lcomplex.ContactNumber,
                    ComplexAmenity = await _complexRepository.ReadAmenityListByComplexIdAsync(lcomplex.ComplexId)
                };
                _log.LogInformation("a list of amenities for complex Id {lcomplex.ComplexId} was found!", lcomplex.ComplexId);

                return(Ok(apiComplex));
            }
            catch (Exception ex)
            {
                _log.LogError("{ex}: Internal Server Error", ex);
                return(StatusCode(500, ex.Message));
            }
        }
Esempio n. 2
0
        public void ApiComplexTest()
        {
            var aId = Guid.NewGuid();
            var pId = Guid.NewGuid();

            var complex = new ApiComplex
            {
                ComplexId     = aId,
                ComplexName   = "Test",
                ContactNumber = "1234567890",
                ProviderId    = pId
            };

            Assert.Equal(aId, complex.ComplexId);
            Assert.Equal(pId, complex.ProviderId);
            Assert.Equal("Test", complex.ComplexName);
            Assert.Equal("1234567890", complex.ContactNumber);
        }
Esempio n. 3
0
        //GET: api/complex/Getallcomplex
        public async Task <ActionResult <IEnumerable <ApiComplex> > > GetAllComplexAsync()
        {
            try
            {
                var complices = await _complexRepository.ReadComplexListAsync();

                var apiComplices = new List <ApiComplex>();

                //foreach complex, get address from address service
                //create Apicomplex object for each complex we have
                //return them.
                foreach (var com in complices)
                {
                    var aId     = com.AddressId;
                    var address = await _addressRequest.GetAddressAsync(aId);

                    var complex = new ApiComplex
                    {
                        ComplexId      = com.ComplexId,
                        Address        = address,
                        ProviderId     = com.ProviderId,
                        ComplexName    = com.ComplexName,
                        ContactNumber  = com.ContactNumber,
                        ComplexAmenity = await _complexRepository.ReadAmenityListByComplexIdAsync(com.ComplexId)
                    };
                    _log.LogInformation("a list of amenities for complex Id {com.ComplexId} were found!", com.ComplexId);
                    apiComplices.Add(complex);
                }

                return(Ok(apiComplices));
            }
            catch (Exception ex)
            {
                _log.LogError("{ex}: Internal Server Error", ex);
                return(StatusCode(500, ex.Message));
            }
        }
Esempio n. 4
0
        //GET: api/complex/provierId/{providerID}
        public async Task <ActionResult <IEnumerable <ApiComplex> > > GetComplexListByProviderId([FromRoute] Guid providerId)
        {
            try
            {
                var complices = await _complexRepository.ReadComplexByProviderIdAsync(providerId);

                _log.LogInformation("a list of complices for provider Id: {providerId} were found", providerId);

                var apiComplices = new List <ApiComplex>();

                foreach (var complex in complices)
                {
                    var aId     = complex.AddressId;
                    var address = await _addressRequest.GetAddressAsync(aId);

                    var apiComplextoAdd = new ApiComplex
                    {
                        ComplexId      = complex.ComplexId,
                        Address        = address,
                        ProviderId     = complex.ProviderId,
                        ComplexName    = complex.ComplexName,
                        ContactNumber  = complex.ContactNumber,
                        ComplexAmenity = await _complexRepository.ReadAmenityListByComplexIdAsync(complex.ComplexId)
                    };
                    _log.LogInformation("a list of amenities for complex Id {complex.ComplexId} was found!", complex.ComplexId);

                    apiComplices.Add(apiComplextoAdd);
                }

                return(Ok(apiComplices));
            }
            catch (Exception ex)
            {
                _log.LogError("{ex}: Internal Server Error", ex);
                return(StatusCode(500, ex.Message));
            }
        }
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);
        }