示例#1
0
        public FrayteShipperReceiver GetShipperDetail(int shipperId)
        {
            FrayteShipperReceiver shipperReceiver = new FrayteShipperReceiver();
            WorkingWeekDay        workingDays     = new WorkingWeekDay();
            //Step 1: Get Shipper basic information
            var shipper = dbContext.Users.Where(p => p.UserId == shipperId).FirstOrDefault();

            if (shipper != null)
            {
                //Set User's bacic information
                shipperReceiver = UtilityRepository.ShipperReceiverMapping(shipper);
                // get Working Week day

                if (shipperReceiver.WorkingWeekDay.WorkingWeekDayId > 0)
                {
                    workingDays = dbContext.WorkingWeekDays.Find(shipperReceiver.WorkingWeekDay.WorkingWeekDayId);
                }


                if (workingDays != null)
                {
                    shipperReceiver.WorkingWeekDay = workingDays;
                }
                //Step 1.1: Get time zone
                var timeZone = dbContext.Timezones.Where(p => p.TimezoneId == shipper.TimezoneId).FirstOrDefault();
                if (timeZone != null)
                {
                    shipperReceiver.Timezone             = new TimeZoneModal();
                    shipperReceiver.Timezone.TimezoneId  = timeZone.TimezoneId;
                    shipperReceiver.Timezone.Name        = timeZone.Name;
                    shipperReceiver.Timezone.Offset      = timeZone.Offset;
                    shipperReceiver.Timezone.OffsetShort = timeZone.OffsetShort;
                }

                //Step 2: Get Shipper's Address information
                var shipperAddress = dbContext.UserAddresses.Where(p => p.UserId == shipperId).ToList();
                if (shipperAddress != null)
                {
                    shipperReceiver.PickupAddresses = new List <FrayteAddress>();

                    foreach (UserAddress address in shipperAddress)
                    {
                        if (address.AddressTypeId == (int)FrayteAddressType.MainAddress)
                        {
                            //Step 2.1: Set Shipper.ShipperAddress
                            shipperReceiver.UserAddress = new FrayteAddress();
                            shipperReceiver.UserAddress = UtilityRepository.UserAddressMapping(address);

                            //Step : Get country information
                            var country = dbContext.Countries.Where(p => p.CountryId == address.CountryId).FirstOrDefault();
                            if (country != null)
                            {
                                shipperReceiver.UserAddress.Country                = new FrayteCountryCode();
                                shipperReceiver.UserAddress.Country.CountryId      = country.CountryId;
                                shipperReceiver.UserAddress.Country.Code           = country.CountryCode;
                                shipperReceiver.UserAddress.Country.Name           = country.CountryName;
                                shipperReceiver.UserAddress.Country.TimeZoneDetail = new TimeZoneModal();
                                if (country.TimeZoneId != null && country.TimeZoneId > 0)
                                {
                                    var time = dbContext.Timezones.Find(country.TimeZoneId);
                                    shipperReceiver.UserAddress.Country.TimeZoneDetail.Name        = time.Name;
                                    shipperReceiver.UserAddress.Country.TimeZoneDetail.Offset      = time.Offset;
                                    shipperReceiver.UserAddress.Country.TimeZoneDetail.OffsetShort = time.OffsetShort;
                                    shipperReceiver.UserAddress.Country.TimeZoneDetail.TimezoneId  = time.TimezoneId;
                                }
                            }
                        }
                        else
                        {
                            //Step 2.2: Set Agent's other addresses
                            FrayteAddress otherAddress = UtilityRepository.UserAddressMapping(address);

                            //Step : Get country information
                            var country = dbContext.Countries.Where(p => p.CountryId == otherAddress.Country.CountryId).FirstOrDefault();
                            if (country != null)
                            {
                                otherAddress.Country                = new FrayteCountryCode();
                                otherAddress.Country.CountryId      = country.CountryId;
                                otherAddress.Country.Code           = country.CountryCode;
                                otherAddress.Country.Name           = country.CountryName;
                                otherAddress.Country.TimeZoneDetail = new TimeZoneModal();
                                if (country.TimeZoneId != null && country.TimeZoneId > 0)
                                {
                                    var time = dbContext.Timezones.Find(country.TimeZoneId);
                                    otherAddress.Country.TimeZoneDetail.Name        = time.Name;
                                    otherAddress.Country.TimeZoneDetail.Offset      = time.Offset;
                                    otherAddress.Country.TimeZoneDetail.OffsetShort = time.OffsetShort;
                                    otherAddress.Country.TimeZoneDetail.TimezoneId  = time.TimezoneId;
                                }
                            }

                            shipperReceiver.PickupAddresses.Add(otherAddress);
                        }
                    }
                }
            }

            return(shipperReceiver);
        }