예제 #1
0
        /// <summary>
        /// 获取所有用户的信息。
        /// </summary>
        /// <param name="spec">查询方式。</param>
        /// <returns>包含了所有用户信息的数据传输对象列表。</returns>
        public UserDataObjectList GetUsers(QuerySpec spec)
        {
            var users = userRepository.FindAll();

            if (users == null)
            {
                return(null);
            }
            var ret = new UserDataObjectList();

            foreach (var user in users)
            {
                var userDataObject = Mapper.Map <User, UserDataObject>(user);
                if (spec.IsVerbose())
                {
                    var role = userRoleRepository.GetRoleForUser(user);
                    if (role != null)
                    {
                        userDataObject.Role = Mapper.Map <Role, RoleDataObject>(role);
                    }
                }
                ret.Add(userDataObject);
            }
            return(ret);
        }
예제 #2
0
 /// <summary>
 /// 删除用户。
 /// </summary>
 /// <param name="userDataObjects">需要删除的用户对象。</param>
 public void DeleteUsers(UserDataObjectList userDataObjects)
 {
     if (userDataObjects == null)
     {
         throw new ArgumentNullException("userDataObjects");
     }
     foreach (var userDataObject in userDataObjects)
     {
         User user = null;
         if (!IsEmptyGuidString(userDataObject.ID))
         {
             user = userRepository.GetByKey(new Guid(userDataObject.ID));
         }
         else if (!string.IsNullOrEmpty(userDataObject.UserName))
         {
             user = userRepository.GetUserByName(userDataObject.UserName);
         }
         else if (!string.IsNullOrEmpty(userDataObject.Email))
         {
             user = userRepository.GetUserByEmail(userDataObject.Email);
         }
         else
         {
             throw new ArgumentNullException("userDataObject", "Either ID, UserName or Email should be specified.");
         }
         var userRole = userRoleRepository.Find(Specification <UserRole> .Eval(ur => ur.UserID == user.ID));
         if (userRole != null)
         {
             userRoleRepository.Remove(userRole);
         }
         userRepository.Remove(user);
     }
     Context.Commit();
 }
예제 #3
0
        public ByteartRetailMembershipUser CreateUser(string username,
                                                      string password,
                                                      string email,
                                                      string passwordQuestion,
                                                      string passwordAnswer,
                                                      bool isApproved,
                                                      object providerUserKey,
                                                      string contact,
                                                      string phoneNumber,
                                                      AddressDataObject contactAddress,
                                                      AddressDataObject deliveryAddress,
                                                      out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);
            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }
            if (RequiresUniqueEmail && !string.IsNullOrEmpty(GetUserNameByEmail(email)))
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return(null);
            }
            ByteartRetailMembershipUser user = GetUser(username, true) as ByteartRetailMembershipUser;

            if (user == null)
            {
                using (ServiceProxy <IUserService> proxy = new ServiceProxy <IUserService>())
                {
                    UserDataObjectList userDataObjects = new UserDataObjectList
                    {
                        new UserDataObject
                        {
                            UserName        = username,
                            Password        = password,
                            Contact         = contact,
                            DateLastLogon   = null,
                            DateRegistered  = DateTime.Now,
                            Email           = email,
                            IsDisabled      = false,
                            PhoneNumber     = phoneNumber,
                            ContactAddress  = contactAddress,
                            DeliveryAddress = deliveryAddress
                        }
                    };
                    proxy.Channel.CreateUsers(userDataObjects);
                }
                status = MembershipCreateStatus.Success;
                return(GetUser(username, true) as ByteartRetailMembershipUser);
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
                return(null);
            }
        }
