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 ActionResult Register(FormCollection formCollection, RegisterViewModel viewModel, string returnUrl) { if (ModelState.IsValid) { var userEntity = new UserEntity(); userEntity.CreatedDate = DateTime.Now; userEntity.UpdatedDate = DateTime.Now; userEntity.Description = String.Empty; userEntity.EMail = viewModel.Email; userEntity.Gender = 0; userEntity.LastLoginDate = DateTime.Now; userEntity.Logo = String.Empty; userEntity.Mobile = String.Empty; userEntity.Name = viewModel.UserName; userEntity.Password = viewModel.Password; userEntity.Nickname = viewModel.Nickname; userEntity.Status = (int)DataStatus.Normal; userEntity.UserLevel = (int)UserLevel.User; var e = _customerRepository.Insert(userEntity); //写认证 SetAuthorize(new WebSiteUser(e.Name, e.Id, e.Nickname, UserRole.User)); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } return RedirectToAction("Index"); } else { ModelState.AddModelError("", "验证错误."); } return View(viewModel); }
public UserModel UserModelMapping(UserEntity source) { if (source == null) { return null; } //var target = Mapper.Map<UserEntity, UserModel>(source); //这步可以判断 //modelAccount var accounts = UserAccountMapping(_userAccountRepository.GetUserAccount(source.Id)).ToList(); //roles var userRoles = UserRolesMapping(_vUserRoleRepository.GetList(source.Id)); return UserModelMapping(source, accounts, userRoles); }
private static UserModel UserModelMapping(UserEntity source, List<UserAccountModel> userAccountModels, List<UserRole> userRoles) { if (source == null) { return null; } var target = Mapper.Map<UserEntity, UserModel>(source); //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; }
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; }
public UserEntity UserEntityMapping(UserEntity source, UserEntity target) { var result = Mapper.Map(source, target); return UserEntityCheck(result); }
public UserModel Insert(UserEntity entity) { var e = _customerRepository.Insert(entity); return Get(e.Id); }