Пример #1
0
        /// <summary>
        ///     Update admin SPOJ Account
        /// </summary>
        /// <param name="model"></param>
        public void UpdateSpojAccount(AdminSettingSpojAccountUpdateModel model)
        {
            if (model == null || string.IsNullOrEmpty(model.UserName) || string.IsNullOrEmpty(model.Password) || string.IsNullOrEmpty(model.ConfirmPassword))
            {
                throw new SpojDebugException("Invalid model");
            }

            if (model.Password != model.ConfirmPassword)
            {
                throw new SpojDebugException("Invalid Password");
            }

            var setting = Repository.GetSingle();

            if (setting == null)
            {
                setting = new AdminSettingEntity
                {
                    SpojUserNameEncode = DataSecurityUltils.Encrypt(model.UserName, ApplicationConfigs.SpojKey.ForUserName),
                    SpojPasswordEncode = DataSecurityUltils.Encrypt(model.Password, ApplicationConfigs.SpojKey.ForPassword)
                };

                Repository.Insert(setting);

                Repository.SaveChanges();
                return;
            }


            setting.SpojUserNameEncode = DataSecurityUltils.Encrypt(model.UserName, ApplicationConfigs.SpojKey.ForUserName);
            setting.SpojPasswordEncode = DataSecurityUltils.Encrypt(model.Password, ApplicationConfigs.SpojKey.ForPassword);
            Repository.Update(setting, x => x.SpojPasswordEncode, x => x.SpojUserNameEncode);

            Repository.SaveChanges();
        }
Пример #2
0
        public async Task <AdminSettingModel> UpdateAdminSetting(AdminSettingUpdateModel model)
        {
            var adminInfo = await _adminSettingCacheBusiness.GetFullInfo();

            var entityToUpdate = new AdminSettingEntity
            {
                Id                        = adminInfo.Id,
                TestCaseLimit             = adminInfo.TestCaseLimitation,
                ContestName               = adminInfo.ContestName,
                SpojUserNameEncode        = DataSecurityUltils.Encrypt(adminInfo.Username, ApplicationConfigs.SpojKey.ForUserName),
                SpojPasswordEncode        = DataSecurityUltils.Encrypt(adminInfo.Password, ApplicationConfigs.SpojKey.ForPassword),
                SystemEmail               = adminInfo.SystemEmail,
                SystemEmailPasswordEncode = DataSecurityUltils.Encrypt(adminInfo.EmailPassword, ApplicationConfigs.SpojKey.ForPassword)
            };


            // If update spoj account
            if (model.IsUpdateAccount)
            {
                if (model.IsNewAccount)
                {
                    if (model.NewPassword != model.ConfirmPassword)
                    {
                        throw new SpojDebugException("New password and confirmed password not match");
                    }
                }
                else
                {
                    if (model.OldPassword != adminInfo.Password)
                    {
                        throw new SpojDebugException("Wrong password");
                    }

                    if (model.NewPassword != model.ConfirmPassword)
                    {
                        throw new SpojDebugException("New password and confirmed password not match");
                    }
                }


                entityToUpdate.SpojUserNameEncode = DataSecurityUltils.Encrypt(model.Username, ApplicationConfigs.SpojKey.ForUserName);
                entityToUpdate.SpojPasswordEncode = DataSecurityUltils.Encrypt(model.NewPassword, ApplicationConfigs.SpojKey.ForPassword);
            }


            if (model.IsUpdateEmail)
            {
                if (model.IsNewEmail)
                {
                    if (model.NewEmailPassword != model.ConfirmEmailPassword)
                    {
                        throw new SpojDebugException("New email password and confirmed email password not match");
                    }
                }
                else
                {
                    if (model.OldEmailPassword != adminInfo.EmailPassword)
                    {
                        throw new SpojDebugException("Wrong email password");
                    }

                    if (model.NewEmailPassword != model.ConfirmEmailPassword)
                    {
                        throw new SpojDebugException("Email new password and confirmed password not match");
                    }
                }

                entityToUpdate.SystemEmail = model.SystemEmail;
                entityToUpdate.SystemEmailPasswordEncode = DataSecurityUltils.Encrypt(model.NewEmailPassword, ApplicationConfigs.SpojKey.ForPassword);
            }

            if (model.IsUpdateConfig)
            {
                entityToUpdate.ContestName = model.ContestName;

                if (model.Unlimited)
                {
                    entityToUpdate.TestCaseLimit = null;
                }
                else
                {
                    entityToUpdate.TestCaseLimit = model.TestCaseLimitation;
                }
            }


            Repository.Update(entityToUpdate,
                              x => x.SpojUserNameEncode,
                              x => x.SpojPasswordEncode,
                              x => x.SystemEmail,
                              x => x.SystemEmailPasswordEncode,
                              x => x.TestCaseLimit,
                              x => x.ContestName);

            Repository.SaveChanges();

            _adminSettingCacheBusiness.RemoveCache();

            return(await _adminSettingCacheBusiness.GetCache());
        }