Ejemplo n.º 1
0
        internal IResult Execute(CompanyKey brokerKey, CustomerKey customerKey)
        {
            if (brokerKey == null)
            {
                throw new ArgumentNullException("brokerKey");
            }
            if (customerKey == null)
            {
                throw new ArgumentNullException("customerKey");
            }

            var broker = _companyUnitOfWork.CompanyRepository.FindByKey(brokerKey, c => c.CompanyTypes);

            if (broker == null)
            {
                return(new InvalidResult(string.Format(UserMessages.CompanyNotFound, brokerKey.KeyValue)));
            }
            if (broker.CompanyTypes.All(t => t.CompanyTypeEnum != CompanyType.Broker))
            {
                return(new InvalidResult(string.Format(UserMessages.CompanyNotOfType, brokerKey.KeyValue, CompanyType.Broker)));
            }

            var customer = _companyUnitOfWork.CustomerRepository.FindByKey(customerKey);

            if (customer == null)
            {
                return(new InvalidResult(string.Format(UserMessages.CustomerNotFound, customerKey.KeyValue)));
            }

            customer.Broker   = broker;
            customer.BrokerId = broker.Id;

            return(new SuccessResult());
        }
            public void Returns_non_succesful_result_if_any_Items_received_have_a_Quantity_not_greater_than_0()
            {
                //Arrange
                var chileProductKey = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var dehydratorKey   = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                var packagingProductKey0  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var warehouseLocationKey0 = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    UserToken       = TestUser.UserName,
                    DateReceived    = new DateTime(2012, 3, 29),
                    ChileProductKey = chileProductKey,
                    SupplierKey     = dehydratorKey,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = 0,
                            Variety             = "variety",
                            PackagingProductKey = packagingProductKey0.KeyValue,
                            LocationKey         = warehouseLocationKey0.KeyValue
                        }
                    }
                });

                //Assert
                result.AssertNotSuccess(UserMessages.QuantityNotGreaterThanZero);
            }
        internal static IResult <ReceiveInventoryParameters> ToParsedParameters(this IReceiveInventoryParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var productKeyResult = KeyParserHelper.ParseResult <IProductKey>(parameters.ProductKey);

            if (!productKeyResult.Success)
            {
                return(productKeyResult.ConvertTo <ReceiveInventoryParameters>());
            }
            var productKey = productKeyResult.ResultingObject.ToProductKey();

            PackagingProductKey packagingKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.PackagingReceivedKey))
            {
                var packagingKeyResult = KeyParserHelper.ParseResult <IPackagingProductKey>(parameters.PackagingReceivedKey);
                if (!packagingKeyResult.Success)
                {
                    return(packagingKeyResult.ConvertTo <ReceiveInventoryParameters>());
                }
                packagingKey = packagingKeyResult.ResultingObject.ToPackagingProductKey();
            }

            CompanyKey vendorKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.VendorKey))
            {
                var vendorKeyResult = KeyParserHelper.ParseResult <ICompanyKey>(parameters.VendorKey);
                if (!vendorKeyResult.Success)
                {
                    return(vendorKeyResult.ConvertTo <ReceiveInventoryParameters>());
                }
                vendorKey = vendorKeyResult.ResultingObject.ToCompanyKey();
            }

            var items = new List <ReceiveInventoryItemParameters>();

            foreach (var item in parameters.Items)
            {
                var parsedItem = item.ToParsedParameters();
                if (!parsedItem.Success)
                {
                    return(parsedItem.ConvertTo <ReceiveInventoryParameters>());
                }
                items.Add(parsedItem.ResultingObject);
            }

            return(new SuccessResult <ReceiveInventoryParameters>(new ReceiveInventoryParameters
            {
                Parameters = parameters,
                ProductKey = productKey,
                PackagingReceivedKey = packagingKey,
                VendorKey = vendorKey,
                Items = items
            }));
        }
