Esempio n. 1
0
        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" }));
                }
            }
        }
Esempio n. 2
0
        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;
                }
            }
        }
Esempio n. 5
0
        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!"));
            }
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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;
                }
            }
        }
Esempio n. 9
0
        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;
                }
            }
        }
Esempio n. 10
0
        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();
        }
Esempio n. 11
0
        private void DoShowChatCmd()
        {
            var wnd = IoCHelper.GetIoC().Resolve <ChatWindow>();

            //wnd.ModelView.Browser = Browser;
            wnd.Show();
        }
Esempio n. 12
0
        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" }));
            }
        }
Esempio n. 14
0
        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);
            }
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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" });
            //}
        }
Esempio n. 18
0
        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" }));
                }
            }
        }
Esempio n. 19
0
        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" }));
            }
        }
Esempio n. 21
0
        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();
        }
Esempio n. 22
0
        private List <UnitsKillsHistory> GetPlayerKillsHistory(string player)
        {
            var get = IoCHelper.GetIoC().Resolve <GetKillsHistory>();

            get.PlayerName = player;
            Db.ExecuteWork(get);
            return(get.Result);
        }
Esempio n. 23
0
 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));
 }
Esempio n. 24
0
        private List <OffReputationHistory> GetOffRepHistory(string player)
        {
            var get = IoCHelper.GetIoC().Resolve <GetOffRepHistory>();

            get.PlayerName = player;
            Db.ExecuteWork(get);
            return(get.Result);
        }
Esempio n. 25
0
        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>();
            }
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        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);
        }
Esempio n. 29
0
        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));
        }