Exemplo n.º 1
0
        public async Task GetNextTour_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();

                    await CreateDemoTour(createdMindfight.Id);
                    var createdTour = await GetDemoTour();

                    await CreateDemoTeam(johnNashUser.Id);
                    var johnNashTeam = await GetDemoTeam();

                    await _registrationService.CreateRegistration(createdMindfight.Id, johnNashTeam.Id);
                    await _registrationService.UpdateConfirmation(createdMindfight.Id, johnNashTeam.Id, true);

                    var nextTour = await _tourService.GetNextTour(createdMindfight.Id, johnNashTeam.Id);
                    nextTour.Id.ShouldBe(createdTour.Id);
                }
            });
        }
Exemplo n.º 2
0
        public async Task GetAllTourQuestions_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();

                    await CreateDemoTour(createdMindfight.Id);
                    var createdTour = await GetDemoTour();

                    await CreateDemoQuestion(createdTour.Id);

                    var tourQuestions = await _questionService.GetAllTourQuestions(createdTour.Id);
                    tourQuestions.Count.ShouldBeGreaterThanOrEqualTo(1);
                }
            });
        }
        public async Task <AuthenticateResultModel> Authenticate([FromBody] AuthenticateModel model)
        {
            if (model == null)
            {
                return(null);
            }
            var loginResult = await GetLoginResultAsync(model.UserName, model.Password).ConfigureAwait(false);

            if (loginResult.Flag)
            {
                AbpSession.Use(null, StringHelper.GuidToLongID(loginResult.ResultData.Id));
                var accessToken = _configuration.CreateAccessToken(loginResult.ResultData);
                return(new AuthenticateResultModel
                {
                    AccessToken = accessToken,
                    EncryptedAccessToken = _configuration.GetEncryptedAccessToken(accessToken),
                    ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds,
                    UserId = loginResult.ResultData.Id
                });
            }
            else
            {
                throw new Exception(loginResult.Message);
            }
        }
Exemplo n.º 4
0
        public async Task SendMessage(string message)
        {
            Clients.All.getMessage(Context.ConnectionId, message);
            var infoarr      = Regex.Split(message, "@");
            var ndtp         = infoarr[0];
            var datp         = infoarr[1];
            var ndmt         = infoarr[2];
            var damt         = infoarr[3];
            var connectionID = Context.ConnectionId;

            if (AbpSession.UserId != null)
            {
                var thietbi = _dm_ThietBiAppService.GetThietBiByConnectionID(connectionID);
                if (thietbi != null)
                {
                    await _thongTin_ThietBiAppService.UpdateThongTinFromClient(thietbi.Id, ndtp, datp, ndmt, damt);
                    await AutoDieuHoa(thietbi, ndtp, ndmt);
                }
            }
            else
            {
                AbpSession.Use(1, 2);
                var thietbi = _dm_ThietBiAppService.GetThietBiByConnectionID(connectionID);
                if (thietbi != null)
                {
                    await _thongTin_ThietBiAppService.UpdateThongTinFromClient(thietbi.Id, ndtp, datp, ndmt, damt);
                    await AutoDieuHoa(thietbi, ndtp, ndmt);
                }
            }
        }
Exemplo n.º 5
0
        public async Task RemoveUser_Test()
        {
            await CreateDemoUser();
            await CreateDemoUser2();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();
                var johnNashUser2 = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash2");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoTeam(johnNashUser.Id);
                    var johnNashTeam = await GetDemoTeam();

                    await _teamService.InsertUser(johnNashTeam.Id, johnNashUser2.UserName);
                    await _teamService.RemoveUser(johnNashTeam.Id, johnNashUser2.Id);
                    var lukeNashTeam = await context.Teams
                                       .Include(user => user.Players)
                                       .FirstOrDefaultAsync(team => team.Name == "Winners" && team.Players.Any(p => p.Id == johnNashUser2.Id));
                    lukeNashTeam.ShouldBeNull();
                }
            });
        }
