public void GetAssociateCustomeDetail(FrayteInternalUser customer) { customer.AssociateCustomer = new List <FrayteAssociateCustomer>(); FrayteAssociateCustomer user; var associatedetail = (from cs in dbContext.CustomerStaffs join u in dbContext.Users on cs.UserId equals u.UserId join ua in dbContext.UserAddresses on u.UserId equals ua.UserId join c in dbContext.Countries on ua.CountryId equals c.CountryId where cs.CustomerStaffId == customer.UserId && cs.IsActive == true && u.IsActive == true select new { CustomerStaffDetailId = cs.CustomerStaffDetailId, UserId = u.UserId, ContactName = u.ContactName, Email = u.UserEmail, PhoneCode = (c == null || c.CountryPhoneCode == "") ? "" : c.CountryPhoneCode, TelephoneNo = u.TelephoneNo, WorkingStartTime = u.WorkingStartTime, WorkingEndTime = u.WorkingEndTime }).ToList(); if (associatedetail != null && associatedetail.Count > 0) { foreach (var dd in associatedetail) { user = new FrayteAssociateCustomer(); user.CustomerId = dd.UserId; user.CustomerStaffDetailId = dd.CustomerStaffDetailId; user.CustomerName = dd.ContactName; user.Email = dd.Email; user.ContactNo = dd.PhoneCode == "" ? dd.TelephoneNo : "(+" + dd.PhoneCode + ") " + dd.TelephoneNo; user.WorkingHours = UtilityRepository.GetWorkingHours(dd.WorkingStartTime, dd.WorkingEndTime); customer.AssociateCustomer.Add(user); } } }
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); }