Ejemplo n.º 4
0
        public IResult <IEnumerable <ICompanySummaryReturn> > GetCustomersForBroker(string brokerKey)
        {
            if (brokerKey == null)
            {
                throw new ArgumentNullException("brokerKey");
            }

            var keyResult = KeyParserHelper.ParseResult <ICompanyKey>(brokerKey);

            if (!keyResult.Success)
            {
                return(keyResult.ConvertTo <IEnumerable <ICompanySummaryReturn> >());
            }
            var parsedBrokerKey = new CompanyKey(keyResult.ResultingObject);

            var broker = _inventoryShipmentOrderUnitOfWork.CompanyRepository.FindByKey(parsedBrokerKey, c => c.CompanyTypes);

            if (broker == null)
            {
                return(new InvalidResult <IEnumerable <ICompanySummaryReturn> >(null, string.Format(UserMessages.CompanyNotFound, brokerKey)));
            }
            if (broker.CompanyTypes.All(t => t.CompanyTypeEnum != CompanyType.Broker))
            {
                return(new InvalidResult <IEnumerable <ICompanySummaryReturn> >(null, string.Format(UserMessages.CompanyNotOfType, brokerKey, CompanyType.Broker)));
            }

            var predicate = CustomerPredicates.ByBroker(parsedBrokerKey);
            var select    = CustomerProjectors.SelectCompanySummary();

            var customers = _inventoryShipmentOrderUnitOfWork.CustomerRepository.Filter(predicate).AsExpandable().Select(select).ToList();

            return(new SuccessResult <IEnumerable <ICompanySummaryReturn> >(customers));
        }
Ejemplo n.º 5
0
        internal IResult <Data.Models.Company> Execute(ICompanyKey companyKey, CompanyType?companyType = null)
        {
            if (companyKey == null)
            {
                throw new ArgumentNullException("companyKey");
            }
            var parsedKey = new CompanyKey(companyKey);

            var company = _companyUnitOfWork.CompanyRepository.FindByKey(parsedKey, c => c.CompanyTypes);

            if (company == null)
            {
                return(new InvalidResult <Data.Models.Company>(null, string.Format(UserMessages.CompanyNotFound, parsedKey)));
            }

            if (companyType != null)
            {
                if (company.CompanyTypes.All(t => t.CompanyTypeEnum != companyType))
                {
                    return(new InvalidResult <Data.Models.Company>(null, string.Format(UserMessages.CompanyNotOfType, companyKey, companyType)));
                }
            }

            return(new SuccessResult <Data.Models.Company>(company));
        }
Ejemplo n.º 6
0
            public void Returns_only_Contacts_of_specified_Company()
            {
                //Arrange
                const int expectedContacts = 3;

                var companyKey = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.EmptyItems()));
                var contact0   = TestHelper.CreateObjectGraphAndInsertIntoDatabase <Contact>(c => c.ConstrainByKeys(companyKey));
                var contact1   = TestHelper.CreateObjectGraphAndInsertIntoDatabase <Contact>(c => c.ConstrainByKeys(companyKey));
                var contact2   = TestHelper.CreateObjectGraphAndInsertIntoDatabase <Contact>(c => c.ConstrainByKeys(companyKey));

                TestHelper.CreateObjectGraphAndInsertIntoDatabase <Contact>();
                TestHelper.CreateObjectGraphAndInsertIntoDatabase <Contact>();
                TestHelper.CreateObjectGraphAndInsertIntoDatabase <Contact>();

                //Act
                var result = Service.GetContacts(new FilterContactsParameters {
                    CompanyKey = companyKey.KeyValue
                });

                //Assert
                result.AssertSuccess();
                var results = result.ResultingObject.ToList();

                Assert.AreEqual(expectedContacts, results.Count);

                contact0.AssertEqual(results.Single(r => new ContactKey(contact0).KeyValue == r.ContactKey));
                contact1.AssertEqual(results.Single(r => new ContactKey(contact1).KeyValue == r.ContactKey));
                contact2.AssertEqual(results.Single(r => new ContactKey(contact2).KeyValue == r.ContactKey));
            }
Ejemplo n.º 7
0
            public void Creates_new_Contact_record_with_no_Addresses()
            {
                //Arrange
                const string expectedName  = "Batman";
                const string expectedPhone = "batsignal";
                const string expectedEmail = "*****@*****.**";

                var company    = TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.Contacts = null);
                var companyKey = new CompanyKey(company);



                //Act
                var result = Service.CreateContact(new CreateContactParameters
                {
                    CompanyKey   = companyKey.KeyValue,
                    Name         = expectedName,
                    PhoneNumber  = expectedPhone,
                    EmailAddress = expectedEmail,
                });

                //Assert
                result.AssertSuccess();
                var contact = RVCUnitOfWork.ContactRepository.Filter(c => true, c => c.Addresses).Single();

                Assert.IsEmpty(contact.Addresses);
                Assert.AreEqual(companyKey, contact);
                Assert.AreEqual(expectedName, contact.Name);
                Assert.AreEqual(expectedPhone, contact.PhoneNumber);
                Assert.AreEqual(expectedEmail, contact.EMailAddress);
            }
