Exemple #1
0
        private Error validateModel(FreightForwarderModel model)
        {
            var error = isValidRequiredInt(model.CompanyId, "CompanyId", EvolutionResources.errModelFieldValueRequired);

            if (!error.IsError)
            {
                error = isValidRequiredString(getFieldValue(model.Name), 50, "Name", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.Address), 255, "Address", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.Phone), 20, "Phone", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.Email), 128, "Email", EvolutionResources.errTextDataRequiredInField);
            }

            if (!error.IsError)
            {
                // Check if a record with the same name already exists
                var forwarder = db.FindFreightForwarder(model.CompanyId, model.Name);
                if (forwarder != null &&                 // Record was found
                    ((forwarder.Id == 0 ||               // when creating new or
                      forwarder.Id != model.Id)))        // when updating existing
                {
                    error.SetError(EvolutionResources.errItemAlreadyExists, "Name");
                }
            }

            return(error);
        }
Exemple #2
0
        public Error InsertOrUpdateFreightForwarder(FreightForwarderModel forwarder, UserModel user, string lockGuid)
        {
            var error = validateModel(forwarder);

            if (!error.IsError)
            {
                // Check that the lock is still current
                if (!db.IsLockStillValid(typeof(FreightForwarder).ToString(), forwarder.Id, lockGuid))
                {
                    error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "Name");
                }
                else
                {
                    FreightForwarder temp = null;
                    if (forwarder.Id != 0)
                    {
                        temp = db.FindFreightForwarder(forwarder.Id);
                    }
                    if (temp == null)
                    {
                        temp = new FreightForwarder();
                    }

                    Mapper.Map <FreightForwarderModel, FreightForwarder>(forwarder, temp);

                    db.InsertOrUpdateFreightForwarder(temp);
                    forwarder.Id = temp.Id;
                }
            }
            return(error);
        }
        private FileTransferConfigurationModel getFileTransferConfigurationModel(PurchaseOrderHeader poh,
                                                                                 FileRecipient fileRecipient)
        {
            FileTransferConfigurationModel template = null;

            switch (fileRecipient)
            {
            case FileRecipient.Warehouse:
                LocationModel warehouse = null;
                if (poh.LocationId != null)
                {
                    warehouse = LookupService.FindLocationModel(poh.LocationId.Value, false);
                }
                if (warehouse != null)
                {
                    template = DataTransferService.FindFileTransferConfigurationForWarehouseModel(warehouse, FileTransferDataType.WarehousePurchase);
                }
                break;

            case FileRecipient.FreightForwarder:
                FreightForwarderModel freightForwarder = null;
                if (poh.FreightForwarderId != null)
                {
                    freightForwarder = LookupService.FindFreightForwarderModel(poh.FreightForwarderId.Value, false);
                }
                if (freightForwarder != null)
                {
                    template = DataTransferService.FindFileTransferConfigurationForFreightForwarder(freightForwarder, FileTransferDataType.FreightForwarderPurchase);
                }
                break;
            }

            return(template);
        }
        public void DeleteFreightForwarderTest()
        {
            // Get a test user
            var user        = GetTestUser();
            var testCompany = GetTestCompany(user);

            // Create a record
            FreightForwarderModel model = createFreightForwarder(testCompany);

            var error = LookupService.InsertOrUpdateFreightForwarder(model, user, "");

            Assert.IsTrue(!error.IsError, error.Message);

            // Check that it was written
            var result = db.FindFreightForwarder(model.Id);
            var test   = LookupService.MapToModel(result);

            AreEqual(model, test);

            // Now delete it
            LookupService.DeleteFreightForwarder(model.Id);

            // And check that is was deleted
            result = db.FindFreightForwarder(model.Id);
            Assert.IsTrue(result == null, "Error: A non-NULL value was returned when a NULL value was expected - record delete failed");
        }
        private FreightForwarderModel createFreightForwarder(CompanyModel company)
        {
            var model = new FreightForwarderModel {
                CompanyId = company.Id,
                Name      = RandomString(),
                Enabled   = true
            };

            return(model);
        }
Exemple #6
0
        public FreightForwarderModel FindFreightForwarderModel(int id, bool bCreateEmptyIfNotfound = true)
        {
            FreightForwarderModel model = null;

            var freightCarrier = db.FindFreightForwarder(id);

            if (freightCarrier == null)
            {
                if (bCreateEmptyIfNotfound)
                {
                    model = new FreightForwarderModel();
                }
            }
            else
            {
                model = MapToModel(freightCarrier);
            }

            return(model);
        }
Exemple #7
0
        public FreightForwarderModel Clone(FreightForwarderModel item)
        {
            var model = Mapper.Map <FreightForwarderModel, FreightForwarderModel>(item);

            return(model);
        }
Exemple #8
0
 public string LockFreightForwarder(FreightForwarderModel model)
 {
     return(db.LockRecord(typeof(FreightForwarder).ToString(), model.Id));
 }
        public FileTransferConfigurationModel FindFileTransferConfigurationForFreightForwarder(FreightForwarderModel freightForearder,
                                                                                               FileTransferDataType dataType)
        {
            var item = db.FindFileTransferConfigurations()
                       .Where(ftc => ftc.FreightForwarderId == freightForearder.Id &&
                              ftc.TransferType == (int)FileTransferType.Send &&
                              ftc.LOVItem_DataType.ItemValue1 == ((int)dataType).ToString() &&
                              ftc.Enabled == true)
                       .FirstOrDefault();

            return(MapToModel(item));
        }