Пример #1
0
        private void WorkingWeekDay(FrayteWeekDays frayteWeekDay)
        {
            WorkingWeekDay weekday;

            if (frayteWeekDay.WorkingWeekDayId > 0)
            {
                weekday = dbContext.WorkingWeekDays.Where(p => p.WorkingWeekDayId == frayteWeekDay.WorkingWeekDayId).FirstOrDefault();
                if (weekday != null)
                {
                    weekday.Description = frayteWeekDay.Description;
                    if (frayteWeekDay.IsDefault)
                    {
                        var weekDays = dbContext.WorkingWeekDays.Where(p => p.IsDefault == true).ToList();
                        foreach (var data in weekDays)
                        {
                            data.IsDefault = false;
                            dbContext.Entry(data).State = System.Data.Entity.EntityState.Modified;
                            dbContext.SaveChanges();
                        }
                    }
                    weekday.IsDefault = frayteWeekDay.IsDefault;
                    dbContext.SaveChanges();
                    frayteWeekDay.WorkingWeekDayId = weekday.WorkingWeekDayId;
                }
            }
            else
            {
                weekday             = new WorkingWeekDay();
                weekday.Description = frayteWeekDay.Description;
                if (frayteWeekDay.IsDefault)
                {
                    var weekDays = dbContext.WorkingWeekDays.Where(p => p.IsDefault == true).ToList();
                    foreach (var data in weekDays)
                    {
                        data.IsDefault = false;
                        dbContext.Entry(data).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                    }
                }
                weekday.IsDefault = frayteWeekDay.IsDefault;
                dbContext.WorkingWeekDays.Add(weekday);
                if (weekday != null)
                {
                    dbContext.SaveChanges();
                }
                frayteWeekDay.WorkingWeekDayId = weekday.WorkingWeekDayId;
            }
        }
Пример #2
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);
        }
Пример #3
0
        public FrayteInternalUser CustomerStaffDetail(int UserId)
        {
            FrayteInternalUser customer    = new FrayteInternalUser();
            WorkingWeekDay     workingDays = new WorkingWeekDay();

            var detail = dbContext.Users.Where(p => p.UserId == UserId).FirstOrDefault();

            if (detail != null)
            {
                customer = UtilityRepository.InternalUserMapping(detail);

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

                if (workingDays != null)
                {
                    customer.WorkingWeekDay = workingDays;
                }

                var userRole = dbContext.UserRoles.Where(p => p.UserId == UserId).FirstOrDefault();
                if (userRole != null)
                {
                    customer.RoleId = userRole.RoleId;
                }

                var timeZone = dbContext.Timezones.Where(p => p.TimezoneId == detail.TimezoneId).FirstOrDefault();
                if (timeZone != null)
                {
                    customer.Timezone             = new TimeZoneModal();
                    customer.Timezone.TimezoneId  = timeZone.TimezoneId;
                    customer.Timezone.Name        = timeZone.Name;
                    customer.Timezone.Offset      = timeZone.Offset;
                    customer.Timezone.OffsetShort = timeZone.OffsetShort;
                }

                //Step 2: Get internal user's other information
                var internalUserOtherDetails = dbContext.UserAdditionals.Where(p => p.UserId == UserId).FirstOrDefault();
                if (internalUserOtherDetails != null)
                {
                    if (internalUserOtherDetails.IsFuelSurCharge.HasValue)
                    {
                        customer.IsFuelSurCharge = internalUserOtherDetails.IsFuelSurCharge.Value;
                    }
                    if (internalUserOtherDetails.IsCurrency.HasValue)
                    {
                        customer.IsCurrency = internalUserOtherDetails.IsCurrency.Value;
                    }

                    customer.ManagerUser = new FrayteCustomerAssociatedUser();
                    customer.ManagerUser = null;

                    //Get associated customer's detail
                    GetAssociateCustomeDetail(customer);
                }

                //Step 3: Get user address
                var address = dbContext.UserAddresses.Where(p => p.UserId == UserId).FirstOrDefault();
                if (address != null)
                {
                    customer.UserAddress                   = new FrayteAddress();
                    customer.UserAddress.Address           = address.Address;
                    customer.UserAddress.Address2          = address.Address2;
                    customer.UserAddress.Address3          = address.Address3;
                    customer.UserAddress.AddressTypeId     = address.AddressTypeId;
                    customer.UserAddress.City              = address.City;
                    customer.UserAddress.EasyPostAddressId = address.EasyPostAddressId;
                    customer.UserAddress.State             = address.State;
                    customer.UserAddress.Suburb            = address.Suburb;
                    customer.UserAddress.UserAddressId     = address.UserAddressId;
                    customer.UserAddress.UserId            = address.UserId;
                    customer.UserAddress.Zip               = address.Zip;
                    customer.UserAddress.Country           = new FrayteCountryCode();
                    {
                        var country = dbContext.Countries.Where(p => p.CountryId == address.CountryId).FirstOrDefault();
                        if (country != null)
                        {
                            customer.UserAddress.Country.CountryId        = country.CountryId;
                            customer.UserAddress.Country.Code             = country.CountryCode;
                            customer.UserAddress.Country.Code2            = country.CountryCode2;
                            customer.UserAddress.Country.Name             = country.CountryName;
                            customer.UserAddress.Country.CountryPhoneCode = country.CountryPhoneCode;
                        }
                    }
                }
            }

            return(customer);
        }
