Exemplo n.º 1
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);
        }