Ejemplo n.º 8
0
            public void Sets_CompanyTypeRecords_as_expected()
            {
                //Arrange
                var companyKey    = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Broker, CompanyType.Dehydrator)));
                var expectedTypes = new List <CompanyType>
                {
                    CompanyType.Dehydrator,
                    CompanyType.Freight,
                    CompanyType.Supplier
                };

                //Act
                var result = Service.UpdateCompany(new Parameters
                {
                    UserToken    = TestUser.UserName,
                    CompanyKey   = companyKey.KeyValue,
                    CompanyTypes = expectedTypes
                });

                //Assert
                result.AssertSuccess();
                var companyTypes = RVCUnitOfWork.CompanyRepository.FindByKey(companyKey, c => c.CompanyTypes).CompanyTypes.ToList();

                Assert.AreEqual(expectedTypes.Count, companyTypes.Count);
                expectedTypes.ForEach(e => Assert.IsTrue(companyTypes.Count(t => t.CompanyTypeEnum == e) == 1));
            }
Ejemplo n.º 9
0
        private IResult SetCustomerRecord(Data.Models.Company company, CompanyKey brokerKey)
        {
            if (company == null)
            {
                throw new ArgumentNullException("company");
            }

            var customer = CompanyUnitOfWork.CustomerRepository.FindByKey(new CustomerKey(company));

            if (company.CompanyTypes.Any(t => t.CompanyTypeEnum == CompanyType.Customer))
            {
                if (customer == null)
                {
                    customer = CompanyUnitOfWork.CustomerRepository.Add(new Data.Models.Customer
                    {
                        Id      = company.Id,
                        Company = company,
                    });
                }

                var setBrokerResult = SetCustomerBroker(customer, brokerKey);
                if (!setBrokerResult.Success)
                {
                    return(setBrokerResult);
                }
            }

            return(new SuccessResult());
        }
Ejemplo n.º 10
0
        internal static IResult <CreateCompanyCommandParameters> ToParsedParameters(this ICreateCompanyParameters createCompanyParameters)
        {
            if (createCompanyParameters == null)
            {
                throw new ArgumentNullException("createCompanyParameters");
            }

            CompanyKey brokerKey = null;

            if (!string.IsNullOrEmpty(createCompanyParameters.BrokerKey))
            {
                var brokerKeyResult = KeyParserHelper.ParseResult <ICompanyKey>(createCompanyParameters.BrokerKey);
                if (!brokerKeyResult.Success)
                {
                    return(brokerKeyResult.ConvertTo <CreateCompanyCommandParameters>());
                }
                brokerKey = brokerKeyResult.ResultingObject.ToCompanyKey();
            }

            if (createCompanyParameters.CompanyTypes == null || !createCompanyParameters.CompanyTypes.Any())
            {
                return(new InvalidResult <CreateCompanyCommandParameters>(null, UserMessages.CompanyTypesRequired));
            }

            return(new SuccessResult <CreateCompanyCommandParameters>(new CreateCompanyCommandParameters
            {
                Parameters = createCompanyParameters,
                BrokerKey = brokerKey
            }));
        }
