예제 #1
0
        public FrayteResult SaveShipper(FrayteShipperReceiver frayteUser)
        {
            FrayteResult         result         = new FrayteResult();
            FrayteUserRepository userRepository = new FrayteUserRepository();

            //Step 1: Save User Detail
            userRepository.SaveUserDetail(frayteUser);

            //Step 2: Save user role
            userRepository.SaveUserRole(frayteUser.UserId, (int)FrayteUserRole.Shipper);

            //Step 3: Save User Address information
            frayteUser.UserAddress.AddressTypeId = (int)FrayteAddressType.MainAddress;
            frayteUser.UserAddress.UserId        = frayteUser.UserId;
            userRepository.SaveUserAddress(frayteUser.UserAddress);

            //Step 4: Save Shipper Pickup address information
            if (frayteUser.PickupAddresses != null && frayteUser.PickupAddresses.Count > 0)
            {
                foreach (FrayteAddress address in frayteUser.PickupAddresses)
                {
                    address.AddressTypeId = (int)FrayteAddressType.OtherAddress;
                    address.UserId        = frayteUser.UserId;
                    userRepository.SaveUserAddress(address);
                }
            }

            result.Status = true;
            return(result);
        }
예제 #2
0
        public FrayteResult SaveAgent(FrayteAgent frayteUser)
        {
            FrayteResult result = new FrayteResult();

            FrayteUserRepository userRepository = new FrayteUserRepository();

            //Step 1: Save Agent Detail
            userRepository.SaveUserDetail(frayteUser);

            //Step 2: Save Agent's additional detail
            SaveAgentAdditional(frayteUser);

            // Step 3: Save UserShipmentType
            SaveAgentShipmentType(frayteUser);

            //Step 4: Save Agent role
            userRepository.SaveUserRole(frayteUser.UserId, (int)FrayteUserRole.Agent);

            //Step 5: Save Agent Address information
            frayteUser.UserAddress.AddressTypeId = (int)FrayteAddressType.MainAddress;
            frayteUser.UserAddress.UserId        = frayteUser.UserId;
            userRepository.SaveUserAddress(frayteUser.UserAddress);

            //Step 6: Save Agent other address information
            if (frayteUser.OtherAddresses != null && frayteUser.OtherAddresses.Count > 0)
            {
                foreach (FrayteAddress address in frayteUser.OtherAddresses)
                {
                    address.AddressTypeId = (int)FrayteAddressType.OtherAddress;
                    address.UserId        = frayteUser.UserId;
                    userRepository.SaveUserAddress(address);
                }
            }

            //Step 7: Save Agent's Associated Users information
            if (frayteUser.AssociatedUsers != null && frayteUser.AssociatedUsers.Count > 0)
            {
                foreach (FrayteAgentAssociatedUser agentUser in frayteUser.AssociatedUsers)
                {
                    AgentAssociatedUser saveUser = new AgentAssociatedUser();

                    if (agentUser.AgentAssociatedUserId > 0)
                    {
                        // Update AgentAssociated user Info
                        var associatedUser = dbContext.AgentAssociatedUsers.Where(p => p.AgentAssociatedUserId == agentUser.AgentAssociatedUserId).FirstOrDefault();
                        if (associatedUser != null)
                        {
                            associatedUser.Name        = agentUser.Name;
                            associatedUser.UserType    = agentUser.UserType;
                            associatedUser.Email       = agentUser.Email;
                            associatedUser.TelephoneNo = agentUser.TelephoneNo;

                            associatedUser.WorkingStartTime = UtilityRepository.GetTimeZoneUTCTime(agentUser.WorkingStartTime, frayteUser.Timezone.TimezoneId).Value;
                            associatedUser.WorkingEndTime   = UtilityRepository.GetTimeZoneUTCTime(agentUser.WorkingEndTime, frayteUser.Timezone.TimezoneId).Value;
                            associatedUser.WorkingWeekDays  = agentUser.WorkingWeekDays;
                            dbContext.SaveChanges();
                        }
                        else
                        {
                            saveUser.AgentId          = frayteUser.UserId;
                            saveUser.Name             = agentUser.Name;
                            saveUser.UserType         = agentUser.UserType;
                            saveUser.Email            = agentUser.Email;
                            saveUser.TelephoneNo      = agentUser.TelephoneNo;
                            saveUser.WorkingStartTime = UtilityRepository.GetTimeZoneUTCTime(agentUser.WorkingStartTime, frayteUser.Timezone.TimezoneId).Value;
                            saveUser.WorkingEndTime   = UtilityRepository.GetTimeZoneUTCTime(agentUser.WorkingEndTime, frayteUser.Timezone.TimezoneId).Value;
                            saveUser.WorkingWeekDays  = agentUser.WorkingWeekDays;
                            dbContext.AgentAssociatedUsers.Add(saveUser);
                            dbContext.SaveChanges();
                        }
                    }
                    else
                    {
                        // Insert Agent Associated User Info
                        saveUser.AgentId          = frayteUser.UserId;
                        saveUser.Name             = agentUser.Name;
                        saveUser.UserType         = agentUser.UserType;
                        saveUser.Email            = agentUser.Email;
                        saveUser.TelephoneNo      = agentUser.TelephoneNo;
                        saveUser.WorkingStartTime = UtilityRepository.GetTimeZoneUTCTime(agentUser.WorkingStartTime, frayteUser.Timezone.TimezoneId).Value;
                        saveUser.WorkingEndTime   = UtilityRepository.GetTimeZoneUTCTime(agentUser.WorkingEndTime, frayteUser.Timezone.TimezoneId).Value;
                        saveUser.WorkingWeekDays  = agentUser.WorkingWeekDays;
                        dbContext.AgentAssociatedUsers.Add(saveUser);
                        dbContext.SaveChanges();
                    }
                }
            }

            result.Status = true;

            return(result);
        }