public async Task CreateUserAsync(IUserModel newUser) { if (newUser == null) { throw new ArgumentNullException("newUser"); } EntityValidationResult result = _entityValidator.ValidateEntity(newUser, _validationContextFactory(newUser)); if (result.IsValid == false) { throw new InvalidUserDataException(result.ValidationResults); } IdentityResult identityResult = await _userManager.CreateAsync(_userDtoMapper.Map(newUser)); if (!identityResult.Succeeded) { var validationResults = new List<ValidationResult>(result.ValidationResults); validationResults.AddRange(identityResult.Errors.Select(e => new ValidationResult(e))); throw new InvalidUserDataException(validationResults); } IUserDto createdUser = await _userManager.FindByEmailAsync(newUser.Email); await _emailService.SendUserRegistrationConfirmationEmailAsync(createdUser); }
public TestPreviewViewModel(IUserModel user) { if (user == null) throw new ArgumentNullException("user"); _user = user; InitializeCommands(); }
public UserRegistrationViewModel(IUserModel user) { if (user == null) throw new ArgumentNullException("user"); _user = user; InitializeCommands(); }
public Mail(IUserModel fromUser, IUserModel toUser, string n,string param) { // this.fromUser = fromUser; this.toUser = toUser; this.n = n; this.param = param; // this.dayOfYear = DateTime.Now.DayOfYear; }
public TestViewModel(IUserModel user) { if (user == null) throw new ArgumentNullException("user"); if (user.CurrentTest == null) throw new ArgumentException("You must have selected a test."); _user = user; InitializeCommands(); InitializeQuestions(); }
public TestSelectionViewModel(IUserModel user, ITestQuery testsDb) { if (user == null) throw new ArgumentNullException("user"); if (testsDb == null) throw new ArgumentNullException("tests"); _user = user; _testsDb = testsDb; LoadTests(); InitializeCommands(); }
public TestEvaluationViewModel( IUserModel user, ITestEvaluator evaluator, IInterpretationBuilder interpreter ) { if (evaluator == null) throw new ArgumentNullException("evaluator"); if (interpreter == null) throw new ArgumentNullException("interpreter"); if (user == null) throw new ArgumentNullException("user"); _userName = user.Name; InitializeAssessment(user, evaluator, interpreter); InitalizeCommands(); }
public static OrderModel Create(IUserModel userModel, IEnumerable<CartItemModel> cartItems) { if (userModel.BillingAddress == null) { throw new ArgumentException("Billing address cannot be empty."); } var order = new OrderModel { BillingAddress = userModel.BillingAddress, User = userModel }; foreach (var cartItem in cartItems) { order.Orderlines.Add(OrderlineModel.Create(cartItem)); } order.Status = OrderStatus.Unpaid; order.Key = GenerateOrderId(); order.DateCreated = DateTime.UtcNow; order.TotalSpecialPrice = cartItems .ToList() .Select(c => c.DealOption.SpecialPrice) .Aggregate(0.0d, (c1, c2) => { return c1 + c2; }); order.TotalRegularPrice = cartItems .ToList() .Select(c => c.DealOption.RegularPrice) .Aggregate(0.0d, (c1, c2) => { return c1 + c2; }); return order; }
public UserServiceTest() { _userManager = A.Fake<UserManager<IUserDto, int>>(); _userDtoMapper = A.Fake<IUserDtoMapper>(); _emailService = A.Fake<IEmailService>(); _entityValidator = A.Fake<EntityValidator>(); _userRepository = A.Fake<IUserRepository>(); _userService = new UserService(_userManager, _userDtoMapper, _emailService, _entityValidator, _userRepository, o => new ValidationContext(o, null, null)); _validUser = new User { FirstName = "test", LastName = "test", UserType = UserType.Student, Group = new Group { GroupNumber = 2, Year = 2009 }, Email = "*****@*****.**" }; _invalidEmptyUser = new User(); }
/// <summary> /// 这里的add调用前要加逻辑判断,不像session那样可以直接add /// 已在线,需要先挤掉 /// </summary> /// <param name="strIpPort"></param> /// <param name="user"></param> public void addUser(string strIpPort, IUserModel user) { removeUser(strIpPort); _userList.Add(strIpPort, user); }
public void setGameOver(IUserModel leaveUser) { //loop use int len = this._chair.Count; for (int i = 0; i < len; i++) { IChairModel chair = this._chair[i]; if ("" == chair.User.Id) { chair.setUser(leaveUser); break; } } //for (int i = 0; i < len; i++) //{ //IChairModel chair = this._chair[i]; //if (chair.User.Id == leaveUser.Id) //{ //离开的人是地主 //if (chair.User.Id == this.dizhu) if (leaveUser.Id == this.dizhu) { //逃跑惩罚,加上所有未出的炸弹 this.leaveUserId = leaveUser.Id;//chair.getUser().Id; this.leaveBomb = getAllHasBombCount(); this._matchResult = this.MATCH_RESULT.NONGMING_WIN; this.setStatus(RoomStatusByDdz.GAMEOVER_WAIT_START); //break; } //else if(this.nongming.IndexOf(chair.getUser().Id) >= 0) else if (this.nongming.IndexOf(leaveUser.Id) >= 0) { //逃跑惩罚,加上所有未出的炸弹 this.leaveUserId = leaveUser.Id; this.leaveBomb = getAllHasBombCount(); this._matchResult = this.MATCH_RESULT.DIZHU_WIN; this.setStatus(RoomStatusByDdz.GAMEOVER_WAIT_START); // break; } else { //未分出地主和农民离开的人 //强设地主和农民 this.dizhu = leaveUser.Id;//chair.getUser().Id; List<IChairModel> list = this.getOtherChair( leaveUser.Id //chair.getUser().Id ); this.setNongMing(list); //惩罚性扣分 //调高房间底分 this._matchResult = this.MATCH_RESULT.NONGMING_WIN; this.setStatus(RoomStatusByDdz.GAMEOVER_WAIT_START); //break; } //} //}//end for //leave 上层函数结束指令生成后再调用 //setLeaveUser(leaveUser); }
public void setLeaveUser(IUserModel leaveUser) { //loop use int len = this._chair.Count; for (int i = 0; i < len; i++) { IChairModel chair = this._chair[i]; if (chair.getUser().Id == leaveUser.Id) { if (leaveUser.Id == this.dizhu) { //重设棋基 if (!this.isWaitReconnection) { this.dizhu = ""; } }else { // if (!this.isWaitReconnection) { this.nongming = ""; } } //reset chair.reset(); } }//end for }
public bool hasSameIpPeople(IUserModel user, bool isOnChair) { //test //return false; if (isOnChair) { for (int i = 0; i < this._chair.Count; i++) { IChairModel chair = this._chair[i]; if ("" != chair.getUser().Id) { string[] compare_1 = chair.getUser().getStrIpPort().Split(':'); string[] compare_2 = user.getStrIpPort().Split(':'); if (compare_1[0] == compare_2[0]) { return true; } } }//end for } return false; }
/// <summary> /// /// </summary> /// <param name="value"></param> public RoomModelByToac(IUserModel value) { _u = value.clone(); _pickResult = new string[]{ "0", "0", "0" }; }
public void Create(IUserModel model) { throw new NotImplementedException(); }
private void TimedAutoMatchRoom_Sub_Match(ref IRoomModel room, AutoMatchRoomModel amr, IUserModel user, AppSession userSession, ref ToSitDownStatus sitDownStatus, ref bool sitDown, ref int roomId, int matchLvl) { try { foreach (int roomKey in roomList.Keys) { room = (IRoomModel)roomList.get(roomKey); //自动匹配差1人 if (amr.Tab == room.Tab) { roomId = room.Id; //不可为上次的房间,否则会因三人中的二人未退出,又匹配到该房间 if (amr.getRoomOldId() == roomId) { continue; } //不可为正在游戏中的房间 if (room.hasGamePlaying()) { continue; } //不可为断线重连中的房间 if (room.isWaitReconnection) { continue; } //不可为有尸体的房间 if (logicChkRoomByDeadPeople(roomId)) { continue; } //自动匹配原则是 差1人的游戏最佳 //所以这里不能单单只是坐下,要做在差一人的坐位上 sitDown = logicHasIdleChairAndMatchSitDown(roomId, matchLvl, //user.getStrIpPort(), userSession.RemoteEndPoint.ToString(), true, out sitDownStatus); if (sitDown) { TimedAutoMatchRoom_Sub_SitDown_Ok(room, userSession); break; }//end if }//end if }//end for } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "TimedAutoMatchRoom_Sub_Match", exd.Message, exd.Source, exd.StackTrace); } }
private void SetProperties(IUserModel source) { _data.Username = source.Username; _data.Password = source.Password; _data.Email = source.Email; _data.DateOfBirth = source.DateOfBirth; _data.Description = source.Description; }
public RoomModelByDdz(int id, IRuleModel rule, int tab, string gridXml) { this._id = id; this._tab = tab; if ("" == gridXml) { this._name = string.Empty; } else { XmlDocument gridDoc = new XmlDocument(); gridDoc.LoadXml(gridXml); this._name = gridDoc.DocumentElement.Attributes["name"].Value; } this.setStatus(RoomStatusByDdz.GAME_WAIT_START); this._matchResult = MATCH_RESULT.EMPTY; this._chair = new List<IChairModel>(); for (int i = 1; i <= rule.getChairCount(); i++) { this._chair.Add(ChairModelFactory.Create(i, rule)); }//end for //red = ""; //black = ""; this.difen = ""; this.bomb = 0; this.leaveBomb = 0; this.leaveUserId = ""; this.dizhu = ""; this.nongming = ""; this.mingpai = ""; this.turn = ""; this._board = new PaiBoardByDdz(); this._record = new RoundModelByDdz(ROUND_TYPE.JIAO_FEN); this._round = new List<RoundModelByDdz>(); _runAwayMultiG = 1; _isWaitReconnection = false; _curWaitReconnectionTime = 0; _waitReconnectionUser = null; }
public IUserDto Map(IUserModel userModel) { return Mapper.Map<UserDto>(userModel); }
/// <summary> /// IChairModel包含 User,能提供更多信息 /// </summary> /// <param name="value"></param> /// <returns></returns> public List<IChairModel> findUser(IUserModel value) { List<IChairModel> users = new List<IChairModel>(); //loop use int i = 0; int len = this._chair.Count; //check for (i = 0; i < len; i++) { if ((this._chair[i] as IChairModel).getUser().Id == value.Id) { break; } //到这里还没跳出循环,说明没找到 if (i == (len - 1)) { throw new ArgumentException("can not found user id:" + value.Id); } } //add for (i = 0; i < len; i++) { if ((this._chair[i] as IChairModel).getUser().Id != value.Id) { users.Add((this._chair[i] as IChairModel)); } } return users; }
/// <summary> /// 使用该方法先使用 hasPeople /// </summary> /// <param name="user"></param> /// <returns></returns> public IChairModel getChair(IUserModel user) { //loop use int len = this._chair.Count; for (int i = 0; i < len; i++) { IChairModel chair = this._chair[i]; if (chair.getUser().Id == user.Id) { return chair; } }//end for //throw new ArgumentException("can not find user " + user.Id + " func:getChair"); return null; }
/// <summary> /// 通过某人逃跑判定输赢 /// 并且重置该座位 /// 前台调用发 UserLeave指令 /// /// 注意此人是leaveUser,所以还要设置棋基 /// /// 发了游戏结束指令后,再setLeaveUser /// </summary> /// <param name="leaveUser"></param> /// public void setWaitReconnection(IUserModel waitUser) { if (null == waitUser) { this._isWaitReconnection = false; } else { this._isWaitReconnection = true; } this._waitReconnectionUser = waitUser; }
protected IUserModel AuthenticateUser(IUserModel value, bool rememberMe) { Contract.Assert(value != null); var ticket = new FormsAuthenticationTicket( 1, value.Login, DateTime.Now, DateTime.Now + FormsAuthentication.Timeout, rememberMe, value.Id.ToString()); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)) { HttpOnly = true, Expires = DateTime.Now + FormsAuthentication.Timeout, Path = FormsAuthentication.FormsCookiePath, Domain = FormsAuthentication.CookieDomain, Secure = FormsAuthentication.RequireSSL }; this.HttpContext.Response.SetCookie(authCookie); this.CurrentUser = value; this.ResetCurrentAccount(); return value; }
/// <summary> /// 坐下 /// </summary> /// <param name="user"></param> /// <returns></returns> public bool setSitDown(IUserModel user) { //loop use int len = this._chair.Count; int i = 0; IChairModel c = null; // for (i = 0; i < len; i++) { c = this._chair[i]; if (user.Id == c.getUser().Id) { //已经坐在本房间的另一个座位上 return true; } } // for (i = 0; i < len; i++) { c = this._chair[i]; if ("" != c.getUser().Id) { //有人,不能坐 } else { c.setUser(user); //设置棋基,决定谁先走 //设定谁先叫地主,这里不由谁先坐下决定,由明牌ready和随机决定 return true; }//end if }//end for return false; }
public void Update(IUserModel model) { this.dbContext.Update(model); }
/// <summary> /// /// </summary> /// <param name="fromUser">需使用拷贝的参数</param> /// <param name="toUser">需使用拷贝的参数</param> /// <param name="n">val Attributes["n"]</param> /// <param name="c">val InnerText</param> public void setMvars(IUserModel fromUser,IUserModel toUser,string n,string param) { Mail m = new Mail(fromUser, toUser, n, param); _pipe.Add(m); }
/// <summary> /// Initializes a new instance of the <see cref="Userpresenter"/> class. /// </summary> /// <param name="view"> /// The view. /// </param> /// <param name="model"> /// The model. /// </param> public Userpresenter(IUserView view,IUserModel model) { this.m_view = view; this.m_model = model; }
/// <summary> /// 房间里是否有这个人 /// </summary> /// <param name="user"></param> /// <returns></returns> public bool hasPeople(IUserModel user) { for (int i = 0; i < this._chair.Count; i++) { IChairModel chair = this._chair[i]; if (chair.getUser().Id == user.Id) { return true; } }//end for return false; }
private void InitializeAssessment(IUserModel user, ITestEvaluator evaluator, IInterpretationBuilder interpreter) { TaskScheduler scheduler = TaskScheduler.FromCurrentSynchronizationContext(); Task.Factory.StartNew( () => { TestModel test = user.EndTest(evaluator); AssessmentModel assessment = test.Assessments[test.Assessments.Keys.ElementAt(0)]; interpreter.Intepret(assessment); var outcomeViewModels = assessment.Outcomes.Select(x => new OutcomeViewModel(x)).ToList(); return new { Assessment = assessment, Outcomes = outcomeViewModels }; } ) .ContinueWith( task => { _outcomes = task.Result.Outcomes; _assessment = task.Result.Assessment; RaisePropertyChanged(string.Empty); }, scheduler ); }
public ILookChairModel getLookChair(IUserModel value) { return null; }