public ActionResult Create(CourseViewModel model) { try { var repository = new CourseRepository(context); if (ModelState.IsValid) { var course = MapperHelper.Map <Course>(model); //Pasar modelo ya lleno //course.Topics = new List<Topic>(); /* var topicRepo = new TopicRepository(context); * foreach (var topicId in model.SelectedTopics) { * course.Topics.Add(topicRepo.Find(topicId)); * * } * repository.Insert(course); */ repository.InsertCourseWithTopics(course, model.SelectedTopics); context.SaveChanges(); return(RedirectToAction("Index")); } else { var topicRepository = new TopicRepository(context); var topics = topicRepository.Query(null, "Name DESC"); model.AvailableTopics = MapperHelper.Map <ICollection <TopicViewModel> >(topics); return(View(model)); } } catch { return(View()); } }
public UnitOfWork(ApplicationDbContext context) { _context = context; Attempts = new AttemptRepository(_context); Exams = new ExamRepository(_context); Images = new ImageRepository(_context); NoteParameters = new NoteParameterRepository(_context); Notifications = new NotificationRepository(_context); Notes = new NoteRepository(_context); Opinions = new OpinionRepository(_context); Options = new OptionRepository(_context); Passages = new PassageRepository(_context); Questions = new QuestionRepository(_context); Requirements = new RequirementRepository(_context); Roles = new RoleRepository(_context); RoleClaims = new RoleClaimRepository(_context); Standards = new StandardRepository(_context); Sittings = new SittingRepository(_context); Topics = new TopicRepository(_context); Users = new UserRepository(_context); UserClaims = new UserClaimRepository(_context); UserLogins = new UserLoginRepository(_context); UserRoles = new UserRoleRepository(_context); UserTokens = new UserTokenRepository(_context); }
public IActionResult Index(int id = 0, int unread = 0) { var boardRoles = RoleRepository.BoardRoles.Where(r => r.BoardId == id).Select(r => r.RoleId).ToList(); if (!UserContext.IsAdmin && boardRoles.Any() && !boardRoles.Intersect(UserContext.Roles).Any()) { throw new HttpForbiddenError(); } var sidebar = new ViewModels.Sidebar { Birthdays = AccountRepository.GetBirthdaysList().ToArray(), OnlineUsers = AccountRepository.GetOnlineList(), Notifications = NotificationRepository.Index() }; var page = 1; var topicPreviews = TopicRepository.GetPreviews(id, page, unread); var boardRecord = id == 0 ? null : BoardRepository.FirstOrDefault(record => record.Id == id); var viewModel = new PageModels.TopicIndexPage { BoardId = id, BoardName = boardRecord?.Name ?? "All Topics", Page = page, Topics = topicPreviews, UnreadFilter = unread, Sidebar = sidebar }; return(ForumViewResult.ViewResult(this, viewModel)); }
public async void CanPartialUpdateTopicDescription() { _dataAccessMock.Setup(dal => dal.Update <DataEntity.Topic>( It.IsAny <string>(), It.IsAny <Expression <Func <DataEntity.Topic> > >())) .ReturnsAsync(new DataEntity.Topic()) .Verifiable(); MockTopicCache(new DataEntity.Topic { Id = "5883a3fa50f5fea2822f21cf", Description = "mockedDescription", Notes = "mockNotes" }); var topicRep = new TopicRepository(_dataAccessMock.Object, _topicCacheMock.Object); var topicController = new TopicController.TopicController(new QuizManager.QuizManager(topicRep, null, null), null); var jsonPatchRequest = new JsonPatchDocument <ResponseData.TopicIgnoreUniqId>(); jsonPatchRequest.Replace((q) => q.Description, "mockDescriptionToUpdate"); var result = await topicController.UpdateTopic("mockId", jsonPatchRequest); var objectResult = Assert.IsType <OkObjectResult>(result); objectResult.StatusCode.Should().Be(200, "Should return status code as modified"); var updatedResult = Assert.IsAssignableFrom <ResponseData.Topic>(((ObjectResult)result).Value); updatedResult.Description.Should().Equals("mockDescriptionToUpdate"); updatedResult.Notes.Should().Equals("mockNotes"); updatedResult.Id.Should().Equals("5883a3fa50f5fea2822f21cf"); }
public DataService() { switch (Device.RuntimePlatform) { case Device.Android: databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), databaseName); break; case Device.iOS: SQLitePCL.Batteries_V2.Init(); databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library", databaseName); break; default: break; } Database = new SQLiteConnection(databasePath); Database.CreateTable <Minute>(); Database.CreateTable <MinuteImage>(); Database.CreateTable <Topic>(); Database.CreateTable <Information>(); Database.CreateTable <Person>(); MinuteRepository = new MinuteRepository(Database); MinuteImageRepository = new MinuteImageRepository(Database); TopicRepository = new TopicRepository(Database); InformationRepository = new InformationRepository(Database); PersonRepository = new PersonRepository(Database); }
public TopicLogic CreateLogic() { var Repository = new TopicRepository(Context); var Logic = new TopicLogic(Repository); return(Logic); }
public void Topic_ShoulInsertOk() { var context = new LearningContext(); var topicRepository = new TopicRepository(context); topicRepository.Insert(new Topic { Name = "Entity Framework", Descripcion = "Applyling EF6 Data Access Stratagy" } ); topicRepository.Insert(new Topic { Name = "Entity Framework2", Descripcion = "Applyling EF6 Data Access Stratagy" } ); var individual = new IndividualRepository(context); individual.Insert(new Individual { Name = "Benigno", Email = "*****@*****.**" } ); individual.Insert(new Individual { Name = "Antonio", Email = "*****@*****.**" } ); context.SaveChanges(); }
public IHttpActionResult stopTopic(StopTopicReq str) { TopicRepository tr = new TopicRepository(); topic t = tr.setStop(str.topicSn); return(Ok(t)); }
public async Task <IActionResult> Index(int id = 0, int pageId = 1, int unread = 0) { var messageIds = await TopicRepository.GetIndexIds(id, pageId, unread); var morePages = true; if (messageIds.Count < UserContext.ApplicationUser.TopicsPerPage) { morePages = false; } var topicPreviews = await TopicRepository.GetPreviews(messageIds); var boardRecord = id == 0 ? null : (await BoardRepository.Records()).FirstOrDefault(record => record.Id == id); var viewModel = new PageModels.TopicIndexPage { BoardId = id, BoardName = boardRecord?.Name ?? "All Topics", CurrentPage = pageId, Topics = topicPreviews, UnreadFilter = unread, MorePages = morePages }; return(await ForumViewResult.ViewResult(this, viewModel)); }
public Topics( ApplicationDbContext applicationDbContext, UserContext userContext, BoardRepository boardRepository, BookmarkRepository bookmarkRepository, MessageRepository messageRepository, RoleRepository roleRepository, SmileyRepository smileyRepository, TopicRepository topicRepository, IForumViewResult forumViewResult, IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory ) { DbContext = applicationDbContext; UserContext = userContext; BoardRepository = boardRepository; BookmarkRepository = bookmarkRepository; MessageRepository = messageRepository; RoleRepository = roleRepository; SmileyRepository = smileyRepository; TopicRepository = topicRepository; ForumViewResult = forumViewResult; UrlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext); }
public async Task <IActionResult> Index(int id = 0, int page = 1, int unread = 0) { var topicIds = await TopicRepository.GetIndexIds(id, page, unread); var morePages = true; if (topicIds.Count < UserContext.ApplicationUser.TopicsPerPage) { morePages = false; } var topicPreviews = await TopicRepository.GetPreviews(topicIds); var boardRecords = await BoardRepository.Records(); var boardRecord = id == 0 ? null : boardRecords.FirstOrDefault(item => item.Id == id); var viewModel = new ViewModels.Topics.TopicIndexPage { BoardId = id, BoardName = boardRecord?.Name ?? "All Topics", CurrentPage = page, Topics = topicPreviews, UnreadFilter = unread, MorePages = morePages }; return(View(viewModel)); }
public ActionResult AddTopic(string name) { TopicRepository repo = new TopicRepository(); string message = string.Empty; bool errored = false; if (string.IsNullOrEmpty(name)) { errored = true; message = "Missing value"; } else { try { repo.AddTopic(name); } catch (Exception exc) { errored = true; message = exc.ToString(); } } if (!errored) { message = "Changes Saved"; } return(Json(new { Errored = errored, Message = message }, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(TopicViewModel model) { try { if (ModelState.IsValid) { var repository = new TopicRepository(context); var topicQry = new Topic { Name = model.Name }; var nombreExiste = repository.QueryByExample(topicQry).Count > 0; if (!nombreExiste) { var topic = MapperHelper.Map <Topic>(model); repository.Insert(topic); context.SaveChanges(); } else { ModelState.AddModelError("Name", "El nombre ya está ocupado por otro tópico."); return(View(model)); } } return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Error = ex.Message; return(View()); } }
public void GetEntityWithNotExistingID() { TopicRepository repository = new TopicRepository(); Topic resultTopic = repository.GetEntity <Topic>(NotExistindID); Assert.IsNull(resultTopic); }
private void GetPostService(UnitOfWork uow, out ICategoryService categoryService, out IForumService forumService, out ITopicService topicService, out IPostService postService) { ICategoryRepository cateRepo = new CategoryRepository(uow); IForumRepository forumRepo = new ForumRepository(uow); ITopicRepository topicRepo = new TopicRepository(uow); IPostRepository postRepo = new PostRepository(uow); IForumConfigurationRepository configRepo = new ForumConfigurationRepository(uow); IState request = new DummyRequest(); ILogger logger = new ConsoleLogger(); IUserRepository userRepo = new UserRepository(uow); User user = userRepo.Create(new User { Name = "D. Ummy", ProviderId = "12345678", FullName = "Mr. Doh Ummy", EmailAddress = "[email protected]", Culture = "th-TH", TimeZone = "GMT Standard Time" }); List<IEventSubscriber> subscribers = new List<IEventSubscriber>(); IEventPublisher eventPublisher = new EventPublisher(subscribers, logger, request); IUserProvider userProvider = new DummyUserProvider(user); IPermissionService permService = new PermissionService(); IForumConfigurationService confService = new ForumConfigurationService(configRepo); categoryService = new CategoryService(userProvider, cateRepo, eventPublisher, logger, permService); forumService = new ForumService(userProvider, cateRepo, forumRepo, topicRepo, postRepo, eventPublisher, logger, permService); topicService = new TopicService(userProvider, forumRepo, topicRepo, postRepo, eventPublisher, logger, permService, confService); postService = new PostService(userProvider, forumRepo, topicRepo, postRepo, eventPublisher, logger, permService, confService); }
public void GetAllEntitiesCount() { TopicRepository repository = new TopicRepository(); var topics = repository.GetAllEntities <Topic>(); Assert.AreEqual(repository.Topics.Count, topics.Count); }
/*========================================================================================================================== | METHOD: INVOKE (ASYNC) \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Provides the footer menu for the site. /// </summary> public async Task<IViewComponentResult> InvokeAsync() { /*------------------------------------------------------------------------------------------------------------------------ | Establish variables \-----------------------------------------------------------------------------------------------------------------------*/ var navigationRootTopic = TopicRepository.Load("Web:Company"); var webPath = CurrentTopic?.GetWebPath(); var isInWeb = CurrentTopic?.GetUniqueKey().StartsWith("Root:Web", StringComparison.OrdinalIgnoreCase); var navigationRoot = CurrentTopic?.Attributes.GetValue("NavigationRoot", null, true); /*------------------------------------------------------------------------------------------------------------------------ | Construct view model \-----------------------------------------------------------------------------------------------------------------------*/ var navigationViewModel = new FooterViewModel() { NavigationRoot = await HierarchicalTopicMappingService.GetRootViewModelAsync(navigationRootTopic).ConfigureAwait(true), CurrentWebPath = webPath, IsMainSite = navigationRoot?.Equals("Web", StringComparison.OrdinalIgnoreCase)?? isInWeb?? true }; /*------------------------------------------------------------------------------------------------------------------------ | Return the corresponding view \-----------------------------------------------------------------------------------------------------------------------*/ return View(navigationViewModel); }
public UnitOfWork(AppDbContext context) { this.context = context; Auth = new AuthRepository(this.context); Users = new AccountRepository(this.context); UserSessions = new UserSessionRepository(this.context); Settings = new SettingsRepository(this.context); Clients = new ClientRepository(this.context); PersistedGrants = new PersistentGrantRepository(this.context); SekaniLevels = new SekaniLevelRepository(this.context); SekaniWords = new SekaniWordRepository(this.context); SekaniCategories = new SekaniCategoryRepository(this.context); Topics = new TopicRepository(this.context); EnglishWords = new EnglishWordRepository(this.context); SekaniWordAudios = new SekaniWordAudioRepository(this.context); SekaniRoots = new SekaniRootRepository(this.context); SekaniRootImages = new SekaniRootImageRepository(this.context); SekaniForms = new SekaniFormRepository(this.context); SekaniWordExamples = new SekaniWordExampleRepository(this.context); SekaniWordExampleAudios = new SekaniWordExampleAudioRepository(this.context); SekaniWordAttributes = new SekaniWordAttributeRepository(this.context); SekaniRootsEnglishWords = new SekaniRootEnglishWordRepository(this.context); SekaniRootsTopics = new SekaniRootTopicRepository(this.context); UserActivityStats = new UserActivityStatRepository(this.context); UserLearnedWords = new UserLearnedWordRepository(this.context); UserFailedWords = new UserFailedWordRepository(this.context); GameRepository = new GameRepository(this.context); }
public IActionResult Delete(int[] topics) { /*------------------------------------------------------------------------------------------------------------------------ | Validate input \-----------------------------------------------------------------------------------------------------------------------*/ Contract.Requires(topics, nameof(topics)); /*------------------------------------------------------------------------------------------------------------------------ | Delete topics \-----------------------------------------------------------------------------------------------------------------------*/ foreach (var topicId in topics) { if (topicId < 0) { continue; } var topic = TopicRepository.Load(topicId); if (!topic.GetUniqueKey().StartsWith(_licenseRoot, StringComparison.InvariantCultureIgnoreCase)) { continue; } TopicRepository.Delete(topic); } /*------------------------------------------------------------------------------------------------------------------------ | Return default view \-----------------------------------------------------------------------------------------------------------------------*/ return RedirectToAction(nameof(Index)); }
public void Setup() { //remove this call to base cause Resharper 4.5 doesn't support NUnit 2.5 very well yet setup(); repository = new TopicRepository(session); }
public Topics( ApplicationDbContext applicationDbContext, UserContext userContext, AccountRepository accountRepository, BoardRepository boardRepository, MessageRepository messageRepository, NotificationRepository notificationRepository, RoleRepository roleRepository, SettingsRepository settingsRepository, SmileyRepository smileyRepository, TopicRepository topicRepository, IForumViewResult forumViewResult, IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory ) { DbContext = applicationDbContext; UserContext = userContext; AccountRepository = accountRepository; BoardRepository = boardRepository; MessageRepository = messageRepository; NotificationRepository = notificationRepository; RoleRepository = roleRepository; SettingsRepository = settingsRepository; SmileyRepository = smileyRepository; TopicRepository = topicRepository; ForumViewResult = forumViewResult; UrlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext); }
public UnitOfWork(DbContext context) { _context = context; UserRepository = new UserRepository(context); TopicRepository = new TopicRepository(context); }
public ActionResult Topics() { TopicRepository repo = new TopicRepository(); List <Models.Topic> lstReturn = repo.GetAll(); return(Json(lstReturn, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(int id, EditTopicViewModel model) { try { var repository = new TopicRepository(context); if (model.Name != model.NombreAnterior) { var existeNombre = repository.Query(x => x.Name == model.Name && x.Id != model.Id).Count > 0; if (existeNombre) { ModelState.AddModelError("Name", "El nombre ya está ocupado por otro tópico."); return(View(model)); } } else { ModelState.Remove("Nombre"); } if (ModelState.IsValid) { var topic = MapperHelper.Map <Topic>(model); repository.Update(topic); context.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public override BaseRepository <Topic, Area> CreateRepository() { IMMRequestContext IMMRequestContext = ContextFactory.GetNewContext(); TopicRepository topicRepo = new TopicRepository(IMMRequestContext); return(topicRepo); }
public void SearchInTopics(string value, List <TagViewModel> tags) { List <FanficPreViewModel> resultList = Mapper.Map <List <FanficPreViewModel> >( TopicRepository.SearchInTopics(value)); resultList.ForEach(x => addToResult(x, tags)); }
/*========================================================================================================================== | HELPER: SAVE TO TOPIC \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Adds the form values to a new <see cref="Topic"/>, and saves it to the <see cref="ITopicRepository"/>. /// </summary> private async Task SaveToTopic(ITopicBindingModel bindingModel) { /*------------------------------------------------------------------------------------------------------------------------ | Establish variables \-----------------------------------------------------------------------------------------------------------------------*/ bindingModel.ContentType = bindingModel.GetType().Name.Replace("BindingModel", ""); bindingModel.Key = bindingModel.ContentType + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); /*------------------------------------------------------------------------------------------------------------------------ | Validate Topic Parent \-----------------------------------------------------------------------------------------------------------------------*/ var parentKey = "Administration:Licenses"; var parentTopic = TopicRepository.Load(parentKey); /*------------------------------------------------------------------------------------------------------------------------ | Map binding model to new topic \-----------------------------------------------------------------------------------------------------------------------*/ var topic = await _reverseMappingService.MapAsync(bindingModel); var errorMessage = $"The topic '{parentKey}' could not be found. A root topic to store forms to is required."; /*------------------------------------------------------------------------------------------------------------------------ | Set Topic values \-----------------------------------------------------------------------------------------------------------------------*/ topic.Parent = parentTopic?? throw new Exception(errorMessage); topic.LastModified = DateTime.Now; /*------------------------------------------------------------------------------------------------------------------------ | Save form Topic \-----------------------------------------------------------------------------------------------------------------------*/ TopicRepository.Save(topic); }
public ActionResult Edit(int id, CourseViewModel model) { var topicRepository = new TopicRepository(context); try { var repository = new CourseRepository(context); if (ModelState.IsValid) { var course = MapperHelper.Map <Course>(model); repository.UpdateCourseWithTopics(course, model.SelectTopics); context.SaveChanges(); return(RedirectToAction("Index")); } var topic = topicRepository.Query(null, "Name"); model.AvailableTopics = MapperHelper.Map <ICollection <TopicCourseViewModel> >(topic); return(View(model)); } catch { var topic = topicRepository.Query(null, "Name"); model.AvailableTopics = MapperHelper.Map <ICollection <TopicCourseViewModel> >(topic); return(View(model)); } }
public async Task <IActionResult> DisplayPartial(int id, long latest) { var latestTime = new DateTime(latest); var record = DbContext.Messages.Find(id); if (record is null) { throw new HttpNotFoundError(); } var topicId = id; if (record.ParentId > 0) { topicId = record.ParentId; } await LoadTopicBoards(topicId); var messageIds = MessageRepository.GetMessageIds(topicId, latestTime); var messages = await MessageRepository.GetMessages(messageIds); var latestMessageTime = messages.Max(r => r.RecordTime); TopicRepository.MarkRead(topicId, latestMessageTime, messageIds); var viewModel = new PageModels.TopicDisplayPartialPage { Latest = DateTime.Now.Ticks, Messages = messages }; return(await ForumViewResult.ViewResult(this, "DisplayPartial", viewModel)); }
public ActionResult Create(CourseViewModel model) { try { if (ModelState.IsValid) { var repository = new CourseRepository(context); var validacionName = new Course { Name = model.Name }; var nameExiste = repository.QueryByExample(validacionName).Count > 0; if (!nameExiste) { var course = MapperHelper.Map <Course>(model); repository.InsertCourseWithTopics(course, model.SelectTopics); context.SaveChanges(); } else { ModelState.AddModelError("Name", "El Nombre del curso ya existe"); var topicrepository = new TopicRepository(context); var topic = topicrepository.Query(null, "Name"); model.AvailableTopics = MapperHelper.Map <ICollection <TopicCourseViewModel> >(topic); return(View(model)); } } return(RedirectToAction("Index")); } catch (Exception ex) { return(View()); } }
private void GetForumService(UnitOfWork uow, out ICategoryService categoryService, out IForumService forumService) { ICategoryRepository cateRepo = new CategoryRepository(uow); IForumRepository forumRepo = new ForumRepository(uow); ITopicRepository topicRepo = new TopicRepository(uow); IPostRepository postRepo = new PostRepository(uow); IState request = new DummyRequest(); ILogger logger = new ConsoleLogger(); IUserRepository userRepo = new UserRepository(uow); User user = userRepo.Create(new User { Name = "D. Ummy", ProviderId = "12345678", FullName = "Mr. Doh Ummy", EmailAddress = "[email protected]", Culture = "th-TH", TimeZone = "GMT Standard Time" }); List <IEventSubscriber> subscribers = new List <IEventSubscriber>(); IEventPublisher eventPublisher = new EventPublisher(subscribers, logger, request); IUserProvider userProvider = new DummyUserProvider(user); IPermissionService permService = new PermissionService(); categoryService = new CategoryService(userProvider, cateRepo, eventPublisher, logger, permService); forumService = new ForumService(userProvider, cateRepo, forumRepo, topicRepo, postRepo, eventPublisher, logger, permService); }
public void Initialize() { topicRepository = ApplicationFactory.getTopicRepository(); topic = new Topic(); topic.Name = "Test"; topic.Description = "Test"; }
public TodoController(TodoRepository repository, BloggerGateway gateway, ThoughtRepository thoughtRepository, TopicRepository topicRepository) { this.repository = repository; this.gateway = gateway; this.thoughtRepository = thoughtRepository; this.topicRepository = topicRepository; }
public void setup() { mocks = new MockRepository(); builder = new TestControllerBuilder(); session = mocks.DynamicMock<ISession>(); topicRepository = mocks.StrictMock<TopicRepository>(session); topicController = new TopicController(topicRepository); builder.InitializeController(topicController); }
public DataService() { ConferenceStart = DateTime.Parse("2013/11/04"); ConferenceEnd = DateTime.Parse("2013/11/06"); TopicRepository = new TopicRepository(LoadJsonArray("topics.json")); SessionRepository = new SessionRepository(LoadJsonArray("sessions.json")); SpeakerRepository = new SpeakerRepository(LoadJsonArray("speakers.json")); SessionTopicRepository = new SessionTopicRepository(LoadJsonArray("sessiontopics.json")); }
public static void Init(DataStore dataStore) { Sentences = new SentenceRepository(dataStore, "SentenceText"); Vocabulary = new VocabRepository(dataStore, "Text"); GrammarEntries = new GrammarEntryRepository(dataStore, "Text"); GrammarRoles = new GrammarRolesRepository(dataStore, "RoleName"); Users = new UserRepository(dataStore, "UserID", "Email"); Topics = new TopicRepository(dataStore, "Index", "ToicName"); Sessions = new SessionRepository(dataStore, "UserID"); }
public TopicViewModel(TopicRepository topicRepository) { _topic = topicRepository; }
public List<Topic> GetTopicList() { var topicList = new TopicRepository(new DatabaseContext()).Get().ToList(); return topicList; }
public TopicController(TopicRepository topicRepository) { this.topicRepository = topicRepository; }
public ThoughtController(ThoughtRepository thoughtRepository, TopicRepository topicRepository) { this.thoughtRepository = thoughtRepository; this.topicRepository = topicRepository; }