예제 #1
0
        //[Route("id")]
        public async Task <IActionResult> PutEmployee(int id, Employee employee)
        {
            if (id != employee.Id)
            {
                return(BadRequest());
            }

            _context.Entry(employee).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task Handle(CreateNewUserCommand command)
        {
            var userWithNumberExistsAlready = await _context.Users
                                              .Where(x => x.UserType == command.UserType.MapToContractEnum() && x.Application == command.Application.MapToContractEnum() && x.Number == command.Number)
                                              .AsNoTracking()
                                              .AnyAsync();

            if (userWithNumberExistsAlready)
            {
                throw new MatchingUserWithNumberExistsException(command.UserType.MapToContractEnum(), command.Number);
            }

            var user = new User(
                command.Username,
                command.ContactEmail,
                command.FirstName,
                command.LastName,
                command.DisplayName,
                command.Number,
                command.TestType.MapToContractEnum(),
                command.UserType.MapToContractEnum(),
                command.Application.MapToContractEnum(),
                command.IsProdUser
                );

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            command.NewUserId = user.Id;
        }
예제 #3
0
        public async Task Handle(CreateNewAllocationByUserIdCommand command)
        {
            var user = await _context.Users
                       .SingleOrDefaultAsync(x => x.Id == command.UserId);

            if (user == null)
            {
                throw new UserNotFoundException(command.UserId);
            }

            var allocation = await _context.Allocations
                             .SingleOrDefaultAsync(x => x.UserId == command.UserId);

            if (allocation != null)
            {
                throw new AllocationAlreadyExistsException(command.UserId);
            }

            allocation = new Allocation(user);
            await _context.Allocations.AddAsync(allocation);

            await _context.SaveChangesAsync();

            command.NewAllocationId = allocation.Id;
        }
        public async Task Handle(AllocateByUserIdCommand command)
        {
            var user = await _context.Users.SingleOrDefaultAsync(x => x.Id == command.UserId);

            if (user == null)
            {
                throw new UserNotFoundException(command.UserId);
            }

            var allocation = await _context.Allocations.SingleOrDefaultAsync(x => x.UserId == user.Id);

            if (allocation == null)
            {
                throw new UserAllocationNotFoundException(command.UserId);
            }

            if (allocation.IsAllocated())
            {
                throw new UserUnavailableException();
            }

            allocation.Allocate(command.ExtendedExpiryInMinutes, command.AllocatedBy);
            await _context.SaveChangesAsync();

            command.User = user;
        }
예제 #5
0
        public async Task <RecentUser> SeedRecentUser(string username)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);
            var recentUser = new RecentUser(username);
            await db.RecentUsers.AddAsync(recentUser);

            await db.SaveChangesAsync();

            return(recentUser);
        }
예제 #6
0
        public async Task <Allocation> SeedAllocation(Guid userId)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            var user = await db.Users.AsNoTracking().SingleOrDefaultAsync(x => x.Id == userId);

            var allocation = new Allocation(user);
            await db.Allocations.AddAsync(allocation);

            await db.SaveChangesAsync();

            return(allocation);
        }
        public async Task Handle(DeleteNewRecentUserByUsernameCommand command)
        {
            var recentUser = await _context.RecentUsers
                             .SingleOrDefaultAsync(x => x.Username == command.Username);

            if (recentUser == null)
            {
                throw new RecentUserNotFoundException(command.Username);
            }

            _context.Remove(recentUser);
            await _context.SaveChangesAsync();
        }
예제 #8
0
        public async Task DeleteRecentUsers()
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            var recentUsers = await db.RecentUsers
                              .Where(x => x.Username == EmailData.RECENT_USER_USERNAME)
                              .AsNoTracking()
                              .ToListAsync();

            foreach (var user in recentUsers)
            {
                db.Remove(user);
                await db.SaveChangesAsync();
            }
        }
예제 #9
0
        public async Task DeleteUsers()
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            var users = await db.Users
                        .Where(x => x.Application == Application.TestApi.MapToContractEnum())
                        .AsNoTracking()
                        .ToListAsync();

            foreach (var user in users)
            {
                db.Remove(user);
                await db.SaveChangesAsync();
            }
        }
