Exemplo n.º 1
0
        public static List <AddressBookDto> FromAddressesDbEntityToAddressBookDto(List <Address> addresses)
        {
            var addressBookDtos = new List <AddressBookDto>();

            foreach (var address in addresses)
            {
                var addressBookDto = new AddressBookDto
                {
                    Company    = address.Company,
                    Email      = address.Email,
                    Name       = address.Name,
                    Surname    = address.Surname,
                    Phone      = address.Phone,
                    AddressDto = new AddressDto
                    {
                        AddressId = address.AddressId,
                        City      = address.City,
                        County    = address.County,
                        Postcode  = address.Postcode,
                        Street    = address.Street,
                        Updated   = address.Updated
                    }
                };

                addressBookDtos.Add(addressBookDto);
            }

            return(addressBookDtos);
        }
Exemplo n.º 2
0
        public static List <AddressBookDto> FromCsvAddressesToAddressBookDto(
            List <CsvAddressesReaderDtoDto> csvAddressesDto)
        {
            var addressBookDtos = new List <AddressBookDto>();

            foreach (var address in csvAddressesDto)
            {
                var addressBookDto = new AddressBookDto
                {
                    Company    = address.Company,
                    Email      = address.Email,
                    Name       = address.Name,
                    Surname    = address.Surname,
                    Phone      = address.Phone,
                    AddressDto = new AddressDto
                    {
                        AddressId = Guid.NewGuid(),
                        City      = address.City,
                        County    = address.County,
                        Postcode  = address.Postcode,
                        Street    = address.Street,
                        Updated   = DateTime.Now
                    }
                };

                addressBookDtos.Add(addressBookDto);
            }

            return(addressBookDtos);
        }
        public async Task <IActionResult> Create([FromBody] AddressBookDto model)
        {
            var modelForAdd = _Mapper.Map <AddressBook>(model);

            _Uow.AddressBooks.Add(modelForAdd);

            if (await _Uow.Save())
            {
                return(Ok(new { Status = true, Message = "Successfully Added" }));
            }
            return(BadRequest());
        }
        public async Task <IActionResult> Update([FromBody] AddressBookDto model)
        {
            var AddressToUpdate = await _Uow.AddressBooks.FirstOrDefault(p => p.Id == model.Id);

            if (AddressToUpdate == null)
            {
                return(NotFound("Could't Found This AddressBook"));
            }
            var modelForUpdate = _Mapper.Map <AddressBook>(model);

            _Uow.AddressBooks.Update(modelForUpdate);

            if (await _Uow.Save())
            {
                return(Ok(new { Status = true, Message = "Successfully Updated" }));
            }
            return(BadRequest());
        }
        public void GetAddressBook_CorrectAttributes_Success(int _clientId)
        {
            DatabaseQueryProcessor.Erase();
            Shared.FillTheDatabase();


            var firstAddress = new AddressDto
            {
                key             = 0,
                country         = "Poland",
                city            = "Gdynia",
                street          = "Rzemieslnicza",
                ZIPCode         = 30445,
                buildingNumber  = 12,
                apartmentNumber = "1a"
            };

            var secondAddress = new AddressDto
            {
                key             = 0,
                country         = "Poland",
                city            = "Warsaw",
                street          = "Grodzka",
                ZIPCode         = 25487,
                buildingNumber  = 23,
                apartmentNumber = ""
            };

            var testAddresses = new AddressDto[2];

            testAddresses[0] = firstAddress;
            testAddresses[1] = secondAddress;

            var expectedAddressBook = new AddressBookDto
            {
                isSuccess = true,
                addresses = testAddresses
            };

            var testSessionToken = SessionRepository.StartNewSession(_clientId);

            var getAddressBookQuery = new GetAddressBookQuery
            {
                sessionToken = testSessionToken,
            };

            var handler     = new GetAddressBookQueryHandler();
            var addressBook = (AddressBookDto)handler.Handle(getAddressBookQuery);

            DatabaseQueryProcessor.Erase();
            SessionRepository.RemoveSession(testSessionToken);

            Assert.AreEqual(expectedAddressBook.addresses.Length, addressBook.addresses.Length);

            Assert.AreEqual(expectedAddressBook.addresses[0].country, addressBook.addresses[0].country);
            Assert.AreEqual(expectedAddressBook.addresses[0].city, addressBook.addresses[0].city);
            Assert.AreEqual(expectedAddressBook.addresses[0].street, addressBook.addresses[0].street);
            Assert.AreEqual(expectedAddressBook.addresses[0].ZIPCode, addressBook.addresses[0].ZIPCode);
            Assert.AreEqual(expectedAddressBook.addresses[0].buildingNumber, addressBook.addresses[0].buildingNumber);
            Assert.AreEqual(expectedAddressBook.addresses[0].apartmentNumber, addressBook.addresses[0].apartmentNumber);

            Assert.AreEqual(expectedAddressBook.addresses[1].country, addressBook.addresses[1].country);
            Assert.AreEqual(expectedAddressBook.addresses[1].city, addressBook.addresses[1].city);
            Assert.AreEqual(expectedAddressBook.addresses[1].street, addressBook.addresses[1].street);
            Assert.AreEqual(expectedAddressBook.addresses[1].ZIPCode, addressBook.addresses[1].ZIPCode);
            Assert.AreEqual(expectedAddressBook.addresses[1].buildingNumber, addressBook.addresses[1].buildingNumber);
            Assert.AreEqual(expectedAddressBook.addresses[1].apartmentNumber, addressBook.addresses[1].apartmentNumber);
        }