Exemplo n.º 6
0
        public async Task GetQuestion_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();

                    await CreateDemoTour(createdMindfight.Id);
                    var createdTour = await GetDemoTour();

                    await CreateDemoQuestion(createdTour.Id);
                    var createdQuestion = await GetDemoQuestion();

                    var questionToGet = await _questionService.GetQuestion(createdQuestion.Id);
                    questionToGet.ShouldNotBeNull();
                }
            });
        }
        public async Task SaveAsync(AuditInfo auditInfo)
        {
            if (_configuration.RunInBackground)
            {
#pragma warning disable 4014
                Task.Factory.StartNew(() =>
#pragma warning restore 4014
                {
                    using (AbpSession.Use(auditInfo.TenantId, auditInfo.UserId))
                    {
                        try
                        {
                            SaveInternal(auditInfo);
                        }
                        catch (Exception exception)
                        {
                            Logger.Error(exception.Message, exception);
                        }
                    }
                });
            }
            else
            {
                await SaveInternalAsync(auditInfo);
            }
        }
Exemplo n.º 8
0
        public async Task UpdateTour_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();

                    await CreateDemoTour(createdMindfight.Id);
                    var createdTour = await GetDemoTour();

                    var updateTourDto = new TourDto
                    {
                        Title       = createdTour.Title,
                        Description = createdTour.Description,
                        TimeToEnterAnswersInSeconds = 20,
                        IntroTimeInSeconds          = 20
                    };

                    await _tourService.UpdateTour(updateTourDto, createdTour.Id);
                    var tour = _tourRepository
                               .FirstOrDefaultAsync(t => t.Id == createdTour.Id && t.IntroTimeInSeconds == 20);
                    tour.ShouldNotBeNull();
                }
            });
        }
Exemplo n.º 9
0
        public async Task <AuthenticateResultModel> Authenticate([FromBody] AuthenticateModel model)
        {
            var loginResult = await GetLoginResultAsync(
                model.UserNameOrEmailAddress,
                model.Password,
                GetTenancyNameOrNull()
                );

            using (((ICustomAbpSession)AbpSession).Use(3, 2, 1))
            {
                var rr = ((ICustomAbpSession)AbpSession).OrganizationUnitId;
            }
            using (AbpSession.Use(3, 2))
            {
                var rr = AbpSession.TenantId;
            }

            var r           = ((ICustomAbpSession)AbpSession).OrganizationUnitId;
            var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity));

            return(new AuthenticateResultModel
            {
                AccessToken = accessToken,
                EncryptedAccessToken = GetEncrpyedAccessToken(accessToken),
                ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds,
                UserId = loginResult.User.Id
            });
        }
Exemplo n.º 10
0
        public async Task <GetCurrentLoginInformationsOutput> GetCurrentLoginInformations()
        {
            var output = new GetCurrentLoginInformationsOutput
            {
                Application = new ApplicationInfoDto
                {
                    Version     = AppVersionHelper.Version,
                    ReleaseDate = AppVersionHelper.ReleaseDate,
                    Features    = new Dictionary <string, bool>
                    {
                        { "SignalR", SignalRFeature.IsAvailable },
                        { "SignalR.AspNetCore", SignalRFeature.IsAspNetCore }
                    }
                }
            };

            AbpSession.Use(1, 2);

            if (AbpSession.TenantId.HasValue)
            {
                output.Tenant = ObjectMapper.Map <TenantLoginInfoDto>(await GetCurrentTenantAsync());
            }

            if (AbpSession.UserId.HasValue)
            {
                output.User = ObjectMapper.Map <UserLoginInfoDto>(await GetCurrentUserAsync());
            }

            return(output);
        }
Exemplo n.º 11
0
        public async Task UpdateMindfight_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();

                    var updatedMindfightDto = new MindfightDto()
                    {
                        Title       = "Hello",
                        Description = createdMindfight.Description,
                        StartTime   = createdMindfight.StartTime,
                        TeamsLimit  = createdMindfight.TeamsLimit,
                        Id          = createdMindfight.Id
                    };

                    await _mindfightService.UpdateMindfight(updatedMindfightDto);

                    var mindfight = await _mindfightService
                                    .GetMindfight(createdMindfight.Id);
                    mindfight.ShouldNotBeNull();
                    mindfight.Title.ShouldBe("Hello");
                }
            });
        }
