private static UserEntity CheckUserEntity(UserEntity source) { if (source == null) { return null; } source.Name = CheckString(source.Name); source.Description = CheckString(source.Description); source.EMail = CheckString(source.EMail); source.Logo = CheckString(source.Logo); source.Mobile = CheckString(source.Mobile); source.Nickname = CheckString(source.Nickname); source.Password = CheckString(source.Password); return source; }
public UserModel UserModelMapping(UserEntity source) { if (source == null) { return null; } //var target = Mapper.Map<UserEntity, UserModel>(source); //这步可以判断 StoreModel store = null; if (source.Store_Id > 0) { store = StoreModelMapping(_storeRepository.GetItem(source.Store_Id)); } //modelAccount var accounts = UserAccountMapping(_userAccountRepository.GetUserAccount(source.Id)).ToList(); //roles var userRoles = UserRolesMapping(_vUserRoleRepository.GetList(source.Id)); return UserModelMapping(source, store, accounts, userRoles); }
private static UserModel UserModelMapping(UserEntity source, StoreModel storeModel, List<UserAccountModel> userAccountModels, List<int> userRoles) { if (source == null) { return null; } var target = Mapper.Map<UserEntity, UserModel>(source); //这步可以判断 target.Store = storeModel; //modelAccount target.Accounts = userAccountModels; //roles target.UserRoles = userRoles; //favorcount //ilikecount //likemecount //LOGO if (!String.IsNullOrWhiteSpace(target.Logo)) { if (!target.Logo.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) { target.Logo = ConfigManager.GetHttpApiImagePath() + target.Logo; } } if (target.Accounts == null || target.Accounts.Count == 0) { return target; } foreach (var item in target.Accounts) { switch (item.AType) { case AccountType.ConsumptionCount: target.ConsumptionCount = (int)item.Amount; break; case AccountType.Coupon: target.CouponCount = (int)item.Amount; break; case AccountType.FavorCount: target.FavorCount = (int)item.Amount; break; case AccountType.IlikeCount: target.ILikeCount = (int)item.Amount; break; case AccountType.LikeMeCount: target.LikeMeCount = (int)item.Amount; break; case AccountType.Point: target.PointCount = (int)item.Amount; break; case AccountType.ShareCount: target.ShareCount = (int)item.Amount; break; } } return target; }
public ShowCustomerInfoResponse ShowCustomerInfoResponseMapping(UserEntity source) { if (source == null) { return null; } var model = UserModelMapping(source); if (model == null) { return null; } return ShowCustomerInfoResponseMapping(model); }
private static UserEntity UserEntityCheck(UserEntity source) { if (source == null) { return null; } source.Description = source.Description ?? String.Empty; source.EMail = source.EMail ?? String.Empty; source.Logo = source.Logo ?? String.Empty; source.Mobile = source.Mobile ?? String.Empty; source.Name = source.Name ?? String.Empty; source.Nickname = source.Nickname ?? String.Empty; source.Password = source.Password ?? String.Empty; source.CreatedDate = EntityDateTime(source.CreatedDate); source.UpdatedDate = EntityDateTime(source.UpdatedDate); return source; }
//[System.Obsolete("建议使用usermodel")] //public ShowCustomerInfoResponse ShowCustomerInfoResponseMapping(UserEntity source, // List<ResourceEntity> resourceEntities) //{ // if (source == null) // { // return null; // } // var target = Mapper.Map<UserEntity, ShowCustomerInfoResponse>(source); // //if (resourceEntities != null && resourceEntities.Count > 0) // //{ // // var resource = resourceEntities.FirstOrDefault(); // // if (resource != null) // // { // // target.Logo = Path.Combine(resource.Domain, resource.Name); // // } // //} // return target; //} ////[System.Obsolete("建议使用usermodel")] ////public ShowCustomerInfoResponse ShowCustomerInfoResponseMapping(UserEntity source) ////{ //// if (source == null) //// { //// return null; //// } //// //var resources = _resourceRepository.GetList((int)SourceType.CustomerPortrait, source.Id); //// //return UserShowResponseMapping(source, resources); //// return ShowCustomerInfoResponseMapping(source, null); ////} //[System.Obsolete("建议使用usermodel")] //public IEnumerable<ShowCustomerInfoResponse> ShowCustomerInfoResponseMapping(List<UserEntity> source) //{ // if (source == null || source.Count == 0) // { // return new List<ShowCustomerInfoResponse>(0); // } // var result = new List<ShowCustomerInfoResponse>(source.Count); // foreach (var item in source) // { // var target = ShowCustomerInfoResponseMapping(item, null); // if (target != null) // { // result.Add(target); // } // } // return result; //} //[System.Obsolete("建议使用usermodel")] //public CustomerInfoResponse CustomerInfoResponseMapping(UserEntity source) //{ // if (source == null) // { // return null; // } // var target = Mapper.Map<UserEntity, CustomerInfoResponse>(source); // return target; //} //[System.Obsolete("建议使用usermodel")] //public IEnumerable<CustomerInfoResponse> CustomerInfoResponseMapping(List<UserEntity> source) //{ // foreach (var entity in source) // { // yield return CustomerInfoResponseMapping(entity); // } //} public UserEntity UserEntityMapping(UserEntity source, UserEntity target) { var result = Mapper.Map(source, target); return UserEntityCheck(result); }