コード例 #1
0
        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;
        }
コード例 #2
0
 private static void ValidateStorageSpace(StorageSpaceDb storageSpace)
 {
     if (storageSpace == null)
     {
         throw new AnabiEntityNotFoundException(Constants.NO_STORAGE_SPACES_FOUND);
     }
 }
コード例 #3
0
        public async Task ShouldReturnAStoargeSpaceForAsset()
        {
            var entity = await AddAssetToStorageSpace();

            var asset = new AssetDb {
                Id = entity.AssetId
            };

            context.Assets.Add(asset);
            var storageSpace = new StorageSpaceDb {
                Id = entity.StorageSpaceId, Address = new AddressDb {
                    County = new CountyDb()
                }
            };

            context.StorageSpaces.Add(storageSpace);
            context.SaveChanges();

            var queryHandler = new GetStorageSpaceAssetHandler(BasicNeeds);

            var query = new GetAssetStorageSpace()
            {
                AssetId = entity.AssetId
            };

            var expected = await queryHandler.Handle(query, CancellationToken.None);

            Assert.IsTrue(expected.Count > 0);
        }
コード例 #4
0
        public async Task <int> Handle(AddStorageSpace message, CancellationToken cancellationToken)
        {
            var newStorageSpace = new StorageSpaceDb()
            {
                Name = message.Name,
                StorageSpacesType = message.StorageSpaceType,
                UserCodeAdd       = UserCode(),
                AddedDate         = DateTime.Now
            };

            context.StorageSpaces.Add(newStorageSpace);

            await SetNewAddressToStorageSpace(message, newStorageSpace);

            await context.SaveChangesAsync();

            return(newStorageSpace.Id);
        }
コード例 #5
0
        private static void AdaugaSpatiiStocare(AnabiContext context)
        {
            var spatiiStocare = new StorageSpaceDb[]
            {
                new StorageSpaceDb()
                {
                    AddressId = 1,
                    Name      = "Spatiul de stocare 1"
                },
                new StorageSpaceDb()
                {
                    AddressId = 2,
                    Name      = "Spatiul de stocare 2"
                }
            };

            context.SpatiiStocare.AddRange(spatiiStocare);
            context.SaveChanges();
        }