예제 #10
0
        public async Task <Allocation> AllocateUser(Guid userId, int expiresInMinutes = 1)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            var allocation = await db.Allocations
                             .Where(x => x.UserId == userId)
                             .AsNoTracking()
                             .SingleOrDefaultAsync();

            allocation.Allocate(expiresInMinutes);
            db.Allocations.Update(allocation);
            await db.SaveChangesAsync();

            return(allocation);
        }
예제 #11
0
        public async Task Handle(CreateNewRecentUserByUsernameCommand command)
        {
            var recentUser = await _context.RecentUsers
                             .SingleOrDefaultAsync(x => x.Username == command.Username);

            if (recentUser != null)
            {
                throw new RecentUserAlreadyExistsException(command.Username);
            }

            recentUser = new RecentUser(command.Username);

            await _context.RecentUsers.AddAsync(recentUser);

            await _context.SaveChangesAsync();
        }
예제 #12
0
        public async Task <UserDto> Handle(GetAllocatedUserByUserTypeQuery query)
        {
            UserDto user;

            if (query.IsEjud && (query.UserType == UserType.Judge || query.UserType == UserType.PanelMember || query.UserType == UserType.Winger))
            {
                user = await _service.AllocateJudicialOfficerHolderToService(query.TestType, query.ExpiryInMinutes, query.AllocatedBy);

                user.UserType = query.UserType;
            }
            else
            {
                user = await _service.AllocateToService(query.UserType, query.Application, query.TestType, query.IsProdUser, query.ExpiryInMinutes, query.AllocatedBy);
            }

            await _context.SaveChangesAsync();

            return(user);
        }
예제 #13
0
        public async Task Handle(UnallocateByUsernameCommand command)
        {
            var user = await _context.Users.SingleOrDefaultAsync(
                x => x.Username.ToLower() == command.Username.ToLower());

            if (user == null)
            {
                throw new UserNotFoundException(command.Username);
            }

            var allocation = await _context.Allocations.SingleOrDefaultAsync(x => x.UserId == user.Id);

            if (allocation == null)
            {
                throw new UserAllocationNotFoundException(command.Username);
            }

            allocation.Unallocate();
            await _context.SaveChangesAsync();
        }
예제 #14
0
        public async Task <UserDto> SeedUser(TestType testType, UserType userType = UserType.Judge)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            const Application APPLICATION  = Application.TestApi;
            const bool        IS_PROD_USER = false;

            var number = await IterateUserNumber(userType, APPLICATION, IS_PROD_USER, testType);

            var user = new UserBuilder(_context.Config.UsernameStem, number)
                       .WithUserType(userType)
                       .ForApplication(APPLICATION)
                       .ForTestType(testType)
                       .BuildUser();

            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            return(UserToUserDtoMapper.Map(user));
        }
예제 #15
0
        public async Task <UserDto> SeedUser(UserType userType = UserType.Judge, bool isProdUser = false)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);

            const Application application = Application.TestApi;
            const TestType    testType    = TestType.Automated;

            var number = await IterateUserNumber(userType, application, isProdUser, testType);

            var user = new UserBuilder(_context.Config.UsernameStem, number)
                       .WithUserType(userType)
                       .ForApplication(application)
                       .IsProdUser(isProdUser)
                       .BuildUser();

            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            return(UserToUserDtoMapper.Map(user));
        }
예제 #16
0
        private async Task <List <PairData> > FormDataAsync()
        {
            var testDate1 = new DateTime(2020, 1, 1);
            var testDate2 = new DateTime(2020, 1, 5);

            _bittrexService = new BittrexService(TestApiDbContext);
            var testPairs = new List <PairData>
            {
                new PairData
                {
                    PairName       = "BTC-USD",
                    BuyPrice       = 254.0m,
                    SellPrice      = 254.0m,
                    LastTradePrice = 254.0m,
                    HighPrice      = 254.0m,
                    LowPrice       = 254.0m,
                    Volume         = 1234567,
                    Updated        = testDate1
                },
                new PairData
                {
                    PairName       = "LTC-XRP",
                    BuyPrice       = 123.0m,
                    SellPrice      = 123.0m,
                    LastTradePrice = 123.0m,
                    HighPrice      = 123.0m,
                    LowPrice       = 123.0m,
                    Volume         = 999999,
                    Updated        = testDate2
                }
            };

            await TestApiDbContext.Pairs.AddRangeAsync(testPairs);

            await TestApiDbContext.SaveChangesAsync();

            return(testPairs);
        }