public void Register(RegisterCommand command) { ISecurityUtility securityUtility = new SecurityUtility(); ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.UserName), String.Format(ErrorMessage.IsRequired, "Tên đăng nhập")); ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.Password), String.Format(ErrorMessage.IsRequired, "Mật khẩu")); var user = securityUtility.GetUserByUsername(command.UserName); ThrowError.Against <ArgumentException>(user != null, String.Format(ErrorMessage.Exists, "Tên đăng nhập")); ThrowError.Against <ArgumentException>(_personService.Query(t => t.Email == command.Email).Select().Any(), String.Format(ErrorMessage.Exists, "Email")); // ThrowError.Against<ArgumentException>(!securityUtility.IsPasswordValid(command.Password), String.Format(ErrorMessage.IsPassword)); var person = new Person() { Email = command.Email, FullName = command.FullName, PersonId = Guid.NewGuid() }; user = new User() { Type = command.Type, UserName = command.UserName, CreationDate = DateTime.Now, Locked = false, PersonId = person.PersonId, Password = Cryptography.EncryptPassword(command.Password, "") }; _unitOfWork.Repository <Domain.Entity.User>().Insert(user); _personService.Insert(person); _unitOfWork.SaveChanges(); }
public void ResetPassword(ResetPasswordCommand command) { ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.PasswordNew), "Vui lòng nhập mật khẩu mới."); var user = _unitOfWork.Repository <Domain.Entity.User>() .Query(u => u.PersonId == command.PersonId) .Select() .FirstOrDefault(); user.Password = Cryptography.EncryptPassword(command.PasswordNew, ""); user.Locked = false; _unitOfWork.Repository <Domain.Entity.User>().Update(user); _unitOfWork.SaveChanges(); }
public ActionResult DeleteExchangeRates(string ids) { ThrowError.WebResourceNotFound(string.IsNullOrEmpty(ids)); var selectedIds = StringUtilities.ParseCommaSeparatedStringToList <Guid>(ids); if (selectedIds.Count > 0) { _exchangeRateCommandService.DeleteExchangeRate(new DeleteExchangeRateCommand(selectedIds)); return(ModelState.JsonValidation(new { Success = true })); } ModelState.AddModelError("DeleteExchangeRates", "Input parameters are invalid."); return(ModelState.JsonValidation()); }
public void ChangePassword(ChangePasswordCommand command) { ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.PasswordOld), "Vui lòng nhập mật khẩu cũ."); ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.PasswordNew), "Vui lòng nhập mật khẩu mới."); var user = _unitOfWork.Repository <Domain.Entity.User>() .Query(u => u.PersonId == command.PersonId && u.Password == Cryptography.EncryptPassword(command.PasswordOld, "")) .Select() .FirstOrDefault(); ThrowError.Against <ApplicationException>(user == null, string.Format("Mật khẩu cũ không đúng.")); user.Password = Cryptography.EncryptPassword(command.PasswordNew, ""); user.Locked = false; _unitOfWork.Repository <Domain.Entity.User>().Update(user); _unitOfWork.SaveChanges(); }
public void EditTypeMember(EditTypeMemberCommand command) { ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.Name), String.Format(ErrorMessage.IsRequired, "Tên")); ThrowError.Against <ArgumentException>(_typeMemberService.Query(t => t.Name.ToUpper().Trim() == command.Name.ToUpper().Trim() && t.TypeMemberId != command.TypeMemberId).Select().Any(), String.Format(ErrorMessage.Exists, "Tên")); var count = _typeMemberService.Query(t => t.TypeMemberId != command.TypeMemberId && ((t.ScoresFrom < command.ScoresFrom && command.ScoresFrom < t.ScoresTo) || (t.ScoresFrom < command.ScoresTo && command.ScoresTo < t.ScoresTo) || (command.ScoresFrom < t.ScoresFrom && t.ScoresFrom < command.ScoresTo) || (command.ScoresFrom < t.ScoresTo && t.ScoresTo < command.ScoresTo) || (command.ScoresFrom == t.ScoresFrom && command.ScoresTo == t.ScoresTo))).Select().Count(); ThrowError.Against <ArgumentException>(count > 0, String.Format(ErrorMessage.IsNotTypemMember)); var typeMember = _typeMemberService.Find(command.TypeMemberId); typeMember.Name = command.Name; typeMember.PercentDownPayment = command.PercentDownPayment; typeMember.ScoresFrom = command.ScoresFrom; typeMember.ScoresTo = command.ScoresTo; _typeMemberService.Update(typeMember); _unitOfWork.SaveChanges(); }
public Guid AddTypeMember(AddTypeMemberCommand command) { ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.Name), String.Format(ErrorMessage.IsRequired, "Tên")); ThrowError.Against <ArgumentException>(_typeMemberService.Query(t => t.Name.ToUpper().Trim() == command.Name.ToUpper().Trim()).Select().Any(), String.Format(ErrorMessage.Exists, "Tên")); var count = _typeMemberService.Query(t => ((t.ScoresFrom < command.ScoresFrom && command.ScoresFrom < t.ScoresTo) || (t.ScoresFrom < command.ScoresTo && command.ScoresTo < t.ScoresTo) || (command.ScoresFrom < t.ScoresFrom && t.ScoresFrom < command.ScoresTo) || (command.ScoresFrom < t.ScoresTo && t.ScoresTo < command.ScoresTo) || (command.ScoresFrom == t.ScoresFrom && command.ScoresTo == t.ScoresTo))).Select().Count(); ThrowError.Against <ArgumentException>(count > 0, String.Format(ErrorMessage.IsNotTypemMember)); var typeMember = new TypeMember() { Name = command.Name, PercentDownPayment = command.PercentDownPayment, ScoresFrom = command.ScoresFrom, ScoresTo = command.ScoresTo, TypeMemberId = Guid.NewGuid() }; _typeMemberService.Insert(typeMember); _unitOfWork.SaveChanges(); return(typeMember.TypeMemberId); }
protected override void OnCustomCommand(int command) { base.OnCustomCommand(command); switch (command) { case (int)ClamConfig.ServiceCommand.noop: break; case (int)ClamConfig.ServiceCommand.update: EventLog.WriteEntry("WHSClamAV Update", "WHSClamAV Update service was instructed to perform update by command", EventLogEntryType.Information); DoUpdate(); break; case (int)ClamConfig.ServiceCommand.kill: EventLog.WriteEntry("WHSClamAV Update", "WHSClamAV Update service was instructed to kill the update process", EventLogEntryType.Information); DoKill(); break; default: ThrowError.Throw("Invalid Command at WHSClamAVUpdate:OnCustomCommand()"); break; } }
private void HandleError(ThrowError message) { throw new Exception(); }