Exemplo n.º 12
0
        public async Task ChangeTeamLeader_Test()
        {
            await CreateDemoUser();
            await CreateDemoUser2();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();
                var johnNashUser2 = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash2");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoTeam(johnNashUser.Id);
                    var johnNashTeam = await GetDemoTeam();

                    await _teamService.InsertUser(johnNashTeam.Id, johnNashUser2.UserName);
                    await _teamService.ChangeTeamLeader(johnNashTeam.Id, johnNashUser2.Id);

                    var lukeNashLeaderTeam = await _teamRepository
                                             .FirstOrDefaultAsync(team => team.Name == "Winners" && team.LeaderId == johnNashUser2.Id);
                    lukeNashLeaderTeam.ShouldNotBeNull();
                }
            });
        }
Exemplo n.º 13
0
        public async Task GetRegisteredMindfights_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();
                    await UpdateMindfightActiveStatus(createdMindfight);

                    await CreateDemoTeam(johnNashUser.Id);
                    var johnNashTeam = await GetDemoTeam();

                    await _registrationService.CreateRegistration(createdMindfight.Id, johnNashTeam.Id);

                    var registeredMindfights = await _mindfightService.GetRegisteredMindfights();
                    registeredMindfights.Count.ShouldBeGreaterThanOrEqualTo(1);
                }
            });
        }
Exemplo n.º 14
0
        public async Task DeleteRegistration_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();
                    await UpdateMindfightActiveStatus(createdMindfight);
                    await CreateDemoTeam(johnNashUser.Id);
                    var johnNashTeam = await GetDemoTeam();

                    await _registrationService.CreateRegistration(createdMindfight.Id, johnNashTeam.Id);

                    var registration = await _registrationRepository
                                       .FirstOrDefaultAsync(x => x.TeamId == johnNashTeam.Id && x.MindfightId == createdMindfight.Id);
                    registration.ShouldNotBeNull();

                    await _registrationService.DeleteRegistration(createdMindfight.Id, johnNashTeam.Id);

                    var deletedRegistration = await _registrationRepository
                                              .FirstOrDefaultAsync(x => x.TeamId == johnNashTeam.Id && x.MindfightId == createdMindfight.Id);
                    deletedRegistration.ShouldBeNull();
                }
            });
        }
Exemplo n.º 15
0
        public async Task SendMessageTrangThai(string message)
        {
            Clients.All.getMessageTrangThai(Context.ConnectionId, message);
            var infoarr   = Regex.Split(message, "@");
            var code      = infoarr[0];
            var trangthai = infoarr[1];
            var des       = infoarr[2];

            //DM_ThietBiDto abc = new DM_ThietBiDto();
            //abc.Id = 1;
            //abc.SENDSMS = true;
            //abc.NAME = "BTS BO HO";
            //DM_TRAMDto tram = new DM_TRAMDto();
            //tram.IDDONVI = 2;
            //abc.TRAM = tram;
            //await _lichSuHoatDongThietBiAppService.SaveLogHoatDong(abc, code, trangthai, des);

            var connectionID = Context.ConnectionId;

            if (AbpSession.UserId != null)
            {
                var thietbi = _dm_ThietBiAppService.GetThietBiByConnectionID(connectionID);
                if (thietbi != null)
                {
                    if (code == "CUA")
                    {
                        await AutoDen(connectionID, trangthai, thietbi.Id);
                    }
                    if (code == "CHAY" && trangthai == "1")
                    {
                        await AutoShutDown(connectionID);
                    }
                    await _lichSuHoatDongThietBiAppService.SaveLogHoatDong(thietbi, code, trangthai, des);

                    await _thongTin_ThietBiAppService.UpdateTrangThaiDieuKhien(thietbi.Id, code, trangthai, des);
                }
            }
            else
            {
                AbpSession.Use(1, 2);
                var thietbi = _dm_ThietBiAppService.GetThietBiByConnectionID(connectionID);
                if (thietbi != null)
                {
                    if (code == "CUA")
                    {
                        await AutoDen(connectionID, trangthai, thietbi.Id);
                    }
                    if (code == "CHAY" && trangthai == "1")
                    {
                        await AutoShutDown(connectionID);
                    }
                    await _lichSuHoatDongThietBiAppService.SaveLogHoatDong(thietbi, code, trangthai, des);

                    await _thongTin_ThietBiAppService.UpdateTrangThaiDieuKhien(thietbi.Id, code, trangthai, des);
                }
            }
        }
