コード例 #1
0
 public void InitializeCategories()
 {
     using (_repository = _getRepository())
     {
         if (!_repository.Get().Any())
         {
             _repository.Insert(new CategoryModel { Name = "Easy" });
             _repository.Insert(new CategoryModel { Name = "Difficult" });
             _repository.Save();
         }
     }
 }
コード例 #2
0
ファイル: RolesService.cs プロジェクト: reaperdk/timetracker
 public void InitializeRoles()
 {
     using (_repository = _getRepository())
     {
         if (!_repository.Get().Any())
         {
             _repository.Insert(new RoleModel { RoleName = "admin" });
             _repository.Insert(new RoleModel { RoleName = "user" });
             _repository.Save();
         }
     }
 }
コード例 #3
0
 public void InitializePriorities()
 {
     using (_repository = _getRepository())
     {
         if (!_repository.Get().Any())
         {
             _repository.Insert(new PriorityModel { Name = "Low" });
             _repository.Insert(new PriorityModel { Name = "Medium" });
             _repository.Insert(new PriorityModel { Name = "High" });
             _repository.Insert(new PriorityModel { Name = "Very high" });
             _repository.Save();
         }
     }
 }
コード例 #4
0
ファイル: TypesService.cs プロジェクト: reaperdk/timetracker
 public void InitializeTypes()
 {
     using (_repository = _getRepository())
     {
         if (!_repository.Get().Any())
         {
             _repository.Insert(new TypeModel { Name = "Epic" });
             _repository.Insert(new TypeModel { Name = "Task" });
             _repository.Insert(new TypeModel { Name = "Bug" });
             _repository.Insert(new TypeModel { Name = "Exception" });
             _repository.Save();
         }
     }
 }
コード例 #5
0
 public void InitializeStatuses()
 {
     using (_repository = _getRepository())
     {
         if (!_repository.Get().Any())
         {
             _repository.Insert(new StatusModel { Name = "Active" });
             _repository.Insert(new StatusModel { Name = "Completed" });
             _repository.Insert(new StatusModel { Name = "Suspended" });
             _repository.Insert(new StatusModel { Name = "New" });
             _repository.Insert(new StatusModel { Name = "Reactivated" });
             _repository.Save();
         }
     }
 }
コード例 #6
0
        public async Task <CommandResult> Handle(CreateUserCommand request, CancellationToken cancellationToken)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var  salt        = SecurityUtility.GenerateSalt(128);
            Guid id          = Guid.NewGuid();
            var  createdUser = await _entitiesRepository.Insert(new Domain.Entities.Users.User(
                                                                    request.Username.ToLower(),
                                                                    SecurityUtility.OneWayHash(request.Password, salt),
                                                                    request.Username.ToLower(),
                                                                    salt,
                                                                    request.CreatedBy,
                                                                    DateTime.UtcNow,
                                                                    id
                                                                    ));

            return(new CommandResult()
            {
                ElapsedMs = stopwatch.ElapsedMilliseconds,
                ObjectRefId = id.ToString(),
                Type = CommandResultTypes.Create
            });
        }
コード例 #7
0
 public void AddUser(Models.UserProfile toAdd)
 {
     using (_userProfileRepository = _userProfileRepositoryInitializer())
     {
         _userProfileRepository.Insert(Mapper.Map<Models.UserProfile, UserProfile>(toAdd));
         _userProfileRepository.Save();
     }
 }
コード例 #8
0
 public void Create(ProjectModel project)
 {
     using (_repository = _getRepository())
     {
         _repository.Insert(project);
         _repository.Save();
     }
 }
コード例 #9
0
ファイル: SlotsService.cs プロジェクト: reaperdk/timetracker
 public void Create(SlotModel slot)
 {
     using (_repository = _getRepository())
     {
         _repository.Insert(slot);
         _repository.Save();
     }
 }
コード例 #10
0
ファイル: TasksService.cs プロジェクト: reaperdk/timetracker
 public void Create(TaskModel task)
 {
     using (_repository = _getRepository())
     {
         _repository.Insert(task);
         _repository.Save();
     }
 }
コード例 #11
0
        public async Task <ShardData> InsertDataAsync(ShardData data)
        {
            data.ShardType = data.GetType().Name;
            try
            {
                switch (data)
                {
                case User t1:
                    return(await _entitiesRepository.Insert(t1));

                case BotKey t1:
                    return(await _entitiesRepository.Insert(t1));

                case GlobalValue t1:
                    return(await _entitiesRepository.Insert(t1));

                case StepTemplate t1:
                    return(await _entitiesRepository.Insert(t1));

                case WorkflowTemplate t1:
                    return(await _entitiesRepository.Insert(t1));

                case Metric t1:
                    return(await _entitiesRepository.Insert(t1));

                case MetricTick t1:
                    return(await _entitiesRepository.Insert(t1));

                case Step t1:
                    return(await _entitiesRepository.Insert(t1));

                case Workflow t1:
                    return(await _entitiesRepository.Insert(t1));

                case ExecutionTemplate t1:
                    return(await _entitiesRepository.Insert(t1));

                case ExecutionSchedule t1:
                    return(await _entitiesRepository.Insert(t1));
                }
                throw new Exception("Object type " + data.ShardType + "has no supported operations");
            }
            catch (Exception e)
            {
                if (e.Message.Contains("E11000 duplicate key error collection"))
                {
                    Console.WriteLine("Detected that there was a duplicate record in the database... Updating existing record and continueing");
                    try
                    {
                        return(await UpdateDataAsync(data));
                    }
                    catch (Exception updateError)
                    {
                        if (updateError.Message.Contains("has no supported update operations"))
                        {
                            return(data);
                        }
                        else
                        {
                            throw updateError;
                        }
                    }
                }
                throw e;
            }
        }