예제 #4
0
 public void DeleteUsers(UserDataObjectList userDataObjects)
 {
     try
     {
          userServiceImpl.DeleteUsers(userDataObjects);
     }
     catch(Exception ex)
     {
         throw new FaultException<FaultData>(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
     }
 }
 public void DeleteUsers(UserDataObjectList userDataObjects)
 {
     try
     {
         userServiceImpl.DeleteUsers(userDataObjects);
     }
     catch (Exception ex)
     {
         throw new FaultException <FaultData>(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
     }
 }
 public UserDataObjectList UpdateUsers(UserDataObjectList userDataObjects)
 {
     try
     {
         return(userServiceImpl.UpdateUsers(userDataObjects));
     }
     catch (Exception ex)
     {
         throw new FaultException <FaultData>(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
     }
 }
		public UserDataObjectList UpdateUsers(UserDataObjectList userDataObjects)
		{
			try
			{
				return _userServiceImpl.UpdateUsers(userDataObjects);
			}
			catch(Exception ex)
			{
				throw new FaultException<FaultData>(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
			}
		}
예제 #8
0
 /// <summary>
 /// 根据指定的客户信息,创建客户对象。
 /// </summary>
 /// <param name="userDataObjects">包含了客户信息的数据传输对象。</param>
 /// <returns>已创建客户对象的全局唯一标识。</returns>
 public UserDataObjectList CreateUsers(UserDataObjectList userDataObjects)
 {
     if (userDataObjects == null)
         throw new ArgumentNullException("userDataObjects");
     return PerformCreateObjects<UserDataObjectList, UserDataObject, User>(userDataObjects, 
         userRepository, 
         dto =>
         {
             if (dto.DateRegistered == null)
                 dto.DateRegistered = DateTime.Now;
         },
         ar =>
         {
             var shoppingCart = ar.CreateShoppingCart();
             shoppingCartRepository.Add(shoppingCart);
         });
 }
예제 #9
0
 /// <summary>
 /// 根据指定的客户信息,创建客户对象。
 /// </summary>
 /// <param name="userDataObjects">包含了客户信息的数据传输对象。</param>
 /// <returns>已创建客户对象的全局唯一标识。</returns>
 public UserDataObjectList CreateUsers(UserDataObjectList userDataObjects)
 {
     if (userDataObjects == null)
     {
         throw new ArgumentNullException("userDataObjects");
     }
     return(PerformCreateObjects <UserDataObjectList, UserDataObject, User>(userDataObjects,
                                                                            userRepository,
                                                                            dto =>
     {
         if (dto.DateRegistered == null)
         {
             dto.DateRegistered = DateTime.Now;
         }
     },
                                                                            ar =>
     {
         var shoppingCart = ar.CreateShoppingCart();
         shoppingCartRepository.Add(shoppingCart);
     }));
 }
예제 #10
0
 /// <summary>
 /// 根据指定的用户信息,更新用户对象。
 /// </summary>
 /// <param name="userDataObjects">需要更新的用户对象。</param>
 /// <returns>已更新的用户对象。</returns>
 public UserDataObjectList UpdateUsers(UserDataObjectList userDataObjects)
 {
     return(PerformUpdateObjects <UserDataObjectList, UserDataObject, User>(userDataObjects, userRepository,
                                                                            udo => udo.ID,
                                                                            (u, udo) =>
     {
         if (!string.IsNullOrEmpty(udo.Contact))
         {
             u.Contact = udo.Contact;
         }
         if (!string.IsNullOrEmpty(udo.PhoneNumber))
         {
             u.PhoneNumber = udo.PhoneNumber;
         }
         if (udo.ContactAddress != null)
         {
             if (!string.IsNullOrEmpty(udo.ContactAddress.City))
             {
                 u.ContactAddress.City = udo.ContactAddress.City;
             }
             if (!string.IsNullOrEmpty(udo.ContactAddress.Country))
             {
                 u.ContactAddress.Country = udo.ContactAddress.Country;
             }
             if (!string.IsNullOrEmpty(udo.ContactAddress.State))
             {
                 u.ContactAddress.State = udo.ContactAddress.State;
             }
             if (!string.IsNullOrEmpty(udo.ContactAddress.Street))
             {
                 u.ContactAddress.Street = udo.ContactAddress.Street;
             }
             if (!string.IsNullOrEmpty(udo.ContactAddress.Zip))
             {
                 u.ContactAddress.Zip = udo.ContactAddress.Zip;
             }
         }
         if (udo.DeliveryAddress != null)
         {
             if (!string.IsNullOrEmpty(udo.DeliveryAddress.City))
             {
                 u.DeliveryAddress.City = udo.DeliveryAddress.City;
             }
             if (!string.IsNullOrEmpty(udo.DeliveryAddress.Country))
             {
                 u.DeliveryAddress.Country = udo.DeliveryAddress.Country;
             }
             if (!string.IsNullOrEmpty(udo.DeliveryAddress.State))
             {
                 u.DeliveryAddress.State = udo.DeliveryAddress.State;
             }
             if (!string.IsNullOrEmpty(udo.DeliveryAddress.Street))
             {
                 u.DeliveryAddress.Street = udo.DeliveryAddress.Street;
             }
             if (!string.IsNullOrEmpty(udo.DeliveryAddress.Zip))
             {
                 u.DeliveryAddress.Zip = udo.DeliveryAddress.Zip;
             }
         }
         if (udo.DateLastLogon != null)
         {
             u.DateLastLogon = udo.DateLastLogon;
         }
         if (udo.DateRegistered != null)
         {
             u.DateRegistered = udo.DateRegistered.Value;
         }
         if (!string.IsNullOrEmpty(udo.Email))
         {
             u.Email = udo.Email;
         }
         if (udo.IsDisabled != null)
         {
             if (udo.IsDisabled.Value)
             {
                 u.Disable();
             }
             else
             {
                 u.Enable();
             }
         }
         if (!string.IsNullOrEmpty(udo.Password))
         {
             u.Password = udo.Password;
         }
     }));
 }
예제 #11
0
 /// <summary>
 /// 获取所有用户的信息。
 /// </summary>
 /// <param name="spec">查询方式。</param>
 /// <returns>包含了所有用户信息的数据传输对象列表。</returns>
 public UserDataObjectList GetUsers(QuerySpec spec)
 {
     var users = userRepository.FindAll();
     if (users == null)
         return null;
     var ret = new UserDataObjectList();
     foreach (var user in users)
     {
         var userDataObject = Mapper.Map<User, UserDataObject>(user);
         if (spec.IsVerbose())
         {
             var role = userRoleRepository.GetRoleForUser(user);
             if (role != null)
             {
                 userDataObject.Role = Mapper.Map<Role, RoleDataObject>(role);
             }
         }
         ret.Add(userDataObject);
     }
     return ret;
 }
예제 #12
0
 /// <summary>
 /// 删除用户。
 /// </summary>
 /// <param name="userDataObjects">需要删除的用户对象。</param>
 public void DeleteUsers(UserDataObjectList userDataObjects)
 {
     if (userDataObjects == null)
         throw new ArgumentNullException("userDataObjects");
     foreach (var userDataObject in userDataObjects)
     {
         User user = null;
         if (!IsEmptyGuidString(userDataObject.ID))
             user = userRepository.GetByKey(new Guid(userDataObject.ID));
         else if (!string.IsNullOrEmpty(userDataObject.UserName))
             user = userRepository.GetUserByName(userDataObject.UserName);
         else if (!string.IsNullOrEmpty(userDataObject.Email))
             user = userRepository.GetUserByEmail(userDataObject.Email);
         else
             throw new ArgumentNullException("userDataObject", "Either ID, UserName or Email should be specified.");
         var userRole = userRoleRepository.Find(Specification<UserRole>.Eval(ur => ur.UserID == user.ID));
         if (userRole != null)
             userRoleRepository.Remove(userRole);
         userRepository.Remove(user);
     }
     Context.Commit();
 }
예제 #13
0
 /// <summary>
 /// 根据指定的用户信息,更新用户对象。
 /// </summary>
 /// <param name="userDataObjects">需要更新的用户对象。</param>
 /// <returns>已更新的用户对象。</returns>
 public UserDataObjectList UpdateUsers(UserDataObjectList userDataObjects)
 {
     return PerformUpdateObjects<UserDataObjectList, UserDataObject, User>(userDataObjects, userRepository,
         udo => udo.ID,
         (u, udo) =>
         {
             if (!string.IsNullOrEmpty(udo.Contact))
                 u.Contact = udo.Contact;
             if (!string.IsNullOrEmpty(udo.PhoneNumber))
                 u.PhoneNumber = udo.PhoneNumber;
             if (udo.ContactAddress != null)
             {
                 if (!string.IsNullOrEmpty(udo.ContactAddress.City))
                     u.ContactAddress.City = udo.ContactAddress.City;
                 if (!string.IsNullOrEmpty(udo.ContactAddress.Country))
                     u.ContactAddress.Country = udo.ContactAddress.Country;
                 if (!string.IsNullOrEmpty(udo.ContactAddress.State))
                     u.ContactAddress.State = udo.ContactAddress.State;
                 if (!string.IsNullOrEmpty(udo.ContactAddress.Street))
                     u.ContactAddress.Street = udo.ContactAddress.Street;
                 if (!string.IsNullOrEmpty(udo.ContactAddress.Zip))
                     u.ContactAddress.Zip = udo.ContactAddress.Zip;
             }
             if (udo.DeliveryAddress != null)
             {
                 if (!string.IsNullOrEmpty(udo.DeliveryAddress.City))
                     u.DeliveryAddress.City = udo.DeliveryAddress.City;
                 if (!string.IsNullOrEmpty(udo.DeliveryAddress.Country))
                     u.DeliveryAddress.Country = udo.DeliveryAddress.Country;
                 if (!string.IsNullOrEmpty(udo.DeliveryAddress.State))
                     u.DeliveryAddress.State = udo.DeliveryAddress.State;
                 if (!string.IsNullOrEmpty(udo.DeliveryAddress.Street))
                     u.DeliveryAddress.Street = udo.DeliveryAddress.Street;
                 if (!string.IsNullOrEmpty(udo.DeliveryAddress.Zip))
                     u.DeliveryAddress.Zip = udo.DeliveryAddress.Zip;
             }
             if (udo.DateLastLogon != null)
                 u.DateLastLogon = udo.DateLastLogon;
             if (udo.DateRegistered != null)
                 u.DateRegistered = udo.DateRegistered.Value;
             if (!string.IsNullOrEmpty(udo.Email))
                 u.Email = udo.Email;
             if (udo.IsDisabled != null)
             {
                 if (udo.IsDisabled.Value)
                     u.Disable();
                 else
                     u.Enable();
             }
             if (!string.IsNullOrEmpty(udo.Password))
                 u.Password = udo.Password;
         });
 }
 public ByteartRetailMembershipUser CreateUser(string username, 
     string password, 
     string email, 
     string passwordQuestion, 
     string passwordAnswer, 
     bool isApproved, 
     object providerUserKey, 
     string contact, 
     string phoneNumber, 
     AddressDataObject contactAddress, 
     AddressDataObject deliveryAddress, 
     out MembershipCreateStatus status)
 {
     ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);
     OnValidatingPassword(args);
     if (args.Cancel)
     {
         status = MembershipCreateStatus.InvalidPassword;
         return null;
     }
     if (RequiresUniqueEmail && !string.IsNullOrEmpty(GetUserNameByEmail(email)))
     {
         status = MembershipCreateStatus.DuplicateEmail;
         return null;
     }
     ByteartRetailMembershipUser user = GetUser(username, true) as ByteartRetailMembershipUser;
     if (user == null)
     {
         using (ServiceProxy<IUserService> proxy = new ServiceProxy<IUserService>())
         {
             UserDataObjectList userDataObjects = new UserDataObjectList
             {
                 new UserDataObject
                 {
                     UserName = username,
                     Password = password,
                     Contact = contact,
                     DateLastLogon = null,
                     DateRegistered = DateTime.Now,
                     Email = email,
                     IsDisabled = false,
                     PhoneNumber = phoneNumber,
                     ContactAddress = contactAddress,
                     DeliveryAddress = deliveryAddress
                 }
             };
             proxy.Channel.CreateUsers(userDataObjects);
         }
         status = MembershipCreateStatus.Success;
         return GetUser(username, true) as ByteartRetailMembershipUser;
     }
     else
     {
         status = MembershipCreateStatus.DuplicateUserName;
         return null;
     }
 }