Exemplo n.º 16
0
        public async Task SendInfoDongDien(string message)
        {
            Clients.All.getInfoDongDien(Context.ConnectionId, message);
            var connectionID = Context.ConnectionId;
            var today        = DateTime.Now.Date;

            if (AbpSession.UserId != null)
            {
                var thietbi = _dm_ThietBiAppService.GetThietBiByConnectionID(connectionID);
                if (thietbi != null)
                {
                    await _thongTin_ThietBiAppService.UpdateThongTinĐongien(thietbi.Id, message);

                    if (_lichSuHoatDongThietBiAppService.CheckSaveCongSuat(thietbi.Id, message.Split('&')[0]))
                    {
                        if (message.Split('&')[0] == "/dev/ttyUSB0")
                        {
                            await _lichSuHoatDongThietBiAppService.SaveLogHoatDong(thietbi, "DONGDIEN", message, "");
                        }
                        if (message.Split('&')[0] == "/dev/ttyUSB1")
                        {
                            await _lichSuHoatDongThietBiAppService.SaveLogHoatDong(thietbi, "DONGDIEN1", message, "");
                        }
                        if (message.Split('&')[0] == "/dev/ttyUSB2")
                        {
                            await _lichSuHoatDongThietBiAppService.SaveLogHoatDong(thietbi, "DONGDIEN2", message, "");
                        }
                    }
                }
            }
            else
            {
                AbpSession.Use(1, 2);
                var thietbi = _dm_ThietBiAppService.GetThietBiByConnectionID(connectionID);
                if (thietbi != null)
                {
                    await _thongTin_ThietBiAppService.UpdateThongTinĐongien(thietbi.Id, message);

                    if (_lichSuHoatDongThietBiAppService.CheckSaveCongSuat(thietbi.Id, message.Split('&')[0]))
                    {
                        if (message.Split('&')[0] == "/dev/ttyUSB0")
                        {
                            await _lichSuHoatDongThietBiAppService.SaveLogHoatDong(thietbi, "DONGDIEN", message, "");
                        }
                        if (message.Split('&')[0] == "/dev/ttyUSB1")
                        {
                            await _lichSuHoatDongThietBiAppService.SaveLogHoatDong(thietbi, "DONGDIEN1", message, "");
                        }
                        if (message.Split('&')[0] == "/dev/ttyUSB2")
                        {
                            await _lichSuHoatDongThietBiAppService.SaveLogHoatDong(thietbi, "DONGDIEN2", message, "");
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        public async Task UpdateIsEvaluated_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();
                    await UpdateMindfightActiveStatus(createdMindfight);

                    await CreateDemoTour(createdMindfight.Id);
                    var createdTour = await GetDemoTour();

                    await CreateDemoQuestion(createdTour.Id);
                    var createdQuestion = await GetDemoQuestion();

                    await CreateDemoTeam(johnNashUser.Id);
                    var johnNashTeam = await GetDemoTeam();

                    await _registrationService.CreateRegistration(createdMindfight.Id, johnNashTeam.Id);
                    await _registrationService.UpdateConfirmation(createdMindfight.Id, johnNashTeam.Id, true);

                    var teamAnswerDto = new TeamAnswerDto
                    {
                        Answer     = "demoAnswer",
                        QuestionId = createdQuestion.Id,
                        TeamId     = johnNashTeam.Id
                    };

                    await _teamAnswerService.CreateTeamAnswer(
                        new List <TeamAnswerDto> {
                        teamAnswerDto
                    },
                        createdMindfight.Id);

                    var teamAnswer = await _teamAnswerRepository
                                     .FirstOrDefaultAsync(x => x.TeamId == johnNashTeam.Id && x.QuestionId == createdQuestion.Id);
                    teamAnswer.ShouldNotBeNull();

                    await _teamAnswerService.UpdateIsEvaluated(createdQuestion.Id, johnNashTeam.Id, "Demo", 10, true);

                    var updatedTeamAnswer = await _teamAnswerRepository
                                            .FirstOrDefaultAsync(x => x.TeamId == johnNashTeam.Id &&
                                                                 x.QuestionId == createdQuestion.Id &&
                                                                 x.IsEvaluated);
                    updatedTeamAnswer.ShouldNotBeNull();
                }
            });
        }
Exemplo n.º 18
0
        public virtual async Task <object> GetTenantRoles(int tenantId)
        {
            var tenantManager = Resolve <TenantManager>();
            var tenant        = await tenantManager.GetByIdFromCacheAsync(tenantId);

            var adminUser = await tenantManager.GetTenantAdminUser(tenant);

            using (CurrentUnitOfWork.SetTenantId(tenantId))
            {
                using (AbpSession.Use(tenantId, adminUser.Id))
                {
                    return((await Manager.GetAllList()).Select(o => new { o.Id, o.DisplayName }));
                }
            }
        }
Exemplo n.º 19
0
        public async Task SendMessageAlarm(string ip, string path, string code, string status)
        {
            var thietbi = _dm_ThietBiAppService.GetThietBiByIP(ip);

            if (thietbi != null)
            {
                var message = code + "@" + status + "@";
                AbpSession.Use(1, 2);
                await _lichSuHoatDongThietBiAppService.SaveLogHoatDong(thietbi, code, status, "");

                await _thongTin_ThietBiAppService.UpdateTrangThaiDieuKhien(thietbi.Id, code, status, path);

                Clients.All.getMessageAlarm(thietbi.ConnectionID, message);
            }
        }
Exemplo n.º 20
0
        public virtual async Task <object> GetTenantTreeJson(int tenantId)
        {
            var tenantManager = Resolve <TenantManager>();
            var tenant        = await tenantManager.GetByIdFromCacheAsync(tenantId);

            var adminUser = await tenantManager.GetTenantAdminUser(tenant);

            using (CurrentUnitOfWork.SetTenantId(tenantId))
            {
                using (AbpSession.Use(tenantId, adminUser.Id))
                {
                    return(await GetTreeJson(null, 0));
                }
            }
        }
Exemplo n.º 21
0
        public async Task UpdateOrderNumber_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();

                    await CreateDemoTour(createdMindfight.Id);
                    var createdTour = await GetDemoTour();

                    await CreateDemoQuestion(createdTour.Id);
                    var createdQuestion = await GetDemoQuestion();

                    await _questionService.CreateQuestion(
                        new QuestionDto
                    {
                        Title                 = "TestQuestion2",
                        Description           = "Best tour",
                        Answer                = "Answer",
                        Points                = 10,
                        TimeToAnswerInSeconds = 10
                    }, createdTour.Id);

                    var question2 = await _questionRepository
                                    .FirstOrDefaultAsync(m => m.Title == "TestQuestion2");
                    question2.ShouldNotBeNull();

                    await _questionService.UpdateOrderNumber(createdQuestion.Id, 2);

                    var firstQuestion = await _questionRepository
                                        .FirstOrDefaultAsync(m => m.TourId == createdTour.Id && m.OrderNumber == 1);

                    var secondQuestion = await _questionRepository
                                         .FirstOrDefaultAsync(m => m.TourId == createdTour.Id && m.OrderNumber == 2);

                    firstQuestion.Id.ShouldBe(question2.Id);
                    secondQuestion.Id.ShouldBe(createdQuestion.Id);
                }
            });
        }