Ejemplo n.º 11
0
            public void Creates_new_Contact_record_as_expected_on_success()
            {
                //Arrange
                const string expectedName  = "Batman";
                const string expectedPhone = "batsignal";
                const string expectedEmail = "*****@*****.**";

                const string expectedAddressLine1 = "Big ol' mansion.";
                const string expectedAddressLine2 = "I dunno some cave I guess.";

                const string addressDescription1 = "Some Address";
                const string addressDescription2 = "Some Other Address";

                var company    = TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.Contacts = null);
                var companyKey = new CompanyKey(company);



                //Act
                var result = Service.CreateContact(new CreateContactParameters
                {
                    CompanyKey   = companyKey.KeyValue,
                    Name         = expectedName,
                    PhoneNumber  = expectedPhone,
                    EmailAddress = expectedEmail,
                    Addresses    = new List <IContactAddressReturn>
                    {
                        new ContactAddressParameters
                        {
                            AddressDescription = addressDescription1,
                            Address            = new Address {
                                AddressLine1 = expectedAddressLine1
                            }
                        },
                        new ContactAddressParameters
                        {
                            AddressDescription = addressDescription2,
                            Address            = new Address {
                                AddressLine1 = expectedAddressLine2
                            }
                        }
                    }
                });

                //Assert
                result.AssertSuccess();
                var contact   = RVCUnitOfWork.ContactRepository.Filter(c => true, c => c.Addresses).Single();
                var addresses = contact.Addresses.ToList();

                Assert.AreEqual(companyKey, contact);
                Assert.AreEqual(expectedName, contact.Name);
                Assert.AreEqual(expectedPhone, contact.PhoneNumber);
                Assert.AreEqual(expectedEmail, contact.EMailAddress);
                Assert.IsNotNull(addresses.Single(a => a.AddressDescription == addressDescription1 && a.Address.AddressLine1 == expectedAddressLine1));
                Assert.IsNotNull(addresses.Single(a => a.AddressDescription == addressDescription2 && a.Address.AddressLine1 == expectedAddressLine2));
            }
            public void Creates_DehydratedMaterialsReceived_record_as_expected_on_success()
            {
                //Arrange
                var          expectedLotDate         = new DateTime(2012, 3, 29);
                const int    expectedLotDateSequence = 1;
                const int    expectedLotTypeId       = (int)LotTypeEnum.DeHydrated;
                const string expectedLoad            = "123";
                const string expectedPurchaseOrder   = "MLAH!";
                const string expectedShipperNumber   = "1029384756";

                var chileProductKey     = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var packagingProductKey = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var locationKey         = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());
                var supplierKey         = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    ChileMaterialsReceivedType = ChileMaterialsReceivedType.Dehydrated,
                    UserToken       = TestUser.UserName,
                    DateReceived    = expectedLotDate,
                    ChileProductKey = chileProductKey,
                    SupplierKey     = supplierKey,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    LoadNumber      = expectedLoad,
                    PurchaseOrder   = expectedPurchaseOrder,
                    ShipperNumber   = expectedShipperNumber,
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = 10,
                            PackagingProductKey = packagingProductKey,
                            LocationKey         = locationKey,
                            Variety             = "Variety"
                        }
                    }
                });

                //Assert
                result.AssertSuccess();

                var received = RVCUnitOfWork.ChileMaterialsReceivedRepository.Filter(d => true, d => d.ChileLot.Lot, d => d.Items).Single();

                Assert.AreEqual(expectedLotDate, received.LotDateCreated);
                Assert.AreEqual(expectedLotDateSequence, received.LotDateSequence);
                Assert.AreEqual(expectedLotTypeId, received.LotTypeId);

                Assert.AreEqual(expectedLoad, received.LoadNumber);
                Assert.AreEqual(expectedPurchaseOrder, received.ChileLot.Lot.PurchaseOrderNumber);
                Assert.AreEqual(expectedShipperNumber, received.ChileLot.Lot.ShipperNumber);

                Assert.IsNotNull(received.ChileLot);
                Assert.IsNotNull(received.Items.SingleOrDefault());
            }