Пример #4
0
        public FrayteWarehouse GetWarehouseDetail(int?warehouseId)
        {
            FrayteWarehouse warehouseDetail = new FrayteWarehouse();
            WorkingWeekDay  workingDays     = new WorkingWeekDay();
            var             warehouse       = dbContext.Warehouses.Where(p => p.WarehouseId == warehouseId).FirstOrDefault();

            if (warehouse != null)
            {
                warehouseDetail.WarehouseId    = warehouse.WarehouseId;
                warehouseDetail.Address        = warehouse.Address;
                warehouseDetail.Address2       = warehouse.Address2;
                warehouseDetail.Address3       = warehouse.Address3;
                warehouseDetail.City           = warehouse.City;
                warehouseDetail.State          = warehouse.State;
                warehouseDetail.Zip            = warehouse.Zip;
                warehouseDetail.WorkingWeekDay = new WorkingWeekDay();
                if (warehouse.WorkingWeekDayId != null)
                {
                    warehouseDetail.WorkingWeekDay.WorkingWeekDayId = warehouse.WorkingWeekDayId.Value;
                }

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


                if (workingDays != null)
                {
                    warehouseDetail.WorkingWeekDay = workingDays;
                }
                warehouseDetail.Email            = warehouse.Email;
                warehouseDetail.TelephoneNo      = warehouse.TelephoneNo;
                warehouseDetail.MobileNo         = warehouse.MobileNo;
                warehouseDetail.Fax              = warehouse.Fax;
                warehouseDetail.WorkingStartTime = UtilityRepository.GetTimeZoneTime(warehouse.WorkingStartTime, warehouse.TimeZoneId);
                warehouseDetail.WorkingEndTime   = UtilityRepository.GetTimeZoneTime(warehouse.WorkingEndTime, warehouse.TimeZoneId);
                warehouseDetail.Address3         = warehouse.Address3;
                warehouseDetail.Address3         = warehouse.Address3;
                warehouseDetail.Address3         = warehouse.Address3;

                warehouseDetail.LocationMapImage    = warehouse.LocationMapImage;
                warehouseDetail.LocationName        = warehouse.LocationName;
                warehouseDetail.MapDetail           = new GrayteGoogleMap();
                warehouseDetail.MapDetail.latitude  = warehouse.LocationLatitude.HasValue ?  warehouse.LocationLatitude.Value : 0;
                warehouseDetail.MapDetail.longitude = warehouse.LocationLongitude.HasValue ? warehouse.LocationLongitude.Value : 0;
                warehouseDetail.Zoom                   = warehouse.LocationZoom.HasValue ? warehouse.LocationZoom.Value : 0;
                warehouseDetail.MarkerDetail           = new GrayteGoogleMap();
                warehouseDetail.MarkerDetail.latitude  = warehouse.MarkerLatitude.HasValue ? warehouse.MarkerLatitude.Value : 0;
                warehouseDetail.MarkerDetail.longitude = warehouse.MarkerLongitude.HasValue ? warehouse.MarkerLongitude.Value : 0;

                //Get Country Details
                var country = dbContext.Countries.Where(p => p.CountryId == warehouse.CountryId).FirstOrDefault();
                if (country != null)
                {
                    warehouseDetail.Country           = new FrayteCountryCode();
                    warehouseDetail.Country.CountryId = country.CountryId;
                    warehouseDetail.Country.Code      = country.CountryCode;
                    warehouseDetail.Country.Code2     = country.CountryCode2;
                    warehouseDetail.Country.Name      = country.CountryName;
                }
                else
                {
                    warehouseDetail.Country = new FrayteCountryCode();
                }

                //Get TimeZone details
                var timezone = dbContext.Timezones.Where(p => p.TimezoneId == warehouse.TimeZoneId).FirstOrDefault();
                if (timezone != null)
                {
                    warehouseDetail.Timezone             = new TimeZoneModal();
                    warehouseDetail.Timezone.TimezoneId  = timezone.TimezoneId;
                    warehouseDetail.Timezone.Name        = timezone.Name;
                    warehouseDetail.Timezone.Offset      = timezone.Offset;
                    warehouseDetail.Timezone.OffsetShort = timezone.OffsetShort;
                }
                else
                {
                    warehouseDetail.Timezone = new TimeZoneModal();
                }

                //Get warehouse manager detail
                var warehouseManager = dbContext.Users.Where(p => p.UserId == warehouse.ManagerId).FirstOrDefault();
                if (warehouseManager != null)
                {
                    warehouseDetail.Manager               = new FrayteCustomerAssociatedUser();
                    warehouseDetail.Manager.UserId        = warehouseManager.UserId;
                    warehouseDetail.Manager.AssociateType = FrayteAssociateType.Manager;
                    warehouseDetail.Manager.ContactName   = warehouseManager.ContactName;
                    warehouseDetail.Manager.Email         = warehouseManager.Email;
                    warehouseDetail.Manager.TelephoneNo   = warehouseManager.TelephoneNo;
                    warehouseDetail.Manager.WorkingHours  = UtilityRepository.GetWorkingHours(warehouseManager.WorkingStartTime, warehouseManager.WorkingEndTime);
                }
                else
                {
                    warehouseDetail.Manager = new FrayteCustomerAssociatedUser();
                }
            }

            return(warehouseDetail);
        }
Пример #5
0
        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);
        }