Exemplo n.º 22
0
        public async Task GetTeamResults_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();
                    await UpdateMindfightActiveStatus(createdMindfight);

                    await CreateDemoTour(createdMindfight.Id);
                    var createdTour = await GetDemoTour();

                    await CreateDemoQuestion(createdTour.Id);
                    var createdQuestion = await GetDemoQuestion();

                    await CreateDemoTeam(johnNashUser.Id);
                    var johnNashTeam = await GetDemoTeam();

                    await _registrationService.CreateRegistration(createdMindfight.Id, johnNashTeam.Id);
                    await _registrationService.UpdateConfirmation(createdMindfight.Id, johnNashTeam.Id, true);

                    var teamAnswerDto = new TeamAnswerDto
                    {
                        Answer     = "demoAnswer",
                        QuestionId = createdQuestion.Id,
                        TeamId     = johnNashTeam.Id
                    };

                    await _teamAnswerService.CreateTeamAnswer(
                        new List <TeamAnswerDto> {
                        teamAnswerDto
                    },
                        createdMindfight.Id);

                    await _teamAnswerService.UpdateIsEvaluated(createdQuestion.Id, johnNashTeam.Id, "Demo", 10, true);
                    var currentResult = await _resultService.GetTeamResults(johnNashTeam.Id);
                    currentResult.Count.ShouldBeGreaterThanOrEqualTo(1);
                }
            });
        }
