public ActionResult Create(DialoguePage page) { if (UserIsAuthenticated) { using (UnitOfWorkManager.NewUnitOfWork()) { var allowedCategories = ServiceFactory.CategoryService.GetAllowedCategories(_membersGroup).ToList(); if (allowedCategories.Any() && CurrentMember.DisablePosting != true) { var viewModel = new CreateTopic(page) { Categories = allowedCategories, LoggedOnUser = CurrentMember, SubscribeToTopic = true, PageTitle = Lang("Topic.CreateTopic") }; // Pre-Select category user is in var cat = Request["cat"]; if (!string.IsNullOrEmpty(cat)) { var catId = Convert.ToInt32(cat); if (catId > 0) { viewModel.Category = catId; } } return(View(PathHelper.GetThemeViewPath("Create"), viewModel)); } } } return(ErrorToHomePage(Lang("Errors.NoPermission"))); }
void PropagateRequest(CreateTopic request) { var client = new RestClient(request.Cooperator); var requestToSend = new RestRequest("topics", Method.POST); requestToSend.AddParameter("Name", request.Name); client.Execute(requestToSend); }
public async Task <ApiResult> PostNewTopic() { var requester = await GetRequestUserAsync(); var converter = await _GetConverterAsync(requester, GetReturnForm); var data = await DeserializeFromBodyAsync <CreateTopicData>(); var handler = new CreateTopic(Db, _logger); var topic = await handler.CreateAsync(data, requester); return(new ApiResult("Topic", converter.Convert(topic))); }
public Task <Topic> Execute(PangulDbContext db, CreateTopic command) { command.Validate(); var instance = new Topic() { Icon = null, Name = command.DerivedProperties.TopicName, TimeCreated = DateTimeOffset.Now }; db.Topic.Add(instance); return(Task.FromResult(instance)); }
public async Task <string> CreateAsync(CreateTopic command) { await _createValidator.ValidateCommandAsync(command); var title = Regex.Replace(command.Title, @"\s+", " "); // Remove multiple spaces from title var slug = string.IsNullOrWhiteSpace(command.Slug) ? await GenerateSlugAsync(command.ForumId, title) : command.Slug; var topic = Post.CreateTopic(command.Id, command.ForumId, command.UserId, title, slug, command.Content, command.Status); _dbContext.Posts.Add(topic); _dbContext.Events.Add(new Event(command.SiteId, command.UserId, EventType.Created, typeof(Post), command.Id, new { command.ForumId, title, Slug = slug, command.Content, command.Status })); var forum = await _dbContext.Forums.Include(x => x.Category).FirstOrDefaultAsync(x => x.Id == topic.ForumId); forum.UpdateLastPost(topic.Id); forum.IncreaseTopicsCount(); forum.Category.IncreaseTopicsCount(); var user = await _dbContext.Users.FirstOrDefaultAsync(x => x.Id == topic.CreatedBy); user.IncreaseTopicsCount(); await _dbContext.SaveChangesAsync(); _cacheManager.Remove(CacheKeys.Forum(forum.Id)); return(slug); }
public async Task <OmfConnection> CreateOmfConnectionAsync(string deviceClientId, string connectionName, string destinationNamespaceId) { // Create a Topic Console.WriteLine($"Creating a Topic in Namespace {_namespaceId} for Client with Id {deviceClientId}"); Console.WriteLine(); CreateTopic topic = new CreateTopic() { Name = connectionName, Description = "This is a sample Topic", }; topic.ClientIds.Add(deviceClientId); Topic createdTopic = await _omfIngressService.CreateTopicAsync(topic).ConfigureAwait(false); Console.WriteLine($"Created a Topic with Id {createdTopic.Id}"); Console.WriteLine(); // Create a Subscription Console.WriteLine($"Creating a Subscription in Namespace {destinationNamespaceId} for Topic with Id {createdTopic.Id}"); Console.WriteLine(); CreateSubscription subscription = new CreateSubscription() { Name = $"{connectionName}-{destinationNamespaceId}", Description = "This is a sample Subscription", TopicId = createdTopic.Id, TopicTenantId = _tenantId, TopicNamespaceId = _namespaceId, }; Subscription createdSubscription = await _omfIngressService.CreateSubscriptionAsync(subscription).ConfigureAwait(false); Console.WriteLine($"Created a Subscription with Id {createdSubscription.Id}"); Console.WriteLine(); OmfConnection omfConnection = new OmfConnection(new List <string> { deviceClientId }, createdTopic, createdSubscription); return(omfConnection); }
public void Create(CreateTopic request) { var topicLock = Locks.TakeTopicLock(request.Name); lock (topicLock) { if (Locks.TopicsRecoveryLocks.ContainsKey(request.Name)) { throw new Exception($"Topic {request.Name} is inconsistent"); } using (var connection = Connections.ConnectToTopic(request.Name)) { connection.CreateTableIfNotExists <Announcement>(); connection.CreateTableIfNotExists <Subscriber>(); } if (!string.IsNullOrEmpty(request.Cooperator)) { Propagators.ScheduleTopicOperation(request.Name, () => PropagateRequest(request)); } } }
public async Task <IActionResult> CreateTopic([FromBody] CreateTopic newTopic) { try { if (!ModelState.IsValid) { return(Json(new { IsSuccess = false, Message = "" })); } else { var currentUser = _userRepository.GetByIdAsync(_userAppContext.CurrentUserId); newTopic.OwnerId = currentUser.Id; newTopic.UserUId = currentUser.UId; var topicCreated = await _blockService.CreateTopic(newTopic); return(Json(new { IsSuccess = true, Topic = topicCreated })); } } catch (Exception e) { return(Json(new { IsSuccess = false, Message = e.Message })); } }
public async Task <ActionResult> CreateTopic(PostPageModel model) { var site = await _contextService.CurrentSiteAsync(); var user = await _contextService.CurrentUserAsync(); var permissions = await _permissionModelBuilder.BuildPermissionModelsByForumId(site.Id, model.Forum.Id); var canPost = _securityService.HasPermission(PermissionType.Start, permissions) && !user.IsSuspended; if (!canPost) { _logger.LogWarning("Unauthorized access to create topic", new { SiteId = site.Id, ForumId = model.Forum?.Id, User = User.Identity.Name }); return(Unauthorized()); } var command = new CreateTopic { ForumId = model.Forum.Id, Title = model.Topic.Title, Content = model.Topic.Content, Status = PostStatusType.Published, SiteId = site.Id, UserId = user.Id }; var slug = await _topicService.CreateAsync(command); return(Ok(slug)); }
public WebApiTestTopic() { creator = new CreateTopic(); controller = new TopicController(); }
public async Task <BlockViewModel> CreateTopic(CreateTopic newTopic) { try { if (newTopic == null || newTopic.BlockNumber == -1) { throw new ApplicationException("Topic is not null"); } if ( string.IsNullOrEmpty(newTopic.CountryName) || string.IsNullOrEmpty(newTopic.Description) || string.IsNullOrEmpty(newTopic.CountryName)) { throw new ApplicationException("Topic detail is not completed to save"); } //Make sure only 1 topic per block var alreadyHasTopic = _blockRepository.Get(x => x.BlockNumber == newTopic.BlockNumber).Any(); if (alreadyHasTopic) { throw new ApplicationException("This block number already has topic"); } // Find the block this new topic will belong too. var owningCountry = _countryRepository .GetQueryable() .Single(x => x.Blocks.Any(y => y.BlockNumber == newTopic.BlockNumber)); var countryBlock = owningCountry.Blocks.Single(y => y.BlockNumber == newTopic.BlockNumber); var objectId = countryBlock.Id; var UId = countryBlock.UId; // TODO: Consider refactor for BlockDetail and BlockViewModel for interacting with BlockService. var blockObj = new BlockDetail { UId = UId, Id = objectId, Name = newTopic.Name, Description = newTopic.Description, BlockAxis = newTopic.BlockAxis, BlockYxis = newTopic.BlockYxis, BlockNumber = newTopic.BlockNumber, CreatedOn = DateTime.UtcNow, CreatedBy = newTopic.UserUId, CountryId = newTopic.CountryId, OwnerId = newTopic.OwnerId, TotalResidents = 1, IsDeleted = false, }; await _blockRepository.Add(blockObj); var blockViewModel = new BlockViewModel { Id = blockObj.Id, Name = blockObj.Name, Description = blockObj.Description, BlockAxis = blockObj.BlockAxis, BlockYxis = blockObj.BlockYxis, CreatedOn = blockObj.CreatedOn, CreatedBy = blockObj.CreatedBy, Owner = null, TotalResidents = blockObj.TotalResidents, }; return(blockViewModel); } catch (System.Exception e) { throw new ApplicationException("Create topic error " + e.Message); } }
private void newTopic_Click(object sender, EventArgs e) { CreateTopic ct = new CreateTopic(); ct.Show(); }