Exemple #1
0
        public async Task WarehouseAdd()
        {
            var url       = GetHubApiBaseUrl() + "warehouses";
            var dataToAdd = new ManifestDescriptionCM()
            {
                Id   = Guid.NewGuid().ToString(),
                Name = "test envelope added by WarehouseAdd test",
            };

            var crateStorage = new CrateStorage(Fr8.Infrastructure.Data.Crates.Crate.FromContent(null, dataToAdd));

            await HttpPostAsync <CrateStorageDTO, object>(url, CrateStorageSerializer.Default.ConvertToDto(crateStorage));

            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                var user = uow.UserRepository
                           .GetQuery()
                           .FirstOrDefault(x => x.UserName == TestUserEmail);

                Assert.NotNull(user, "Could not find test user in the database.");

                var addedEnvelope = uow.MultiTenantObjectRepository.Query <ManifestDescriptionCM>(user.Id, x => x.Id == dataToAdd.Id).FirstOrDefault();

                Assert.NotNull(addedEnvelope, "Failed to add new record to Warehouse using API");

                uow.MultiTenantObjectRepository.Delete <ManifestDescriptionCM>(user.Id, x => x.Id == dataToAdd.Id);

                Assert.AreEqual(dataToAdd.Name, addedEnvelope.Name, "Invalid value of Name property for stored data");
            }
        }
        public IHttpActionResult Post(ManifestDescriptionDTO description)
        {
            ManifestDescriptionCM manifestDescription = Mapper.Map <ManifestDescriptionCM>(description);

            manifestDescription.Id = NextId();
            var systemUserAccount = _fr8Account.GetSystemUser();

            if (systemUserAccount == null)
            {
                return(BadRequest("System Account is Missing"));
            }

            using (var uow = _uowFactory.Create())
            {
                uow.MultiTenantObjectRepository.Add(manifestDescription, systemUserAccount.UserName);

                uow.SaveChanges();
            }

            var model = Mapper.Map <ManifestDescriptionDTO>(manifestDescription);

            return(Ok(model));
        }