Exemplo n.º 1
0
 public RepliesController(IRepliesRepository repliesRepository, ITopicsRepository topicsRepository, IUsersRepository usersRepository, IMapper mapper)
 {
     _repliesRepository = repliesRepository;
     _topicsRepository  = topicsRepository;
     _usersRepository   = usersRepository;
     _mapper            = mapper;
 }
Exemplo n.º 2
0
 public DataManager(IUsersRepository usesrs, ITopicsRepository topics, IDiscussionsRepository discussions, IMessagesRepository messages)
 {
     usersRepository       = usesrs;
     topicsRepository      = topics;
     discussionsRepository = discussions;
     messagessRepository   = messages;
 }
Exemplo n.º 3
0
 public TopicsController(ITopicsRepository topicsRepository, 
     IChaptersRepository chaptersRepository, IUserRepository userRepository)
 {
     ChaptersRepository = chaptersRepository;
     UserRepository = userRepository;
     TopicsRepository = topicsRepository;
 }
Exemplo n.º 4
0
        public ListOfTopics(ISectionsRepository sectionsRepo, ITopicsRepository topicsRepo, IMessagesRepository messagesRepo, int currentPage)
        {
            Sections = new List<Topics>();
            TotalTopics = topicsRepo.Topics.Count();
            int skip = (currentPage - 1) * TopicsPerPage;
            int current = 0;
            foreach (var section in sectionsRepo.Sections)
            {
                List<Theme> Themes = new List<Theme>();

                foreach (var topic in topicsRepo.Topics.Where(t => t.SectionID == section.Id).ToList())
                {
                    if ((current >= skip) && (current < TopicsPerPage + skip))
                        Themes.Add(new Theme()
                        {
                            Posts = topic,
                            TotalPosts = messagesRepo.Messages.Where(m => m.TopicId == topic.Id).Count(),
                            UserId = messagesRepo.Messages.Where(m =>
                                (m.TopicId == topic.Id) && (m.IsFirstMessage == true)).FirstOrDefault().UserId
                        });
                    current++;
                }

                if (Themes.Count() == 0)
                    continue;

                Sections.Add(new Topics() { SectionId = section.Id, SectionTheme = section.Theme, Items = Themes });

                if (current >= TopicsPerPage + skip)
                    break;
            }

            CurrentPage = currentPage;
        }
Exemplo n.º 5
0
        public async Task InvokeAsync(HttpContext context, ITopicsRepository topicsRepository, IMapper mapper)
        {
            var topics = topicsRepository.GetAll();
            var model  = mapper.Map <IEnumerable <TopicModel> >(topics);

            await Ok(context, model);
        }
Exemplo n.º 6
0
 public ForumController(IMessagesRepository messages, IUsersRepository users, 
     ISectionsRepository sections, ITopicsRepository topics)
 {
     this.messages = messages;
     this.users = users;
     this.sections = sections;
     this.topics = topics;
 }
Exemplo n.º 7
0
 public TopicsService(ITopicsRepository itopicsRepository,
                      ITeacherRepository iteacherRepository,
                      IStudentRepository studentRepository)
 {
     _topicsRepository  = itopicsRepository;
     _teacherRepository = iteacherRepository;
     _studentRepository = studentRepository;
 }
 public GetAllTopicsHandler(ITopicsRepository topicsRepository,
                            IVotesRepository votesRepository,
                            UserManager <User> userManager)
 {
     _topicsRepository = topicsRepository;
     _votesRepository  = votesRepository;
     _userManager      = userManager;
 }
Exemplo n.º 9
0
        public TopicsController(ITopicsRepository repository)
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            _repository = repository;
        }
Exemplo n.º 10
0
        public GetQuizByIdHandler(
            IQuizzesRepository quizRepository,
            ITopicsRepository topicsRepository)
        {
            _quizRepository = quizRepository
                              ?? throw new ArgumentNullException(nameof(quizRepository));

            _topicsRepository = topicsRepository
                                ?? throw new ArgumentNullException(nameof(topicsRepository));
        }
 public CreateTopicHandler(IMapper mapper,
                           ITopicsRepository topicsRepository,
                           IOptionsRepository optionsRepository,
                           ITransaction databaseTransaction, ILogger <CreateTopicHandler> logger)
 {
     _mapper              = mapper;
     _topicsRepository    = topicsRepository;
     _optionsRepository   = optionsRepository;
     _databaseTransaction = databaseTransaction;
     _logger              = logger;
 }
 public GetTopicDetailsHandler(ITopicsRepository topicsRepository,
                               IOptionsRepository optionsRepository,
                               IVotesRepository votesRepository,
                               UserManager <User> userManager, IMapper mapper)
 {
     _topicsRepository  = topicsRepository;
     _optionsRepository = optionsRepository;
     _votesRepository   = votesRepository;
     _userManager       = userManager;
     _mapper            = mapper;
 }
 public AddVoteCommandHandler(IVotesRepository votesRepository,
                              IMapper mapper,
                              IOptionsRepository optionsRepository,
                              ITopicsRepository topicsRepository,
                              ILogger <AddVoteCommandHandler> logger)
 {
     _votesRepository   = votesRepository;
     _mapper            = mapper;
     _optionsRepository = optionsRepository;
     _topicsRepository  = topicsRepository;
     _logger            = logger;
 }
