Exemplo n.º 1
0
        private Models.Tariff CopyTariffVersion(int tariffVersionID)
        {
            //Create a new Tariff and assign entered values
            var tariff = new Models.Tariff
            {
                Description        = txtTariffDescription.Text,
                IsForSubContractor = chkIsForSubContractor.Checked,
            };

            //Create a new TariffVersion and assign entered values
            var version = new Models.TariffVersion
            {
                StartDate   = dteStartDate.SelectedDate.Value.Date,
                Description = txtVersionDescription.Text,
            };

            using (var uow = DIContainer.CreateUnitOfWork())
            {
                var repo = DIContainer.CreateRepository <Repositories.ITariffRepository>(uow);

                //Get the TariffVersion to copy from
                var copyFromVersion = repo.FindTariffVersion(tariffVersionID);

                //Copy the ZoneType, Metric and Multiplier values from the selected Tariff
                var copyFromTariff = copyFromVersion.Tariff;
                tariff.ZoneType             = copyFromTariff.ZoneType;
                tariff.Metric               = copyFromTariff.Metric;
                tariff.MultiplyByOrderValue = copyFromTariff.MultiplyByOrderValue;
                tariff.AdditionalMultiplier = copyFromTariff.AdditionalMultiplier;
                tariff.IgnoreAdditionalCollectsFromADeliveryPoint = copyFromTariff.IgnoreAdditionalCollectsFromADeliveryPoint;

                //Add the new Tariff
                repo.Add(tariff);

                //Use the selected version's ZoneMap and Scale
                version.ZoneMap = copyFromVersion.ZoneMap;
                version.Scale   = copyFromVersion.Scale;

                //Add the new TariffVersion to the new Tariff
                tariff.TariffVersions.Add(version);

                //Save changes to database
                uow.SaveChanges();

                //Call a sproc to copy the selected TariffVersion's TariffTables to the new TariffVersion (including ExtraTypeRates)
                var increaseRate = txtIncreaseRate.Value.HasValue ? (decimal)txtIncreaseRate.Value.Value : 0m;

                repo.TariffVersionCopyTariffTables(
                    copyFromVersion.TariffVersionID,
                    version.TariffVersionID,
                    increaseRate);
            }

            //Return the new tariff with its assigned TariffID
            return(tariff);
        }
Exemplo n.º 2
0
        private async Task SetStoreCacheValue(Models.Tariff tariffNew)
        {
            if (tariffNew == null)
            {
                return;
            }

            var optionsCache = TimeSpan.FromDays(1);

            await _database.
            StringSetAsync(string.Format(TariffCacheKey, tariffNew.CompanyName, tariffNew.CategoryId), JsonConvert.SerializeObject(tariffNew), optionsCache);
        }
Exemplo n.º 3
0
        private void LoadTariff(Models.Tariff tariff, Models.TariffVersion previousVersion)
        {
            if (!previousVersion.FinishDate.HasValue)
            {
                throw new ApplicationException("The last tariff version has not been finished.");
            }

            lblTariffDescription.Text = tariff.Description;

            //Set the new TariffVersion StartDate to the day after the previous version's FinishDate
            lblStartDate.Text = previousVersion.FinishDate.Value.AddDays(1).ToString("dd/MM/yy");

            //Default the new TariffVersion's Description
            txtVersionDescription.Text = lblTariffDescription.Text + " - " + lblStartDate.Text;
        }
Exemplo n.º 4
0
        public async Task <bool> InsertAsync(Models.Tariff tariffNew)
        {
            var tariffOld = await GetCurrencTariffValueAsync(tariffNew.CompanyName, tariffNew.CategoryId);

            if (tariffOld != null)
            {
                tariffOld.ExpirationDate        = DateTime.UtcNow;
                _context.Entry(tariffOld).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }

            await _context.Tariffs.AddAsync(tariffNew);

            var inserted = await _context.SaveChangesAsync();

            return(inserted > 0 ? true : false);
        }
Exemplo n.º 5
0
        private void LoadTariffVersions(IUnitOfWork uow, Models.Tariff tariff)
        {
            var tariffVersions = tariff.TariffVersions.OrderByDescending(tv => tv.StartDate);

            //Only enable the New Version button if the latest version has been finished
            btnNewVersion.Enabled = tariffVersions.First().FinishDate.HasValue;

            var currentTariffVersionID = (cboTariffVersion.SelectedIndex > -1) ? int.Parse(cboTariffVersion.SelectedValue) : (int?)null;

            cboTariffVersion.DataValueField = "TariffVersionID";
            cboTariffVersion.DataTextField  = "Description";
            cboTariffVersion.DataSource     = tariffVersions.Select(tv => new { tv.TariffVersionID, tv.Description }).ToList();
            cboTariffVersion.DataBind();

            //Choose the selected TariffVersion if one was passed otherwise choose the first which is the latest
            if (cboTariffVersion.Items.Count > 0)
            {
                int?tariffVersionID = null;

                if (currentTariffVersionID.HasValue)
                {
                    tariffVersionID = currentTariffVersionID;
                }
                else
                {
                    if (this.TariffTableID.HasValue)
                    {
                        var repo        = DIContainer.CreateRepository <Repositories.ITariffRepository>(uow);
                        var tariffTable = repo.FindTariffTable(this.TariffTableID.Value);
                        tariffVersionID = tariffTable.TariffVersionID;
                    }
                }

                if (tariffVersionID.HasValue)
                {
                    var selectedTariffVersion = cboTariffTable.FindItemByValue(tariffVersionID.Value.ToString());

                    if (selectedTariffVersion != null)
                    {
                        selectedTariffVersion.Selected = true;
                    }
                }

                LoadTariffVersion(uow);
            }
        }