Exemplo n.º 23
0
        public async Task CreateMindfight_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();
                    createdMindfight.ShouldNotBeNull();
                }
            });
        }
Exemplo n.º 24
0
        public async Task UpdateOrderNumber_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();

                    await CreateDemoTour(createdMindfight.Id);
                    var createdTour = await GetDemoTour();

                    await _tourService.CreateTour(
                        new TourDto
                    {
                        Title       = "TestTour2",
                        Description = "Best tour",
                        TimeToEnterAnswersInSeconds = 10,
                        IntroTimeInSeconds          = 10
                    }, createdMindfight.Id);

                    var createdTour2 = await _tourRepository
                                       .FirstOrDefaultAsync(m => m.Title == "TestTour2");
                    createdTour2.ShouldNotBeNull();

                    await _tourService.UpdateOrderNumber(createdTour.Id, 2);

                    var firstTour = await _tourRepository
                                    .FirstOrDefaultAsync(m => m.MindfightId == createdMindfight.Id && m.OrderNumber == 1);

                    var secondTour = await _tourRepository
                                     .FirstOrDefaultAsync(m => m.MindfightId == createdMindfight.Id && m.OrderNumber == 2);

                    firstTour.Id.ShouldBe(createdTour2.Id);
                    secondTour.Id.ShouldBe(createdTour.Id);
                }
            });
        }
Exemplo n.º 25
0
        public async Task <string> SendInforAlarm(AlarmModel alarm)
        {
            AbpSession.Use(1, 2);
            var         abc             = AbpSession.UserId;
            KetQuaModel result          = new KetQuaModel();
            var         loginResultVNPT = _webService.AuthCenter(alarm.USERNAME, alarm.PASSWORD);

            if (loginResultVNPT != null)
            {
                if (loginResultVNPT.isError == false)
                {
                    result.LOGIN = true;
                    try
                    {
                        var thietbi = _dm_ThietBiAppService.GetThietBiByIP(alarm.IPADDRESS);
                        if (thietbi != null)
                        {
                            var url     = alarm.PATH.Replace("@D:\\FTP\\IPCAMERA", "http://10.10.117.175:7711");
                            var message = alarm.CODE + "@" + alarm.STATUS + "@" + alarm.PATH;
                            await _lichSuHoatDongThietBiAppService.SaveLogHoatDong(thietbi, alarm.CODE, alarm.STATUS, url);

                            await _thongTin_ThietBiAppService.UpdateTrangThaiDieuKhien(thietbi.Id, alarm.CODE, alarm.STATUS, url);

                            var context = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                            context.Clients.All.getMessageAlarm(thietbi.ConnectionID, message);
                            result.SUCCESS = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        result.SUCCESS = false;
                        result.ERROR   = ex.InnerException.Message;
                    }
                }
            }
            else
            {
            }
            string output = JsonConvert.SerializeObject(result);

            return(output);
        }
Exemplo n.º 26
0
        public async Task GetMyCreatedMindfights_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();

                    var mindfights = await _mindfightService.GetMyCreatedMindfights();
                    mindfights.Count.ShouldBeGreaterThanOrEqualTo(1);
                }
            });
        }
Exemplo n.º 27
0
        public async Task CreateTeam_Test()
        {
            await CreateDemoUser();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoTeam(johnNashUser.Id);
                    await GetDemoTeam();

                    var createdTeam = await context.Teams.FirstOrDefaultAsync(u => u.Name == "Winners");
                    createdTeam.ShouldNotBeNull();
                }
            });
        }
