private async Task <int> GetLastQuestionTime(Models.Tour tour) { var lastTourQuestion = await _questionRepository .GetAll() .OrderByDescending(question => question.OrderNumber) .Where(question => question.TourId == tour.Id) .FirstOrDefaultAsync(); if (lastTourQuestion == null) { throw new UserFriendlyException("Turas neturi klausimų!"); } var questionTime = lastTourQuestion.TimeToAnswerInSeconds; return(questionTime); }
public async Task <long> CreateTour(TourDto tour, long mindfightId) { var user = await _userManager.Users.IgnoreQueryFilters().FirstOrDefaultAsync(u => u.Id == _userManager.AbpSession.UserId); if (user == null) { throw new UserFriendlyException("Vartotojas neegzistuoja!"); } var currentMindfight = await _mindfightRepository .FirstOrDefaultAsync(x => x.Id == mindfightId); if (currentMindfight == null) { throw new UserFriendlyException("Protmūšis su nurodytu id neegzistuoja!"); } if (!(currentMindfight.CreatorId == _userManager.AbpSession.UserId || _permissionChecker.IsGranted("ManageMindfights"))) { throw new AbpAuthorizationException("Jūs neturite turo kūrimo teisių!"); } tour.OrderNumber = await GetLastOrderNumber(mindfightId); tour.OrderNumber = tour.OrderNumber == 0 ? 1 : tour.OrderNumber + 1; var tourToCreate = new Models.Tour( currentMindfight, tour.Title, tour.Description, tour.TimeToEnterAnswersInSeconds, tour.IntroTimeInSeconds, tour.OrderNumber); return(await _tourRepository.InsertAndGetIdAsync(tourToCreate)); }