Exemplo n.º 14
0
 public TopicsController(ITopicsRepository topicsRepository,
                         IMapper mapper,
                         IUsersRepository usersRepository,
                         ICategoriesRepository categoriesRepository,
                         IRepliesRepository repliesRepository)
 {
     _topicsRepository     = topicsRepository;
     _usersRepository      = usersRepository;
     _categoriesRepository = categoriesRepository;
     _repliesRepository    = repliesRepository;
     _mapper = mapper;
 }
Exemplo n.º 15
0
 public TopicsController(
     ITopicsRepository topicsRepository,
     IStudentRepository studentRepository,
     SignInManager <ApplicationUser> signManager,
     UserManager <ApplicationUser> userManager
     )
 {
     _topicsRepository = topicsRepository;
     //_studentRepository = studentRepository;
     _signManager = signManager;
     _userManager = userManager;
 }
Exemplo n.º 16
0
 public ForumController(ITopicGroupsRepository topicGroupsRepository,
                        ITopicsRepository topicsRepository,
                        IDiscussionsRepository discussionsRepository,
                        IContributionsRepository contributionsRepository,
                        UserManager <User> userManager,
                        ITagsService tagsService)
 {
     this.topicGroupsRepository   = topicGroupsRepository;
     this.topicsRepository        = topicsRepository;
     this.discussionsRepository   = discussionsRepository;
     this.contributionsRepository = contributionsRepository;
     this.userManager             = userManager;
     this.tagsService             = tagsService;
 }
        public async Task InvokeAsync(HttpContext context, ITopicsRepository topicsRepository, IMapper mapper, DefaultEventGridEventHandler eventHandler, IOptions <AwesomeEventGridOptions> options)
        {
            try
            {
                ModelState.Reset();

                using (var reader = new StreamReader(context.Request.Body, Encoding.UTF8))
                {
                    var topicToCreate = JsonConvert.DeserializeObject <TopicModel>(await reader.ReadToEndAsync(), options.Value.SerializerSettings);
                    if (topicToCreate == null)
                    {
                        ModelState.AddError("", "Request body is required");
                    }

                    Validate(topicToCreate);

                    if (!ModelState.IsValid)
                    {
                        await BadRequest(context);

                        return;
                    }

                    if (topicsRepository.FindByName(topicToCreate.Name) != null)
                    {
                        ModelState.AddError("name", "Topic does already exists");
                        await BadRequest(context);

                        return;
                    }

                    var topic = mapper.Map <Topic>(topicToCreate);
                    topic = topicsRepository.Add(topic);

                    var topicModel = mapper.Map <TopicModel>(topic);
                    //todo fix url:
                    await CreatedAt(context, "http://foo", topicModel);
                }
            }
            catch (JsonException ex)
            {
                ModelState.AddError("", ex.Message);
                await BadRequest(context);
            }
        }
Exemplo n.º 18
0
        public async Task InvokeAsync(HttpContext context, ITopicsRepository topicsRepository, IMapper mapper)
        {
            ModelState.Reset();

            var name  = (string)context.GetRouteData().Values["name"];
            var topic = topicsRepository.FindByName(name);

            if (topic == null)
            {
                ModelState.AddError("name", "Topic with this name not found");
                await NotFound(context);
            }
            else
            {
                var model = mapper.Map <TopicModel>(topic);
                await Ok(context, model);
            }
        }
        public async Task InvokeAsync(HttpContext context, ITopicsRepository topicsRepository, IMapper mapper, IEventGridEventHandler eventGridEventHandler)
        {
            var options = context.RequestServices.GetService <IOptions <AwesomeEventGridOptions> >();

            ModelState.Reset();
            var topic = (string)context.GetRouteData().Values["name"];

            if (topicsRepository.FindByName(topic) == null)
            {
                ModelState.AddError("name", "Topic does not exists");
                await BadRequest(context);
            }
            else
            {
                using (var reader = new StreamReader(context.Request.Body, Encoding.UTF8))
                {
                    var eventsToPublish = JsonConvert.DeserializeObject <EventModel[]>(await reader.ReadToEndAsync(), options.Value.SerializerSettings);
                    await eventGridEventHandler.HandleAsync(topic, eventsToPublish);

                    await Accepted(context);
                }
            }
        }