Exemplo n.º 28
0
        public async Task GetAllowedToEvaluateMindfights_Test()
        {
            await CreateDemoUser();
            await CreateDemoUser2();

            // Act
            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash");
                johnNashUser.ShouldNotBeNull();
                var johnNash2User = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash2");
                johnNashUser.ShouldNotBeNull();

                using (AbpSession.Use(null, johnNashUser.Id))
                {
                    await CreateDemoMindfight();
                    var createdMindfight = await GetDemoMindfight();

                    var updatedMindfightDto = new MindfightDto()
                    {
                        Title                  = createdMindfight.Title,
                        Description            = createdMindfight.Description,
                        StartTime              = createdMindfight.StartTime,
                        TeamsLimit             = createdMindfight.TeamsLimit,
                        Id                     = createdMindfight.Id,
                        UsersAllowedToEvaluate = new List <string> {
                            johnNash2User.EmailAddress
                        }
                    };

                    await _mindfightService.UpdateMindfight(updatedMindfightDto);
                }

                using (AbpSession.Use(null, johnNash2User.Id))
                {
                    var evaluatingMindfights = await _mindfightService
                                               .GetAllowedToEvaluateMindfights();
                    evaluatingMindfights.Count.ShouldBeGreaterThanOrEqualTo(1);
                }
            });
        }
Exemplo n.º 29
0
        public void InsertThongTinCanhBao(string connectionID, string info)
        {
            try
            {
                AbpSession.Use(1, 2);
                var infoarr     = Regex.Split(info, "@");
                var code        = infoarr[0];
                var trangthai   = infoarr[1];
                var DESCRIPTION = infoarr[2];
                var thietbi     = _DM_ThietBiAppService.GetThietBiByConnectionID(connectionID);
                var canhbao     = _DM_CanhBaoService.GetDMCanhBaoByCode(code);
                if (trangthai == "1")
                {
                    ThongTinCanhBao item = new ThongTinCanhBao();

                    item.IDTHIETBI = thietbi.Id;
                    item.IDCANHBAO = canhbao.Id;
                    item.SUCCESS   = false;
                    item.START     = DateTime.Now;
                    item.END       = DateTime.Now;
                    item.noidung   = canhbao.NAME;
                    item.TenantId  = 1;
                    _repository.Insert(item);
                }
                else
                {
                    var thongtin = GetThongTinCanhBaoByThietBiAndCanhBao(thietbi.Id, canhbao.Id);
                    if (thongtin != null)
                    {
                        thongtin.SUCCESS = true;
                        thongtin.noidung = "KET THUC " + canhbao.NAME;
                        thongtin.END     = DateTime.Now;
                        _repository.Update(thongtin);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 30
0
 public async Task SendMessagePrivate(string connectionID, string message)
 {
     if (AbpSession.UserId != null)
     {
         var thietbi = _dm_ThietBiAppService.GetThietBiByConnectionID(connectionID);
         if (thietbi != null)
         {
             Clients.Client(connectionID).getMessagePrivate(message);
             var infoarr   = Regex.Split(message, "@");
             var code      = infoarr[0];
             var trangthai = infoarr[1];
             var des       = infoarr[2];
             var thongtin  = _dm_THONGTINQUANLYAppService.GetThongTinQuanLyByCode(code, thietbi.Id);
             if (thongtin != null)
             {
                 await _logDieuKhienAppService.SaveLogDieuKhien(thietbi.Id, thongtin.Id, trangthai, des);
             }
         }
     }
     else
     {
         AbpSession.Use(1, 2);
         var thietbi = _dm_ThietBiAppService.GetThietBiByConnectionID(connectionID);
         if (thietbi != null)
         {
             Clients.Client(connectionID).getMessagePrivate(message);
             var infoarr   = Regex.Split(message, "@");
             var code      = infoarr[0];
             var trangthai = infoarr[1];
             var des       = infoarr[2];
             var thongtin  = _dm_THONGTINQUANLYAppService.GetThongTinQuanLyByCode(code, thietbi.Id);
             if (thongtin != null)
             {
                 await _logDieuKhienAppService.SaveLogDieuKhien(thietbi.Id, thongtin.Id, trangthai, des);
             }
         }
     }
 }