Ejemplo n.º 13
0
        /// ----------------------------------------------------------------------------------------
        /// <summary>
        /// Returns a subkey of HKCU\Software using the company name (Application.CompanyName) and
        /// the product name (Application.ProductName).
        /// </summary>
        /// <param name="subKeys">Zero or more subkeys (e.g., a specific application name, project
        /// name, etc.)</param>
        /// ----------------------------------------------------------------------------------------
        public static RegistryKey SettingsKey(params string[] subKeys)
        {
            StringBuilder bldr = new StringBuilder();

            bldr.Append(ProductName).Append(@"\");
            foreach (string subKey in subKeys)
            {
                bldr.Append(subKey).Append(@"\");
            }
            return(CompanyKey.CreateSubKey(bldr.ToString()));
        }
Ejemplo n.º 14
0
            public void Returns_empty_collection_if_no_Contacts_of_supplied_Company_exist()
            {
                //Arrange
                var companyKey = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.EmptyItems()));

                //Act
                var result = Service.GetContacts(new FilterContactsParameters {
                    CompanyKey = companyKey.KeyValue
                });

                //Assert
                result.AssertSuccess();
                Assert.IsEmpty(result.ResultingObject);
            }
            public void Creates_a_single_Inventory_record_with_aggregate_Quantity_for_Items_received_that_reference_the_same_Packaging_WarehouseLocation()
            {
                //Arrange
                var       expectedLotDate         = new DateTime(2012, 3, 29);
                const int expectedLotDateSequence = 1;
                const int expectedLotTypeId       = (int)LotTypeEnum.DeHydrated;
                const int quantity0        = 10;
                const int quantity1        = 21;
                const int expectedQuantity = quantity0 + quantity1;

                var chileProductKey = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var dehydratorKey   = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                var packagingProductKey  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var warehouseLocationKey = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    UserToken       = TestUser.UserName,
                    DateReceived    = expectedLotDate,
                    ChileProductKey = chileProductKey.KeyValue,
                    SupplierKey     = dehydratorKey.KeyValue,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = quantity0,
                            Variety             = "Variety",
                            PackagingProductKey = packagingProductKey.KeyValue,
                            LocationKey         = warehouseLocationKey.KeyValue
                        },
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = quantity1,
                            Variety             = "Variety",
                            PackagingProductKey = packagingProductKey.KeyValue,
                            LocationKey         = warehouseLocationKey.KeyValue
                        }
                    }
                });

                //Assert
                result.AssertSuccess();

                var inventory = RVCUnitOfWork.InventoryRepository.All().Single(i => i.LotDateCreated == expectedLotDate && i.LotDateSequence == expectedLotDateSequence && i.LotTypeId == expectedLotTypeId);

                Assert.AreEqual(expectedQuantity, inventory.Quantity);
            }
        internal IResult Execute(CompanyKey brokerKey, CustomerKey customerKey)
        {
            if (brokerKey == null)
            {
                throw new ArgumentNullException("brokerKey");
            }
            if (customerKey == null)
            {
                throw new ArgumentNullException("customerKey");
            }

            var broker = _companyUnitOfWork.CompanyRepository.FindByKey(brokerKey, c => c.CompanyTypes);

            if (broker == null)
            {
                return(new InvalidResult(string.Format(UserMessages.CompanyNotFound, brokerKey.KeyValue)));
            }
            if (broker.CompanyTypes.All(t => t.CompanyTypeEnum != CompanyType.Broker))
            {
                return(new InvalidResult(string.Format(UserMessages.CompanyNotOfType, brokerKey.KeyValue, CompanyType.Broker)));
            }

            var customer = _companyUnitOfWork.CustomerRepository.FindByKey(customerKey, c => c.Broker);

            if (customer == null)
            {
                return(new InvalidResult(string.Format(UserMessages.CustomerNotFound, customerKey.KeyValue)));
            }

            if (!brokerKey.Equals(new CompanyKey(customer.Broker)))
            {
                return(new InvalidResult(string.Format(UserMessages.CustomerNotOfBroker, customerKey.KeyValue, brokerKey.KeyValue)));
            }

            var rvcBroker = _companyUnitOfWork.CompanyRepository.Filter(c => c.Name == Data.Models.StaticRecords.StaticCompanies.RVCBroker.Name).FirstOrDefault();

            if (rvcBroker == null)
            {
                throw new Exception("Default RVC Broker Company not found.");
            }

            customer.Broker   = rvcBroker;
            customer.BrokerId = rvcBroker.Id;

            return(new SuccessResult());
        }
Ejemplo n.º 17
0
            public void Returns_non_successful_result_if_no_CompanyTypes_are_supplied()
            {
                //Arrange
                var companyKey = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>());

                //Act
                var resultNull = Service.UpdateCompany(new Parameters
                {
                    CompanyKey   = companyKey.KeyValue,
                    CompanyTypes = null
                });
                var resultEmpty = Service.UpdateCompany(new Parameters
                {
                    CompanyKey   = companyKey.KeyValue,
                    CompanyTypes = new List <CompanyType>()
                });

                //Assert
                resultNull.AssertNotSuccess(UserMessages.CompanyTypesRequired);
                resultEmpty.AssertNotSuccess(UserMessages.CompanyTypesRequired);
            }
            public void Creates_Lot_record_with_LotProductionStatus_set_to_Produced()
            {
                //Arrange
                var chileProductKey      = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var packagingProductKey  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var warehouseLocationKey = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());
                var dehydratorKey        = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    UserToken       = TestUser.UserName,
                    DateReceived    = new DateTime(2012, 3, 29),
                    ChileProductKey = chileProductKey,
                    SupplierKey     = dehydratorKey,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    LoadNumber      = "123",
                    PurchaseOrder   = "MLAH!",
                    ShipperNumber   = "1029384756",
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = 10,
                            PackagingProductKey = packagingProductKey.KeyValue,
                            LocationKey         = warehouseLocationKey.KeyValue,
                            Variety             = "Variety"
                        }
                    }
                });

                //Assert
                result.AssertSuccess();

                var dehydratedReceived = RVCUnitOfWork.ChileMaterialsReceivedRepository.Filter(d => true, d => d.ChileLot.Lot, d => d.Items).Single();

                Assert.AreEqual(LotProductionStatus.Produced, dehydratedReceived.ChileLot.Lot.ProductionStatus);
            }
            public void Returns_successful_result_if_ProductionDate_has_a_time_component_and_a_Lot_exists_with_the_same_Date_Type_and_a_Sequence_of_1()
            {
                //Arrange
                var productionDate = new DateTime(2012, 4, 1, 10, 30, 21);

                TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileLot>(c => c.LotDateCreated = productionDate, c => c.LotDateSequence = 1, c => c.LotTypeId = (int)LotTypeEnum.DeHydrated);

                var chileProductKey      = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var packagingProductKey  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var warehouseLocationKey = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());
                var dehydratorKey        = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    UserToken       = TestUser.UserName,
                    DateReceived    = productionDate,
                    ChileProductKey = chileProductKey,
                    SupplierKey     = dehydratorKey,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    LoadNumber      = "123",
                    PurchaseOrder   = "POPO",
                    ShipperNumber   = "1029384756",
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = 10,
                            PackagingProductKey = packagingProductKey.KeyValue,
                            LocationKey         = warehouseLocationKey.KeyValue,
                            Variety             = "variety"
                        }
                    }
                });

                //Assert
                result.AssertSuccess();
            }
