public void UpdatePattern(PartnerContractTariffViewModel pattern)
        {
            if (pattern != null)
            {
                var removePatterns = _tariffPatternRepository.Query(p => p.PartnerMainC == pattern.PartnerMainC &&
                                                                    p.PartnerSubC == pattern.PartnerSubC &&
                                                                    p.ApplyD == pattern.ApplyD);
                if (removePatterns != null)
                {
                    foreach (var remPattern in removePatterns)
                    {
                        _tariffPatternRepository.Delete(remPattern);
                    }
                }

                var patterns = pattern.TarrifPatterns;

                foreach (var patternM in patterns.Select(pat => new PartnerContractTariffPattern_M
                {
                    PartnerMainC = pattern.PartnerMainC,
                    PartnerSubC = pattern.PartnerSubC,
                    ApplyD = pattern.ApplyD,
                    DepartureC = pat.DepartureC,
                    DestinationC = pat.DestinationC,
                    ContainerSizeI = pat.ContainerSizeI,
                    ContainerTypeC = pat.ContainerTypeC,
                    UnitPrice = pat.UnitPrice
                }))
                {
                    _tariffPatternRepository.Add(patternM);
                }

                SavePartnerContactTariffPattern();
            }
        }
        public PartnerContractTariffViewModel GetPartnerContractTariffPattern(string partnerMainC, string partnerSubC, DateTime applyD)
        {
            var tarriffs = (from p in _tariffPatternRepository.GetAllQueryable()
                            join ct in _containerTypeRepository.GetAllQueryable() on p.ContainerTypeC equals ct.ContainerTypeC
                            join dp in _locationRepository.GetAllQueryable() on p.DepartureC equals dp.LocationC
                            join ds in _locationRepository.GetAllQueryable() on p.DestinationC equals ds.LocationC
                            where p.PartnerMainC == partnerMainC &&
                            p.PartnerSubC == partnerSubC && p.ApplyD == applyD
                            select new TariffPatternViewModel
            {
                DepartureC = p.DepartureC,
                DepartureN = dp.LocationN,
                DestinationC = p.DestinationC,
                DestinationN = ds.LocationN,
                ContainerTypeC = p.ContainerTypeC,
                ContainerTypeN = ct.ContainerTypeN,
                ContainerSizeI = p.ContainerSizeI,
                UnitPrice = p.UnitPrice
            }).OrderBy(i => i.ContainerSizeI).ThenBy(i => i.ContainerTypeN).ToList();

            var model = new PartnerContractTariffViewModel
            {
                PartnerMainC   = partnerMainC,
                PartnerSubC    = partnerSubC,
                PartnerN       = _partnerRepository.Query(i => i.PartnerMainC == partnerMainC && i.PartnerSubC == partnerSubC).Select(i => i.PartnerN).FirstOrDefault(),
                ApplyD         = applyD,
                TarrifPatterns = tarriffs
            };

            return(model);
        }
        public void CreatePattern(PartnerContractTariffViewModel pattern)
        {
            if (pattern != null)
            {
                var patterns = pattern.TarrifPatterns;

                foreach (var patternM in patterns.Select(pat => new PartnerContractTariffPattern_M
                {
                    PartnerMainC = pattern.PartnerMainC,
                    PartnerSubC = pattern.PartnerSubC,
                    ApplyD = pattern.ApplyD,
                    DepartureC = pat.DepartureC,
                    DestinationC = pat.DestinationC,
                    ContainerSizeI = pat.ContainerSizeI,
                    ContainerTypeC = pat.ContainerTypeC,
                    UnitPrice = pat.UnitPrice
                }))
                {
                    _tariffPatternRepository.Add(patternM);
                }
            }

            SavePartnerContactTariffPattern();
        }
예제 #4
0
 public void Put(PartnerContractTariffViewModel pattern)
 {
     _contractTariffPatternService.UpdatePattern(pattern);
 }