Exemplo n.º 20
0
 public TopicsControllerTests()
 {
     _topicsRepositoryMock = Substitute.For <ITopicsRepository>();
     _server = TestServer.Create(app => OwinStartup.CoreConfiguration(app, PrepareContainer));
 }
Exemplo n.º 21
0
 public TopicsController(ITopicsRepository repository)
 {
     _repository = repository;
 }
Exemplo n.º 22
0
 public GetAllTopicsHandler(ITopicsRepository topicRepository)
 {
     _topicRepository = topicRepository ?? throw new ArgumentNullException(nameof(topicRepository));
 }
Exemplo n.º 23
0
 public TopicsService(ITopicsRepository topicsRepository, IUnitOfWork unitOfWork)
 {
     this.topicsRepository = topicsRepository;
     this.unitOfWork = unitOfWork;
 }
Exemplo n.º 24
0
        public async Task InvokeAsync(HttpContext context, IHttpClientFactory httpClientFactory, ISubscriptionsRepository subscriptionsRepository, ITopicsRepository topicsRepository, IMapper mapper, IEventGridEventHandler eventGridEventHandler, IOptions <AwesomeEventGridOptions> options)
        {
            try
            {
                ModelState.Reset();

                using (var reader = new StreamReader(context.Request.Body, Encoding.UTF8))
                {
                    var routeData = context.GetRouteData();
                    var topic     = (string)routeData.Values["topic"];

                    if (topicsRepository.FindByName(topic) == null)
                    {
                        ModelState.AddError("name", "Topic with this name not found");
                        await NotFound(context);

                        return;
                    }

                    var subscriptionModel = JsonConvert.DeserializeObject <SubscriptionModel>(await reader.ReadToEndAsync(), options.Value.SerializerSettings);

                    var subscription = mapper.Map <Subscription>(subscriptionModel);

                    subscription.Topic = topic;
                    var client = httpClientFactory.CreateClient();

                    var validation = new SubscriptionValidationEventDataModel()
                    {
                        ValidationCode = Guid.NewGuid().ToString()
                    };

                    var source = $"{options.Value.TopicsPath}/{topic}#validation";

                    var validationEvent = new EventModel
                    {
                        EventType = "subscriptions.validate",
                        Source    = new Uri(source, UriKind.Relative),
                        Data      = validation,
                    };
                    var response = await client.PostAsJsonAsync(subscription.EndpointUrl, validationEvent);

                    response.EnsureSuccessStatusCode();
                    var content = await response.Content.ReadAsAsync <SubscriptionValidationResponse>();

                    if (content.ValidationResponse != validation.ValidationCode)
                    {
                        ModelState.AddError("", "Endpoint responded with invalid validation code.");
                        await BadRequest(context);

                        return;
                    }


                    var newSubscription = subscriptionsRepository.AddOrUpdate(subscription);
                    var model           = mapper.Map <SubscriptionModel>(newSubscription);

                    var link = "http://link"; // todo
                    await CreatedAt(context, link, model);

                    //    }
                    //    catch (HttpRequestException ex)
                    //    {
                    //        return BadRequest(ex.Message);
                    //    }
                }
            }
            catch (JsonException ex)
            {
                ModelState.AddError("", ex.Message);
                await BadRequest(context);
            }
            catch (HttpRequestException ex)
            {
                ModelState.AddError("", ex.Message);
                await BadRequest(context);
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Construct TopicsController
 /// </summary>
 /// <param name="topicRepository"></param>
 public TopicsController(ITopicsRepository topicRepository)
 {
     TopicRepository = topicRepository;
 }
 private void InitServices()
 {
     _modulesService = new ModulesRepository(AppConfig.ServiceUrl, _accountService);
     _chaptersService = new ChaptersRepository(AppConfig.ServiceUrl, _accountService);
     _topicsService = new TopicsRepository(AppConfig.ServiceUrl, _accountService);
 }
Exemplo n.º 27
0
 public TopicsService(ITopicsRepository topicsRepository)
 {
     _topicsRepository = topicsRepository;
 }