Ejemplo n.º 1
0
        public async Task <bool> SaveAsync(List <SettingsDto> dtos)
        {
            using (var scope = _dbContextScopeFactory.Create())
            {
                foreach (var dto in dtos)
                {
                    var data = await _settingsRepository.FindAsync(e => dto.Code == e.Code);

                    if (data != null)
                    {
                        data.Name  = dto.Name;
                        data.Value = dto.Value;
                        _settingsRepository.Modify(data);
                    }
                    else
                    {
                        data.Value = dto.Value;
                        data       = _mapper.Map <Setting>(dto);
                        _settingsRepository.Add(data);
                    }
                }

                scope.SaveChanges();
            }
            return(true);
        }
Ejemplo n.º 2
0
        public async Task <SettingResponse> AddAsync(SettingRequest request)
        {
            var entity = _mapper.Map <Setting>(request);

            entity = _repo.Add(entity);
            await _repo.SaveChangesAsync();

            return(await Task.Run(() => _mapper.Map <SettingResponse>(entity)));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Create([Bind(Include = "CoreID,StandardRPM,Allowance,TimeOut,StartAfter")] Settings setting)
        {
            if (ModelState.IsValid)
            {
                await _dataAccessProvider.Add(setting);

                return(RedirectToAction("Index"));
            }

            return(View(setting));
        }
        //Post a setting

        public HttpResponseMessage PostSetting(Setting setting)
        {
            setting = settingRepository.Add(setting);

            var response = Request.CreateResponse <Setting>(HttpStatusCode.Created, setting);

            var uri = Url.Link("DefaultApi", new { id = setting.Id });

            response.Headers.Location = new Uri(uri);

            return(response);
        }
        public void StoreSettings(string phoneId, SettingsDTO settingsRequest)
        {
            Language language = languageRepository.GetLanguageByName(settingsRequest.LanguageCode);

            if (language == null)
            {
                throw new HttpStatusCodeException(
                          HttpStatusCode.NotFound,
                          $"Language [{settingsRequest.LanguageCode}] doesn't exist");
            }

            NotificationFrequency notificationFrequency =
                notificationFrequencyRepository.GetNotificationFrequencyByFrequency(settingsRequest.NotificationFrequency);

            if (notificationFrequency == null)
            {
                throw new HttpStatusCodeException(
                          HttpStatusCode.NotFound,
                          $"Notification frequency [{settingsRequest.NotificationFrequency}] doesn't exist");
            }

            Entities.Models.Settings settings = settingsRepository.GetSettingsByPhoneId(phoneId);
            if (settings != null)
            {
                settings.Language              = language;
                settings.DoesNotify            = settingsRequest.DoesNotify;
                settings.NotificationFrequency = notificationFrequency;
            }
            else
            {
                Entities.Models.Settings newSettings = new Entities.Models.Settings
                {
                    Language              = language,
                    DoesNotify            = true,
                    NotificationFrequency = notificationFrequency
                };

                settingsRepository.Add(newSettings);

                accountRepository.Add(new Account
                {
                    PhoneIdentifier = phoneId,
                    Settings        = newSettings,
                    PasswordHash    = "",
                    Email           = phoneId,
                    FirstName       = "",
                    City            = ""
                });
            }
            theaterScheduleUnitOfWork.Save();
        }
Ejemplo n.º 6
0
        public void CreateDemoData()
        {
            if (!_settingsRepository.GetAll().Any())
            {
                _settingsRepository.Add(new Setting
                {
                    DefaultMaxMmrGap = 0
                });
            }

            _userRepository.Add(new User
            {
                FirstName = "Demo",
                LastName  = "Admin",
                Email     = "*****@*****.**",
                Password  = "******".ToSha256Base64(),
                Role      = UserRole.Admin
            });

            var userIds = new List <Guid>(50);

            // Seed some sample users
            for (var x = 1; x <= 50; x++)
            {
                userIds.Add(_userRepository.Add(new User
                {
                    FirstName = $"Demo{x}",
                    LastName  = $"Last{x}",
                    Email     = $"demouser{x}@gamematchdemo.io",
                    Password  = $"User{x}SuperSecretPassword".ToSha256Base64(),
                    Role      = UserRole.User
                }));
            }

            // Seed some ratings for those users
            var rating = 0.1;

            foreach (var userId in userIds)
            {
                _userRatingRepository.Add(new UserRating
                {
                    UserId   = userId,
                    GameType = GameType.Chess,
                    Rating   = rating
                });

                rating += .1;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// این متد رکورد سازمان مرکزی را به همراه واحد مرکز استان ، دانشگاه ، احراز هویت ، شخص ، کاربر
        /// و نقش مدیر دانشگاه را ثبت می کند و نقش را به کاربر مربوطه انتساب می دهد
        /// </summary>
        /// <param name="modelRegisterProgram"></param>
        /// <returns></returns>
        public bool RegisterProgramUniversity(RegisterProgramUniversityModel modelRegisterProgram)
        {
            try
            {
                _unitOfWork.BeginTransaction();

                //ثبت رکورد سازمان مرکزی
                var centralOrganization = new CentralOrganization
                {
                    Name = "سازمان مرکزی"
                };
                _centralOrganizationRepository.Add(centralOrganization);

                //var baseRegisterProgramModel = new BaseRegisterProgramModel
                //{
                //    RoleType = RoleType.AdminCentral,
                //    Name = "مدیر سازمان",
                //    NationalCode = "1111111111",
                //    Password = "******",
                //    OrganName = "سازمان مرکزی",
                //    UserName = "******",
                //    LicenceCode = "1111111111"
                //};
                //if (!AddUserAdminAutomatic(centralOrganization.Id, AuthenticationType.AdminCentral, RoleType.AdminCentral, baseRegisterProgramModel))
                //    throw new Exception("");

                //ثبت رکورد واحد سازمان
                var branchProvince = new BranchProvince
                {
                    CentralOrganizationId = centralOrganization.Id,
                    Name = "واحد مرکز استان"
                };
                _branchProvinceRepository.Add(branchProvince);

                //baseRegisterProgramModel.RoleType = RoleType.AdminBranch;
                //baseRegisterProgramModel.Name = "مدیر واحد استان";
                //baseRegisterProgramModel.NationalCode = "2222222222";
                //baseRegisterProgramModel.Password = "******";
                //baseRegisterProgramModel.OrganName = "واحد مرکز استان";
                //baseRegisterProgramModel.UserName = "******";
                //baseRegisterProgramModel.LicenceCode = "2222222222";

                //if(!AddUserAdminAutomatic(branchProvince.Id, AuthenticationType.AdminBranch, RoleType.AdminBranch, baseRegisterProgramModel))
                //    throw new Exception("");

                //ثبت رکورد دانشگاه
                var university = new University
                {
                    BranchProvinceId = branchProvince.Id,
                    Name             = modelRegisterProgram.OrganName,
                    Address          = modelRegisterProgram.Address,
                    Code             = modelRegisterProgram.Code,
                    Phone            = modelRegisterProgram.Phone
                };
                _universityRepository.Add(university);
                var setting = new Settings
                {
                    UniversityId = university.Id,
                    CommissionNumberRepetitions = 1,
                    CouncilNumberRepetitions    = 1,
                    Ordinal = Ordinal.Ordinal
                };
                _settingsRepository.Add(setting);
                //_universityRepository.Add(university);

                if (!AddUserAdminAutomatic(university.Id, AuthenticationType.AdminUniversity, RoleType.AdminUniversity, modelRegisterProgram))
                {
                    throw new Exception("");
                }

                _unitOfWork.SaveChanges();
                _unitOfWork.CommitTransaction();
                return(true);
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback();
                return(false);
            }
        }
Ejemplo n.º 8
0
 public Settings Add(Settings settings)
 {
     return(_settingsRepository.Add(settings));
 }
Ejemplo n.º 9
0
 public void CreateSettings(Settings order)
 {
     _settingsRepository.Add(order);
 }