Beispiel #1
0
        public async Task <AddressViewModel> Handle(AddAssetAddress message, CancellationToken cancellationToken)
        {
            var address = new AddressDb()
            {
                CountyId    = message.CountyId,
                Street      = message.Street,
                City        = message.City,
                Building    = message.Building,
                Description = message.Description,
                UserCodeAdd = UserCode(),
                AddedDate   = DateTime.Now
            };

            var asset = await context.Assets.FindAsync(message.AssetId);

            var county = await context.Counties.FindAsync(message.CountyId);

            asset.Address = address;

            context.Addresses.Add(address);
            await context.SaveChangesAsync(cancellationToken);

            var response = mapper.Map <AddAssetAddress, AddressViewModel>(message);

            response.CountyName        = county.Name;
            response.CountyAbreviation = county.Abreviation;
            response.Id      = address.Id;
            response.Journal = new JournalViewModel
            {
                UserCodeAdd = address.UserCodeAdd,
                AddedDate   = address.AddedDate,
            };

            return(response);
        }
Beispiel #2
0
        protected void CreateAddress_Click(object sender, EventArgs e)
        {
            Address newAddress = new Address();

            newAddress.AddressId     = System.Guid.NewGuid().ToString().ToUpper();
            newAddress.UserId        = User.Identity.GetUserId();
            newAddress.StreetAddress = txtStreetAddress.Text;
            newAddress.Type          = ddlAddressType.SelectedValue;
            newAddress.Number        = txtSuiteNumber.Text;
            newAddress.City          = txtCity.Text;
            newAddress.PostalCode    = txtPostalCode.Text;
            newAddress.Region        = ddlRegion.SelectedValue;
            newAddress.Country       = ddlCountry.Text;

            // Store into DB
            AddressDb.InsertAddress(newAddress);

            // Refresh GridView
            GridView1.DataBind();

            // Clear Values from Form
            txtStreetAddress.Text        = "";
            ddlAddressType.SelectedIndex = 0;
            txtSuiteNumber.Text          = "";
            txtCity.Text            = "";
            txtPostalCode.Text      = "";
            ddlRegion.SelectedIndex = 0;
            ddlCountry.Text         = "";
        }
        private async Task SetNewAddressToStorageSpace(IAddMinimalAddress message, StorageSpaceDb storageSpace)
        {
            AddressDb address = new AddressDb();

            /*
             * Edit address of a storage space
             */
            if (storageSpace.AddressId > 0)
            {
                address = await this.context.Addresses.FindAsync(storageSpace.AddressId);

                this.mapper.Map(message, address);
                address.LastChangeDate     = DateTime.Now;
                address.UserCodeLastChange = UserCode();
            }
            else
            {
                address.City        = message.City;
                address.Street      = message.Street;
                address.Description = message.Details;
                address.Building    = message.Building;
                address.UserCodeAdd = UserCode();
                address.AddedDate   = DateTime.Now;
            }

            var countyCode = message.CountyCode.ToUpperInvariant();

            address.County       = context.Counties.SingleOrDefault(x => x.Abreviation == countyCode);
            storageSpace.Address = address;
        }
        public async Task DeleteAsync(int id)
        {
            var toDelete = new AddressDb {
                Id = id
            };

            Context.Remove(toDelete);
            await Context.SaveChangesAsync();
        }
        public async Task <AddressDb> UpdateAsync(AddressDb addressDb)
        {
            if (addressDb == null)
            {
                throw new ArgumentNullException(nameof(addressDb));
            }

            Context.Update(addressDb);
            await Context.SaveChangesAsync();

            return(addressDb);
        }
Beispiel #6
0
        public async Task GivenTwoAddressesInDatabase_WhenIGetById_ItReturnsTheCorrectAddress()
        {
            using (var context = new DefaultContext(DbContextOptions))
            {
                var addressRepository = new AddressRepository(context);

                await addressRepository.CreateAsync(GetNewAddress());

                await addressRepository.CreateAsync(GetNewAddress());

                AddressDb address = await context.Addresses.FindAsync(2);

                Assert.AreEqual(2, address.Id);
            };
        }
Beispiel #7
0
        private static void AdaugaAdrese(AnabiContext context)
        {
            var adrese = new AddressDb[]
            {
                new AddressDb()
                {
                    Street = "Pantelimon nr 23", Building = "Bloc 1", CountyId = 1, City = "Bucuresti"
                },
                new AddressDb()
                {
                    Street = "Iancului 22", Building = "Blco 102S", CountyId = 1, City = "Bucuresti"
                },
                new AddressDb()
                {
                    Street = "O strada 22", Building = "Bloc 13", CountyId = 3, City = "Constanta"
                }
            };

            context.Adrese.AddRange(adrese);
            context.SaveChanges();
        }
 public Address ToConvert(AddressDb address)
 {
     return(Address.Create(address.Street, address.Number, address.Zipcode, address.Coutry, address.Street, address.Latitude, address.Longitude));
 }