Exemplo n.º 6
0
        private void LoadScales(IUnitOfWork uow, Models.Tariff tariff, Models.TariffVersion previousVersion)
        {
            //Get the Scales that are relevant for the Tariff's Metric and load the combo with them
            var scaleRepo = DIContainer.CreateRepository <Repositories.IScaleRepository>(uow);
            var scales    = scaleRepo.GetForMetric(tariff.Metric).Select(s => new { s.ScaleID, s.Description });

            cboScale.DataValueField = "ScaleID";
            cboScale.DataTextField  = "Description";

            cboScale.DataSource = scales.ToList();
            cboScale.DataBind();

            //Default to the previous version's ZoneMap
            if (cboScale.Items.Any())
            {
                cboScale.SelectedValue = previousVersion.ScaleID.ToString();
            }
        }
Exemplo n.º 7
0
        private void LoadZoneMaps(IUnitOfWork uow, Models.Tariff tariff, Models.TariffVersion previousVersion)
        {
            //Get the ZoneMaps that are relevant for the Tariff's ZoneType and load the combo with them
            var zoneMapRepo = DIContainer.CreateRepository <Repositories.IZoneMapRepository>(uow);
            var zoneMaps    = zoneMapRepo.GetForZoneType(tariff.ZoneType).Select(zm => new { zm.ZoneMapID, zm.Description });

            cboZoneMap.DataValueField = "ZoneMapID";
            cboZoneMap.DataTextField  = "Description";

            cboZoneMap.DataSource = zoneMaps.ToList();
            cboZoneMap.DataBind();

            //Default to the previous version's ZoneMap
            if (cboZoneMap.Items.Any())
            {
                cboZoneMap.SelectedValue = previousVersion.ZoneMapID.ToString();
            }
        }
Exemplo n.º 8
0
        private void LoadCopyFromTariffs(IUnitOfWork uow, Models.Tariff tariff)
        {
            var repo = DIContainer.CreateRepository <Repositories.ITariffRepository>(uow);

            var tariffs =
                from t in repo.GetAll()
                orderby t.Description
                select new { t.TariffID, t.Description };

            cboCopyFromTariff.DataValueField = "TariffID";
            cboCopyFromTariff.DataTextField  = "Description";
            cboCopyFromTariff.DataSource     = tariffs.ToList();
            cboCopyFromTariff.DataBind();

            //Default to the Tariff
            if (cboCopyFromTariff.Items.Count > 0)
            {
                cboCopyFromTariff.SelectedValue = tariff.TariffID.ToString();
                this.LoadCopyFromVersions(uow, int.Parse(cboCopyFromTariff.SelectedValue));
            }
        }
Exemplo n.º 9
0
        private Models.Tariff CreateEmptyTariff()
        {
            //Create a new Tariff and assign entered values
            var tariff = new Models.Tariff
            {
                Description          = txtTariffDescription.Text,
                IsForSubContractor   = chkIsForSubContractor.Checked,
                ZoneType             = (eZoneType)int.Parse(optZoneType.SelectedValue),
                Metric               = (eMetric)int.Parse(optMetric.SelectedValue),
                MultiplyByOrderValue = chkMultiplyByOrderValue.Checked,
                AdditionalMultiplier = (chkMultiplyByOrderValue.Checked && txtAdditionalMultiplier.Value > 0) ? (decimal?)txtAdditionalMultiplier.Value : null,
                IgnoreAdditionalCollectsFromADeliveryPoint = chkIgnoreAdditionalCollectsFromADeliveryPoint.Checked,
            };

            //Create a new TariffVersion and assign entered values
            var version = new Models.TariffVersion
            {
                StartDate   = dteStartDate.SelectedDate.Value.Date,
                Description = txtVersionDescription.Text,
                ZoneMapID   = int.Parse(cboZoneMap.SelectedValue),
                ScaleID     = int.Parse(cboScale.SelectedValue),
            };

            //Add the new TariffVersion to the new Tariff
            tariff.TariffVersions.Add(version);

            using (var uow = DIContainer.CreateUnitOfWork())
            {
                var repo = DIContainer.CreateRepository <Repositories.ITariffRepository>(uow);
                repo.Add(tariff);

                //Save changes to database
                uow.SaveChanges();
            }

            //and return the new tariff with its assigned TariffID
            return(tariff);
        }
Exemplo n.º 10
0
 private Models.TariffVersion GetPreviousVersion(Models.Tariff tariff)
 {
     return(tariff.TariffVersions.OrderByDescending(tv => tv.StartDate).First());
 }
Exemplo n.º 11
0
        public async Task <IActionResult> InsertAsync([FromBody] Models.Tariff data)
        {
            var tariff = await _tariffRepository.InsertAsync(data);

            return(Ok(tariff));
        }