public IEnumerable <ValidationResult> Validate(ValidationContext validation) { if (string.IsNullOrEmpty(Name)) { yield return(new ValidationResult("Name is required!", new string[] { "Name" })); } if (BookCategoryId == Guid.Empty) { yield return(new ValidationResult("BookCategory is required!", new string[] { "BookCategoryId" })); } var bookCategoryRepository = IoCHelper.GetInstance <IRepository <BookCategory> >(); var bookCategory = bookCategoryRepository.GetAll().FirstOrDefault(x => x.Id == BookCategoryId); if (bookCategory == null) { yield return(new ValidationResult("BookCategory is not found!", new string[] { "BookCategoryId" })); } var lecturerRepository = IoCHelper.GetInstance <IRepository <Lecturer> >(); if (LecturerIds.Count <= 0) { yield return(new ValidationResult("Lecturer is required!", new string[] { "LecturerIds" })); } foreach (var lecturerId in LecturerIds) { var lecturer = lecturerRepository.GetAll().FirstOrDefault(x => x.Id == lecturerId); if (lecturer == null) { yield return(new ValidationResult("Lecturer is not found!", new string[] { "lecturerId" })); } } }
public void RedirectToView <T>(object senderView, IDictionary <string, string> args) where T : IControlView { Form frm = (Form)IoCHelper.InstantiateObj(TypeNameSource, TypeNameSourceExclude, typeof(T), TypeNameDestForm, "", senderView.GetType(), args == null ? null : args.Values); frm.Show(((UserControl)senderView).ParentForm); }
public StudentViewModel(Student student) : this() { if (student != null) { Id = student.Id; Username = student.Username; FirstName = student.FirstName; LastName = student.LastName; Email = student.Email; Gender = student.Gender; DateOfBirth = student.DateOfBirth; ExtracurricularPoint = 0; CertificateStatus = new CertificateStatusViewModel(student.CertificateStatus); var extracurricularRepository = IoCHelper.GetInstance <IRepository <Extracurricular> >(); var extracurricularActivityRepository = IoCHelper.GetInstance <IRepository <ExtracurricularActivity> >(); var extracurricularActivityIdArray = extracurricularRepository.GetAll() .Where(x => x.StudentId == Id).Select(x => x.ExtracurricularActivityId).ToArray(); Class = new ClassViewModel(student.Class); //ClassId = student.ClassId; //SpecialtyId = student.SpecialtyId; Specialty = new SpecialtyViewModel(student.Specialty); foreach (var extracurricularActivityId in extracurricularActivityIdArray) { ExtracurricularPoint += extracurricularActivityRepository.GetAll().FirstOrDefault(x => x.Id == extracurricularActivityId).Point; } // Lấy điểm của từng //ExtracurricularPoint = student //Roles = user.UserInRoles != null ? user.UserInRoles.Select(y => new RoleViewModel(y.Role)).ToArray() : null; } }
public string InsertUseTransactionScope(bool success) { //插入数据,使用数据库事务,多连接时会命名用到MSDTC using (TransactionScope trans = new TransactionScope()) { try { var service1 = IoCHelper.Resolve <ICRUDService <sys_log> >(); sys_log e1 = new sys_log() { Id = GuidHelper.NewGuid().ToString(), CreateDate = DateTime.Now }; int i1 = service1.Insert(e1); var service2 = IoCHelper.Resolve <ICRUDService <sys_file> >(); string id = success ? GuidHelper.NewGuid().ToString() : GuidHelper.NewGuid().ToString().PadRight(100, '0'); sys_file e2 = new sys_file() { Id = id, CreateDate = DateTime.Now }; int i2 = service2.Insert(e2); trans.Complete(); return($"成功{i1},{i2}"); } catch (Exception) { Transaction.Current.Rollback(); throw; } } }
public IEnumerable <ValidationResult> Validate(ValidationContext validation) { if (string.IsNullOrEmpty(Name)) { yield return(new ValidationResult("Name is required!", new string[] { "Name" })); } if (LevelStudyGuideId == Guid.Empty) { yield return(new ValidationResult("LevelStudyGuideId is required!", new string[] { "LevelId" })); } var levelRepository = IoCHelper.GetInstance <IRepository <LevelStudyGuide> >(); var level = levelRepository.GetAll().FirstOrDefault(x => x.Id == LevelStudyGuideId); if (level == null) { yield return(new ValidationResult("LevelStudyGuide is not found!", new string[] { "LevelStudyGuideId" })); } if (LecturerId == Guid.Empty) { yield return(new ValidationResult("Lecturer is required!", new string[] { "LecturerId" })); } var lecturerRepository = IoCHelper.GetInstance <IRepository <Lecturer> >(); var lecturer = lecturerRepository.GetAll().FirstOrDefault(x => x.Id == LecturerId); if (lecturer == null) { yield return(new ValidationResult("Lecturer is not found!")); } }
private void InitDataRole() { var roleRepository = IoCHelper.GetInstance <IRepository <Role> >(); var roles = new[] { new Role { Id = RoleConstants.SuperAdminId, Name = "Super Admin" }, new Role { Id = RoleConstants.AdminId, Name = "ADMIN" }, new Role { Id = RoleConstants.ShipperId, Name = "Shipper" }, new Role { Id = RoleConstants.UserId, Name = "USER" } }; roleRepository.GetDbContext().Roles.AddIfNotExist(x => x.Name, roles); roleRepository.GetDbContext().SaveChanges(); }
private static void RegisterDependencies() { var container = IoCHelper.GetContainer(); RegisterApplicationDependencies(container); RegisterInfrastructureDependencies(container); }
public StudentProfileViewModel(Student student) : this() { if (student != null) { Id = student.Id; FirstName = student.FirstName; LastName = student.LastName; Photo = student.Photo; DateOfBirth = student.DateOfBirth; Email = student.Email; Gender = student.Gender; ExtracurricularPoint = 0; var extracurricularRepository = IoCHelper.GetInstance <IRepository <Extracurricular> >(); var extracurricularActivityRepository = IoCHelper.GetInstance <IRepository <ExtracurricularActivity> >(); var extracurricularActivityIdArray = extracurricularRepository.GetAll() .Where(x => x.Id == Id).Select(x => x.ExtracurricularActivityId).ToArray(); foreach (var extracurricularActivityId in extracurricularActivityIdArray) { ExtracurricularPoint += extracurricularActivityRepository.GetAll().FirstOrDefault(x => x.Id == extracurricularActivityId).Point; } } }
async private void DoRefreshHistory() { if (SelectedRanking != null) { var get = IoCHelper.GetIoC().Resolve <GetRankingHistory>(); IsBusy = true; try { get.PlayerName = SelectedRanking.PlayerName; get.Continent = SelectedRanking.Continent; await Task.Run(() => Db.ExecuteWork(get)); if (get.Result != null) { EmpireHistRanking.Clear(); foreach (var r in get.Result) { EmpireHistRanking.Add(r); } } } finally { IsBusy = false; } } }
private void InitDataRole() { var roleRepository = IoCHelper.GetInstance <IRepository <Role> >(); var roles = new[] { new Role { Id = RoleConstants.SuperAdminId, Name = "Super Admin" }, new Role { Id = RoleConstants.ArticleManagerId, Name = "Article Manager" }, new Role { Id = RoleConstants.ExtracurricularManagerId, Name = "Extracurricular Manager" }, new Role { Id = RoleConstants.StructureManagerId, Name = "Structure Manager" }, new Role { Id = RoleConstants.UserManagerId, Name = "User Manager" }, new Role { Id = RoleConstants.StudentManagerId, Name = "Student Manager" } }; roleRepository.GetDbContext().Roles.AddIfNotExist(x => x.Name, roles); roleRepository.GetDbContext().SaveChanges(); }
private void DoShowChatCmd() { var wnd = IoCHelper.GetIoC().Resolve <ChatWindow>(); //wnd.ModelView.Browser = Browser; wnd.Show(); }
public T CreateModalDialogView <T>(object senderView, params object[] args) where T : IControlView { Form frm = (Form)IoCHelper.InstantiateObj(TypeNameSource, TypeNameSourceExclude, typeof(T), TypeNameDestDialog, "", senderView.GetType(), args); return(WinControlFindHelper.FindControlOnChild <T>(frm)); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var roleRepository = IoCHelper.GetInstance <IRepository <Role> >(); if (RoleIds.Count <= 0) { yield return(new ValidationResult("Role is required!", new string[] { "RoleIds" })); } foreach (var roleId in RoleIds) { var role = roleRepository.GetAll().FirstOrDefault(x => x.Id == roleId); if (role == null) { yield return(new ValidationResult("Role is not found!", new string[] { "RoleId" })); } } var userRepository = IoCHelper.GetInstance <IRepository <User> >(); var user = userRepository.GetAll().FirstOrDefault(x => x.FullName == FullName); if (FullName.Length <= 2) { yield return(new ValidationResult("Invalid FullName!", new string[] { "FullName" })); } }
public JwtPayload ValidateToken(string token) { var appSetting = IoCHelper.GetInstance <IOptions <AppSettings> >(); try { if (string.IsNullOrEmpty(token)) { return(null); } var json = new JwtBuilder() .WithSecret(appSetting.Value.Secret) .MustVerifySignature() .Decode(token); var jwtJsonDecode = JsonConvert.DeserializeObject <JwtJsonDecode>(json); if (jwtJsonDecode == null || jwtJsonDecode.JwtPayload == null) { return(null); } else { return(jwtJsonDecode.JwtPayload); } } catch (TokenExpiredException) { return(null); } catch (SignatureVerificationException) { return(null); } }
public T CreateControlView <T>(params object[] args) where T : IControlView { return((T)IoCHelper.InstantiateObj(TypeNameSource, TypeNameSourceExclude, typeof(T), TypeNameDest, "", parentView.GetType(), args)); // return (T)Activator.CreateInstance(typeof(T), args); }
private void DoShowDataCollectCmd() { var wnd = IoCHelper.GetIoC().Resolve <DataColectWindow>(); wnd.ModelView.Browser = Browser; wnd.Show(); }
// validate public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var majorRepository = IoCHelper.GetInstance <IRepository <Major> >(); var major = majorRepository.GetAll().FirstOrDefault(x => x.Id == MajorId); if (major == null) { yield return(new ValidationResult("Major is not found!", new string[] { "MajorId" })); } var standardOfCertificateRepository = IoCHelper.GetInstance <IRepository <StandardOfCertificate> >(); var standardOfCertificate = standardOfCertificateRepository.GetAll().FirstOrDefault(x => x.Id == StandardOfCertificateId); if (standardOfCertificate == null) { yield return(new ValidationResult("StandardOfCertificate is not found!", new string[] { "StandardOfCertificateId" })); } //if (string.IsNullOrWhiteSpace(Name)) //{ // yield return new ValidationResult("SpecialtyName can't be null or WhiteSpace!", new string[] { "SpecialtyName" }); //} //var specialtyRepository = IoCHelper.GetInstance<IRepository<Specialty>>(); //var specialty = specialtyRepository.GetAll().FirstOrDefault(x => x.Name == Name && x.Id == Id); //if (specialty != null) //{ // yield return new ValidationResult("SpecialtyName already exists!", new string[] { "SpecialtyName" }); //} }
public IEnumerable <ValidationResult> Validate(ValidationContext validation) { if (string.IsNullOrEmpty(Name)) { yield return(new ValidationResult("Name is required!", new string[] { "Name" })); } if (ClassificationOfScientificWorkId == Guid.Empty) { yield return(new ValidationResult("ClassificationOfScientificWork is required!", new string[] { "ClassificationOfScientificWorkId" })); } var levelRepository = IoCHelper.GetInstance <IRepository <ClassificationOfScientificWork> >(); var level = levelRepository.GetAll().FirstOrDefault(x => x.Id == ClassificationOfScientificWorkId); if (level == null) { yield return(new ValidationResult("ClassificationOfScientificWork is not found!", new string[] { "ClassificationOfScientificWorkId" })); } var lecturerRepository = IoCHelper.GetInstance <IRepository <Lecturer> >(); if (LecturerIds.Count <= 0) { yield return(new ValidationResult("Lecturer is required!", new string[] { "LecturerIds" })); } foreach (var lecturerId in LecturerIds) { var lecturer = lecturerRepository.GetAll().FirstOrDefault(x => x.Id == lecturerId); if (lecturer == null) { yield return(new ValidationResult("Lecturer is not found!", new string[] { "lecturerId" })); } } }
public void NewSaveTest() { //使用 IoCHelper 测试 IArticleRepository article = IoCHelper.Resolve <IArticleRepository>(); ICategoryRepository category = IoCHelper.Resolve <ICategoryRepository>(); BlogArticle model = new BlogArticle(); int expected = 0; int actual = 0; model.Title = "测试标题" + new Random().Next(100000, 999999).ToString(); model.IsTop = true; //model.BlogCategory = category.GetByCondition(new DirectSpecification<BlogCategory>(x => x.CateID == 2)); model.BlogCategory = category.GetList()[0]; model.Content = "这里是内容"; model.PublishTime = DateTime.Now; model.CreateTime = DateTime.Now; model.UpdateTime = DateTime.Now; article.NewSave(model); article.SaveChanges(); Assert.AreEqual(expected, actual); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var roleRepository = IoCHelper.GetInstance <IRepository <Role> >(); if (RoleIds.Count <= 0) { yield return(new ValidationResult("Role is required!", new string[] { "RoleIds" })); } foreach (var roleId in RoleIds) { var role = roleRepository.GetAll().FirstOrDefault(x => x.Id == roleId); if (role == null) { yield return(new ValidationResult("Role is not found!", new string[] { "RoleId" })); } } var userRepository = IoCHelper.GetInstance <IRepository <User> >(); var user = userRepository.GetAll().FirstOrDefault(x => x.Email == Email); if (user != null) { yield return(new ValidationResult("Email already exists!", new string[] { "Email" })); } user = userRepository.GetAll().FirstOrDefault(x => x.Username == Username); if (user != null) { yield return(new ValidationResult("Username already exists!", new string[] { "Username" })); } }
private void InitUserAdmin() { var userRepository = IoCHelper.GetInstance <IRepository <User> >(); var user = new User(); user.Username = "******"; user.FullName = "Super Admin"; user.Email = "*****@*****.**"; user.Password = "******"; /*var password = "******"; * password.GeneratePassword(out string saltKey, out string hashPass); * * user.Password = hashPass;*/ user.Gender = UserEnums.UserGender.Nam; var users = new[] { user }; userRepository.GetDbContext().Users.AddIfNotExist(x => x.Email, users ); userRepository.GetDbContext().SaveChanges(); }
private List <UnitsKillsHistory> GetPlayerKillsHistory(string player) { var get = IoCHelper.GetIoC().Resolve <GetKillsHistory>(); get.PlayerName = player; Db.ExecuteWork(get); return(get.Result); }
public ContractT GetFromContract <ContractT>(params object[] args) where ContractT : IContract { return(typeof(ContractT) == typeof(INullContract) ? default(ContractT) : IoCHelper.InstantiateObj <ContractT>(TypeNameContract, TypeNameContractIgnore, TypeNameDest, null, GetType(), args)); }
private List <OffReputationHistory> GetOffRepHistory(string player) { var get = IoCHelper.GetIoC().Resolve <GetOffRepHistory>(); get.PlayerName = player; Db.ExecuteWork(get); return(get.Result); }
public static IContainer GetContainer() { var containerBuilder = new ContainerBuilder(); IoCHelper.AddBasicRegistrations(containerBuilder); containerBuilder.RegisterType <Application>().As <IApplication>(); return(containerBuilder.Build()); }
public UCTroopsOverviewTable() { InitializeComponent(); if (IoCHelper.IsInitialized) { this.grid.DataContext = IoCHelper.GetIoC().Resolve <UCTroopsOverviewTableMV>(); } }
private List <EmpireScoreHistory> GetPlayerHistory(string player, int continent) { var get = IoCHelper.GetIoC().Resolve <GetRankingHistory>(); get.PlayerName = player; get.Continent = continent; Db.ExecuteWork(get); return(get.Result); }
private List <AlianceScoreHistory> GetAlianceHistory(string aliance, int continent) { var get = IoCHelper.GetIoC().Resolve <GetAlianceRankingHistory>(); get.AlianceName = aliance; get.Continent = continent; Db.ExecuteWork(get); return(get.Result); }
public UCRaidsReports() { InitializeComponent(); if (IoCHelper.IsInitialized) { this.grid.DataContext = IoCHelper.GetIoC().Resolve <UCRaidsReportsMV>(); ModelView.PropertyChanged += ModelView_PropertyChanged; } }
public async Task <IActionResult> GetCertificateStatus() { var studentRepository = IoCHelper.GetInstance <IRepository <Student> >(); var SelfCertificateStatusId = studentRepository.GetAll() .FirstOrDefault(x => x.Id == CurrentUserId).CertificateStatusId; var certificateStatus = await _certificateStatusService.GetCertificateStatusBySelfIdAsync(SelfCertificateStatusId); return(Ok(certificateStatus)); }