/// <summary>
        /// Creates the user and profile.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns></returns>
        public static string CreateUserAndProfile(UserDetails user)
        {
            if (user.IsValid)
            {
                //save profile details too
                ProfileCommon p          = new ProfileCommon();
                ProfileCommon newProfile = p.GetProfile(user.UserName);
                newProfile.WarehouseId     = user.WarehouseId;
                newProfile.RegionId        = user.RegionId;
                newProfile.OpCoId          = user.OpCoId;
                newProfile.SalesLocationId = user.SalesLocationId;
                newProfile.OpCoCode        = "";
                newProfile.RegionCode      = "";
                if (user.OpCoId != -1)
                {
                    newProfile.OpCoCode = OpcoController.GetOpCo(user.OpCoId, false).Code;
                }

                if (user.RegionId != -1)
                {
                    newProfile.RegionCode = OptrakRegionController.GetRegion(user.RegionId).Code;
                }

                newProfile.Save();


                Membership.CreateUser(user.UserName, user.NewPassword, user.Email);
                return(user.UserName);
            }
            return("");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:UserDetails"/> class.
        /// </summary>
        /// <param name="membershipUser">The membership user.</param>
        /// <param name="getProfile">if set to <c>true</c> [get profile].</param>
        public UserDetails(MembershipUser membershipUser, bool getProfile)
        {
            if (membershipUser != null)
            {
                UserName         = membershipUser.UserName;
                Email            = membershipUser.Email;
                LastActivityDate = membershipUser.LastActivityDate.ToShortDateString();

                if (getProfile)
                {
                    ProfileCommon p       = new ProfileCommon();
                    ProfileCommon profile = p.GetProfile(membershipUser.UserName);


                    if (profile != null)
                    {
                        OpCoId          = profile.OpCoId;
                        OpCoCode        = profile.OpCoCode;
                        RegionId        = profile.RegionId;
                        RegionCode      = profile.RegionCode;
                        WarehouseId     = profile.WarehouseId;
                        SalesLocationId = profile.SalesLocationId;
                        SalesLocation   = SalesLocationController.GetLocation(salesLocationId, false);
                        OpCo            = OpcoController.GetOpCo(OpCoId, false);
                        Warehouse       = WarehouseController.GetWarehouse(WarehouseId);
                        Region          = OptrakRegionController.GetRegion(RegionId);
                    }
                }
            }
        }
        /// <summary>
        /// Updates the user and profile.
        /// </summary>
        /// <param name="user">The user.</param>
        public static string UpdateUserAndProfile(UserDetails user)
        {
            if (user.IsValid)
            {
                MembershipUser membershipUser = Membership.GetUser(user.UserName);
                membershipUser.Email = user.Email;
                bool success = true;
                if (!string.IsNullOrEmpty(user.OldPassword) && !string.IsNullOrEmpty(user.NewPassword))
                {
                    success = membershipUser.ChangePassword(user.OldPassword, user.NewPassword);
                }
                if (success)
                {
                    Membership.UpdateUser(membershipUser);

                    //update profile too
                    ProfileCommon p = new ProfileCommon();
                    ProfileCommon selectedProfile = p.GetProfile(user.UserName);
                    selectedProfile.WarehouseId     = user.WarehouseId;
                    selectedProfile.RegionId        = user.RegionId;
                    selectedProfile.SalesLocationId = user.SalesLocationId;
                    selectedProfile.OpCoId          = user.OpCoId;
                    selectedProfile.OpCoCode        = "";
                    selectedProfile.RegionCode      = "";
                    if (user.OpCoId != -1)
                    {
                        selectedProfile.OpCoCode = OpcoController.GetOpCo(user.OpCoId, false).Code;
                    }

                    if (user.RegionId != -1)
                    {
                        selectedProfile.RegionCode = OptrakRegionController.GetRegion(user.RegionId).Code;
                    }

                    selectedProfile.Save();

                    return(user.UserName);
                }
                else
                {
                    throw new SystemException("The Password has not be successfully changed.");
                }
            }
            return("");
        }
Esempio n. 4
0
 internal OptrakRegion GetItem(int id)
 {
     return(OptrakRegionController.GetRegion(id));
 }