public List <FrayteAddress> GetShippeOtherAddresses(int shipperId) { List <FrayteAddress> shipperOtherAddresses = new List <FrayteAddress>(); var addresses = dbContext.UserAddresses.Where(p => p.UserId == shipperId && (p.AddressTypeId == (int)FrayteAddressType.OtherAddress || p.AddressTypeId == (int)FrayteAddressType.MainAddress)).ToList(); if (addresses != null) { foreach (UserAddress userAddress in addresses) { FrayteAddress address = UtilityRepository.UserAddressMapping(userAddress); var countryResult = dbContext.Countries.Where(p => p.CountryId == address.Country.CountryId).FirstOrDefault(); if (countryResult != null) { address.Country.Name = countryResult.CountryName; address.Country.Code = countryResult.CountryCode; } shipperOtherAddresses.Add(address); } } return(shipperOtherAddresses); }
public FrayteAddress GetShipperMainAddress(int shipperId) { FrayteAddress shipperMainAddress = new FrayteAddress(); var address = dbContext.UserAddresses.Where(p => p.UserId == shipperId && p.AddressTypeId == (int)FrayteAddressType.MainAddress).FirstOrDefault(); if (address != null) { shipperMainAddress = UtilityRepository.UserAddressMapping(address); } return(shipperMainAddress); }
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); }
public FrayteAgent GetAgentDetail(int?agentId) { FrayteAgent agentDetail = new FrayteAgent(); WorkingWeekDay workingDays = new WorkingWeekDay(); //Step 1: Get Agent's basic information var agent = dbContext.Users.Where(p => p.UserId == agentId).FirstOrDefault(); if (agent != null) { agentDetail = UtilityRepository.AgentMapping(agent); agentDetail.RoleId = (int)FrayteUserRole.Agent; // get Working Week Time if (agentDetail.WorkingWeekDay.WorkingWeekDayId > 0) { workingDays = dbContext.WorkingWeekDays.Find(agentDetail.WorkingWeekDay.WorkingWeekDayId); } if (workingDays != null) { agentDetail.WorkingWeekDay = workingDays; } //Step 1.1: Get Agent's time zone var timeZone = dbContext.Timezones.Where(p => p.TimezoneId == agent.TimezoneId).FirstOrDefault(); if (timeZone != null) { agentDetail.Timezone = new TimeZoneModal(); agentDetail.Timezone.TimezoneId = timeZone.TimezoneId; agentDetail.Timezone.Name = timeZone.Name; agentDetail.Timezone.Offset = timeZone.Offset; agentDetail.Timezone.OffsetShort = timeZone.OffsetShort; } //Step 2: Get Agent's other information var agentOtherDetails = dbContext.UserAdditionals.Where(p => p.UserId == agentId).FirstOrDefault(); if (agentOtherDetails != null) { //Get associated Frayte User's detail GetAssociateUsersDetail(agent.UserId, agentDetail); } // Step 3: Get AgentShipmentType if (agentDetail != null && agentDetail.UserId > 0) { var agentShipmentType = dbContext.UserShipmentTypes.Where(p => p.UserId == agent.UserId).FirstOrDefault(); if (agentShipmentType != null) { agentDetail.UserShipmentTypeId = agentShipmentType.UserShipmentTypeId; agentDetail.IsAir = agentShipmentType.IsAir; agentDetail.IsSea = agentShipmentType.IsSea; agentDetail.IsExpryes = agentShipmentType.IsExpryes; } } //Step 4: Get Agents's Address information var agentAddress = dbContext.UserAddresses.Where(p => p.UserId == agentId && (p.AddressTypeId == (int)FrayteAddressType.MainAddress || p.AddressTypeId == (int)FrayteAddressType.OtherAddress)).ToList(); if (agentAddress != null) { agentDetail.OtherAddresses = new List <FrayteAddress>(); foreach (UserAddress address in agentAddress) { if (address.AddressTypeId == (int)FrayteAddressType.MainAddress) { //Step 3.1: Set Agent main address agentDetail.UserAddress = new FrayteAddress(); agentDetail.UserAddress = UtilityRepository.UserAddressMapping(address); //Step : Get country information var country = dbContext.Countries.Where(p => p.CountryId == address.CountryId).FirstOrDefault(); if (country != null) { agentDetail.UserAddress.Country = new FrayteCountryCode(); agentDetail.UserAddress.Country.CountryId = country.CountryId; agentDetail.UserAddress.Country.Code = country.CountryCode; agentDetail.UserAddress.Country.Name = country.CountryName; } } else { //Step 4.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; } agentDetail.OtherAddresses.Add(otherAddress); } } } } return(agentDetail); }