Ejemplo n.º 20
0
        public static Expression <Func <SampleOrder, bool> > ByBroker(CompanyKey brokerKey)
        {
            var brokerPredicate = brokerKey.FindByPredicate;

            return(o => new[] { o.Broker }.Where(c => c != null).Any(c => brokerPredicate.Invoke(c)));
        }
Ejemplo n.º 21
0
        private IResult <Data.Models.Customer> SetCustomerBroker(Data.Models.Customer customer, CompanyKey brokerKey)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            Data.Models.Company broker;
            if (brokerKey == null)
            {
                broker = CompanyUnitOfWork.CompanyRepository.Filter(c => c.Name == StaticCompanies.RVCBroker.Name).FirstOrDefault();
                if (broker == null)
                {
                    throw new Exception("Default RVC Broker Company not found.");
                }
            }
            else
            {
                var brokerResult = new GetCompanyCommand(CompanyUnitOfWork).Execute(brokerKey, CompanyType.Broker);
                if (!brokerResult.Success)
                {
                    return(brokerResult.ConvertTo <Data.Models.Customer>());
                }

                broker = brokerResult.ResultingObject;
            }

            customer.BrokerId = broker.Id;

            return(new SuccessResult <Data.Models.Customer>(customer));
        }
Ejemplo n.º 22
0
        private IResult SetCompanyTypes(Data.Models.Company company, IEnumerable <CompanyType> companyTypes, CompanyKey brokerKey)
        {
            if (company == null)
            {
                throw new ArgumentNullException("company");
            }

            company.CompanyTypes = company.CompanyTypes ?? new List <CompanyTypeRecord>();
            var setTypes      = companyTypes == null ? new List <CompanyType>() : companyTypes.Distinct().ToList();
            var typesToRemove = company.CompanyTypes.Where(t => !setTypes.Contains(t.CompanyTypeEnum)).ToList();

            setTypes.Where(t => company.CompanyTypes.All(e => e.CompanyTypeEnum != t)).Select(t => new CompanyTypeRecord
            {
                CompanyId       = company.Id,
                CompanyTypeEnum = t
            }).ToList().ForEach(n => company.CompanyTypes.Add(n));;
            typesToRemove.ForEach(t => company.CompanyTypes.Remove(t));

            var setCustomerRecordResult = SetCustomerRecord(company, brokerKey);

            if (!setCustomerRecordResult.Success)
            {
                return(setCustomerRecordResult);
            }

            return(new SuccessResult());
        }
Ejemplo n.º 23
0
        internal static IResult <SetSampleOrderParameters> ToParsedParameters(this ISetSampleOrderParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            SampleOrderKey sampleOrderKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.SampleOrderKey))
            {
                var sampleOrderKeyResult = KeyParserHelper.ParseResult <ISampleOrderKey>(parameters.SampleOrderKey);
                if (!sampleOrderKeyResult.Success)
                {
                    return(sampleOrderKeyResult.ConvertTo <SetSampleOrderParameters>());
                }

                sampleOrderKey = sampleOrderKeyResult.ResultingObject.ToSampleOrderKey();
            }

            CustomerKey requestCustomerKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.RequestedByCompanyKey))
            {
                var customerKeyResult = KeyParserHelper.ParseResult <ICustomerKey>(parameters.RequestedByCompanyKey);
                if (!customerKeyResult.Success)
                {
                    return(customerKeyResult.ConvertTo <SetSampleOrderParameters>());
                }

                requestCustomerKey = customerKeyResult.ResultingObject.ToCustomerKey();
            }

            CompanyKey brokerKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.BrokerKey))
            {
                var companyKey = KeyParserHelper.ParseResult <ICompanyKey>(parameters.BrokerKey);
                if (!companyKey.Success)
                {
                    return(companyKey.ConvertTo <SetSampleOrderParameters>());
                }

                brokerKey = companyKey.ResultingObject.ToCompanyKey();
            }

            var itemParameters = parameters.Items.ToParsedParameters(ToParsedParameters);

            if (!itemParameters.Success)
            {
                return(itemParameters.ConvertTo <SetSampleOrderParameters>());
            }

            return(new SuccessResult <SetSampleOrderParameters>(new SetSampleOrderParameters
            {
                Parameters = parameters,
                SampleOrderKey = sampleOrderKey,
                RequestCustomerKey = requestCustomerKey,
                BrokerKey = brokerKey,

                Items = itemParameters.ResultingObject
            }));
        }
        internal static IResult <SalesQuoteParameters> ToParsedParameters(this ISalesQuoteParameters parameters, bool updateExisting)
        {
            if (updateExisting && parameters.SalesQuoteNumber == null)
            {
                return(new InvalidResult <SalesQuoteParameters>(null, UserMessages.SalesQuoteNumberRequired));
            }

            FacilityKey sourceFacilityKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.SourceFacilityKey))
            {
                var sourceFacilityKeyResult = KeyParserHelper.ParseResult <IFacilityKey>(parameters.SourceFacilityKey);
                if (!sourceFacilityKeyResult.Success)
                {
                    return(sourceFacilityKeyResult.ConvertTo <SalesQuoteParameters>());
                }
                sourceFacilityKey = sourceFacilityKeyResult.ResultingObject.ToFacilityKey();
            }

            CustomerKey customerKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.CustomerKey))
            {
                var customerKeyResult = KeyParserHelper.ParseResult <ICustomerKey>(parameters.CustomerKey);
                if (!customerKeyResult.Success)
                {
                    return(customerKeyResult.ConvertTo <SalesQuoteParameters>());
                }
                customerKey = customerKeyResult.ResultingObject.ToCustomerKey();
            }

            CompanyKey brokerKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.BrokerKey))
            {
                var brokerKeyResult = KeyParserHelper.ParseResult <ICompanyKey>(parameters.BrokerKey);
                if (!brokerKeyResult.Success)
                {
                    return(brokerKeyResult.ConvertTo <SalesQuoteParameters>());
                }
                brokerKey = brokerKeyResult.ResultingObject.ToCompanyKey();
            }

            var itemParameters = new List <SalesQuoteItemParameters>();

            foreach (var item in parameters.Items ?? new ISalesQuoteItemParameters[0])
            {
                SalesQuoteItemKey itemKey = null;
                if (updateExisting && !string.IsNullOrWhiteSpace(item.SalesQuoteItemKey))
                {
                    var itemKeyResult = KeyParserHelper.ParseResult <ISalesQuoteItemKey>(item.SalesQuoteItemKey);
                    if (!itemKeyResult.Success)
                    {
                        return(itemKeyResult.ConvertTo <SalesQuoteParameters>());
                    }
                    itemKey = itemKeyResult.ResultingObject.ToSalesQuoteItemKey();
                }

                var productKeyResult = KeyParserHelper.ParseResult <IProductKey>(item.ProductKey);
                if (!productKeyResult.Success)
                {
                    return(productKeyResult.ConvertTo <SalesQuoteParameters>());
                }

                var packagingKeyResult = KeyParserHelper.ParseResult <IPackagingProductKey>(item.PackagingKey);
                if (!packagingKeyResult.Success)
                {
                    return(packagingKeyResult.ConvertTo <SalesQuoteParameters>());
                }

                var treatmentKeyResult = KeyParserHelper.ParseResult <IInventoryTreatmentKey>(item.TreatmentKey);
                if (!treatmentKeyResult.Success)
                {
                    return(treatmentKeyResult.ConvertTo <SalesQuoteParameters>());
                }

                itemParameters.Add(new SalesQuoteItemParameters
                {
                    Parameters            = item,
                    SalesQuoteItemKey     = itemKey,
                    ProductKey            = productKeyResult.ResultingObject.ToProductKey(),
                    PackagingProductKey   = packagingKeyResult.ResultingObject.ToPackagingProductKey(),
                    InventoryTreatmentKey = treatmentKeyResult.ResultingObject.ToInventoryTreatmentKey()
                });
            }

            return(new SuccessResult <SalesQuoteParameters>(new SalesQuoteParameters
            {
                Parameters = parameters,
                SalesQuoteNumber = updateExisting ? parameters.SalesQuoteNumber : null,
                SourceFacilityKey = sourceFacilityKey,
                CustomerKey = customerKey,
                BrokerKey = brokerKey,
                Items = itemParameters
            }));
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Returns a subkey of HKCU\Software using the company name (Application.CompanyName) and
 /// the product name (Application.ProductName).
 /// </summary>
 /// <param name="subKeys">Zero or more subkeys (e.g., a specific application name, project name, etc.)</param>
 public static RegistryKey SettingsKey(params string[] subKeys)
 {
     return(CompanyKey.CreateSubKey(GetSubkeyName(subKeys)));
 }
            public void Creates_Inventory_records_as_expected_on_success()
            {
                //Arrange
                var          expectedLotDate         = new DateTime(2012, 3, 29);
                const int    expectedLotDateSequence = 1;
                const int    expectedLotTypeId       = (int)LotTypeEnum.DeHydrated;
                const int    expectedItems           = 3;
                const int    quantity0   = 10;
                const int    quantity1   = 21;
                const int    quantity2   = 40001;
                const string toteKey0    = "tote0";
                const string toteKey1    = "tote-1";
                const string toteKey2    = "";
                const string varietyKey0 = "variety0";
                const string varietyKey1 = "variety1";

                var chileProductKey = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var dehydratorKey   = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                var packagingProductKey0  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var packagingProductKey1  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var warehouseLocationKey0 = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());
                var warehouseLocationKey1 = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    UserToken       = TestUser.UserName,
                    DateReceived    = expectedLotDate,
                    ChileProductKey = chileProductKey.KeyValue,
                    SupplierKey     = dehydratorKey.KeyValue,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = quantity0,
                            Variety             = varietyKey0,
                            PackagingProductKey = packagingProductKey0.KeyValue,
                            LocationKey         = warehouseLocationKey0.KeyValue,
                            ToteKey             = toteKey0
                        },
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = quantity1,
                            Variety             = varietyKey0,
                            PackagingProductKey = packagingProductKey1.KeyValue,
                            LocationKey         = warehouseLocationKey0.KeyValue,
                            ToteKey             = toteKey1
                        },
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = quantity2,
                            Variety             = varietyKey1,
                            PackagingProductKey = packagingProductKey0.KeyValue,
                            LocationKey         = warehouseLocationKey1.KeyValue,
                            ToteKey             = toteKey2
                        }
                    }
                });

                //Assert
                result.AssertSuccess();

                var inventory = RVCUnitOfWork.InventoryRepository.Filter(i => i.LotDateCreated == expectedLotDate && i.LotDateSequence == expectedLotDateSequence && i.LotTypeId == expectedLotTypeId).ToList();

                Assert.AreEqual(expectedItems, inventory.Count);

                var item = inventory.Single(i => i.Quantity == quantity0);

                Assert.IsTrue(packagingProductKey0.Equals(item));
                Assert.IsTrue(warehouseLocationKey0.Equals(item));
                Assert.IsTrue(NoTreatmentKey.Equals(item));
                Assert.AreEqual(toteKey0, item.ToteKey);

                item = inventory.Single(i => i.Quantity == quantity1);
                Assert.IsTrue(packagingProductKey1.Equals(item));
                Assert.IsTrue(warehouseLocationKey0.Equals(item));
                Assert.IsTrue(NoTreatmentKey.Equals(item));
                Assert.AreEqual(toteKey1, item.ToteKey);

                item = inventory.Single(i => i.Quantity == quantity2);
                Assert.IsTrue(packagingProductKey0.Equals(item));
                Assert.IsTrue(warehouseLocationKey1.Equals(item));
                Assert.IsTrue(NoTreatmentKey.Equals(item));
                Assert.AreEqual(toteKey2, item.ToteKey);
            }