public async Task <IActionResult> PostTopic() { var source = JsonConvert.DeserializeObject <PostTopicViewModel>(Request.Form["source"]); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (await _topicRepository.Exists(source.Title, source.LessonId)) { return(BadRequest(new { errors = "Already Exists" })); } Topic target = new Topic { Slug = Slug.GenerateSlug(source.Title), LessonId = source.LessonId, Title = source.Title, IsActive = source.IsActive, CreatedOn = DateTime.Now, RowId = Guid.NewGuid() }; var result = await _topicRepository.Add(target); await StoreToAzureTable(source, target); return(CreatedAtAction("getCategory", new { id = result.TopicId }, source)); }
public bool Add(TopicDto topicDto) { try { var result = _topicRepository.GetByName(topicDto.TopicName); if (result == null) { Topic topic = new Topic() { TopicName = topicDto.TopicName, TopicDetail = topicDto.TopicDetail }; _topicRepository.Add(topic); _topicRepository.SaveChange(); } else { return(false); } return(true); } catch (Exception ex) { return(false); } }
public async Task <IActionResult> CreateTopic(int?subjectId) { if (subjectId.HasValue) { var subject = await _subjectRepository.GetById(subjectId.Value); if (!ExistsAndAllowedToUse(subject)) { return(NotFound()); } Topic newTopic = new Topic() { Name = "", DateLearned = DateTime.Now, SubjectId = subjectId.Value, UserId = _userManager.GetUserId(HttpContext.User) }; newTopic.DateLearned = newTopic.DateLearned.AddMilliseconds(-newTopic.DateLearned.Millisecond); newTopic.DateLearned = newTopic.DateLearned.AddSeconds(-newTopic.DateLearned.Second); var userId = _userManager.GetUserId(HttpContext.User); User user = await _userManager.FindByIdAsync(userId); _scheduler.Schedule(newTopic, user.RepeatIntervals); await _topicRepository.Add(newTopic); return(RedirectToAction(nameof(Topic), new { topicId = newTopic.Id })); } else { return(NotFound()); } }
public ServiceResult <TopicServiceResultCode> AddTopic(AddOrUpdateTopicRequest request) { var isValidRequest = ValidateAddTopicRequest(request); if (!isValidRequest) { return(ArgumentErrorResult(TopicServiceResultCode.ArgumentError)); } var topic = new Topic { Id = Guid.NewGuid(), CourseId = request.CourseId, Title = request.Title, DisplayOrder = request.DisplayOrder }; try { _topicRepo.Add(topic); _topicRepo.SaveChanges(); return(BuildResult(true, TopicServiceResultCode.Success, resultObj: topic)); } catch (Exception ex) { _systemErrorsRepo.AddLog(ex); return(InternalErrorResult(TopicServiceResultCode.BackendException)); } }
public void CreateTopic(string TopicName) { var topic = new Topic { TopicName = TopicName }; _repository.Add(topic); _repository.Save(); }
public IActionResult Index(Topic topic) { if (ModelState.IsValid) { topic.CreateOn = DateTime.Now; topic.Type = TopicType.Normal; TopicRepository.Add(topic); } return(RedirectToAction("Index")); }
/// <summary> /// Create a new topic and also the topic starter post /// </summary> /// <param name="topic"></param> /// <returns></returns> public Topic Add(Topic topic) { topic = SanitizeTopic(topic); topic.CreateDate = DateTime.UtcNow; // url slug generator topic.Slug = ServiceHelpers.GenerateSlug(topic.Name, x => _topicRepository.GetTopicBySlugLike(ServiceHelpers.CreateUrl(topic.Name))); return(_topicRepository.Add(topic)); }
public async Task <IActionResult> Create(Topic topic) { try { await _repository.Add(topic); } catch { return(StatusCode(500)); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> CreateTopic([FromBody] TopicForCreateDto topicForCreateDto) { var userId = int.Parse(HttpContext.GetUserIdFromToken()); var count = _repository.Count(t => t.OwnerId == userId || t.OwnerId == null); if (count >= Constants.MaxUserTopics) { return(BadRequest(new { Message = "User already has too much topics" })); } var topic = _mapper.Map <Topic>(topicForCreateDto); topic.OwnerId = userId; await _repository.Add(topic); await _repository.SaveChangesAsync(); var topicDto = _mapper.Map <TopicDto>(topic); return(CreatedAtAction(nameof(GetTopic), new { id = topic.Id }, topicForCreateDto)); }
public async Task <IActionResult> CreateAsync([FromBody] Topic input) { if (await _topicRepository.Exists(input.Name, input.ClusterId)) { return(Conflict(new { Message = "Topic already exists." })); } await _topicRepository.Add(input, input.ClusterId); return(Ok(input)); }
public ActionResult Create(TopicViewModel topic) { if (ModelState.IsValid) { topic.CreatorId = userRepository .GetUserByUsername(User.Identity.Name) .UserId; topic.CreationDate = DateTime.Now; repository.Add(topic.ToOrm()); int addedTopicId = repository.Topics .Where(x => x.Name == topic.Name && x.CreatorId == topic.CreatorId) .ToList().OrderBy(x => x.Creation_date).Last().TopicId; return(RedirectToRoute(new { controller = "Topic", Action = "Topic", id = addedTopicId, page = 1 })); } return(View(topic)); }
public MessageReport Create(Topic topic) { var rp = new MessageReport(); try { _ITopicRepository.Add(topic); rp.Success = true; rp.Message = "Thêm chủ đề thành công!"; } catch (Exception ex) { rp.Message = ex.Message; } return(rp); }
public void AddTopic(BllTopic topic) { topic.Date = DateTime.Now; topic.Status = new BllStatus() { Id = (int)StatusEnum.Raw }; try { topicRepository.Add(topic.ToDalTopic()); } catch (InvalidOperationException e) { logger.Warn(e.Message); throw; } }
// Topic public void Handle(AddTopicCommand message) { var topic = new Topic(message.UserId, message.CategoryId, message.Title, message.Description); if (!topic.IsValid()) { NotifyErrors(topic.ValidationResult); return; } // Validar se o usuario pode criar tópico _topicRepository.Add(topic); if (Commit()) { // Notificar successo _bus.RaiseEvent(new AddedTopicEvent(topic.Id, topic.UserId, topic.CategoryId, topic.Title, topic.Description, topic.Created, topic.Active, topic.Removed)); } }
//consider changing the out parameter to a validation type object public void Save(ITopic topic, out bool success) { Checks.Argument.IsNotNull(topic, "topic"); success = false; if (null == _repo.FindByTopicId(topic.TopicId)) { try { _repo.Add(topic); success = true; } catch (Exception ex) { success = false; } } }
public async Task <TopicDTO> AddTopic(TopicDTO model, string operatorId) { var now = DateTime.Now; var count = _topicRepository.GetFiltered(o => o.OrganizationId == model.OrganizationId && (o.EndDate == null || o.EndDate >= now)).Count(); if (count >= 3) { throw new Exception("商户最多发布3条主题。"); } if (!string.IsNullOrEmpty(model?.Address?.StreetAddress)) { var lonLat = await _amapProxy.Geo(model.Address.StreetAddress); model.Address.Longitude = lonLat?.Longitude ?? 0; model.Address.Latitude = lonLat?.Latitude ?? 0; } var obj = TopicFactory.CreateInstance( model.Title, model.FaceImageUrl, model.Introduction, model.IsCustom, model.CustomTopicUrl, model.OrganizationId, model.Address.Province, model.Address.City, model.Address.Area, model.Address.StreetAddress, model.Address.Postcode, model.Address.Latitude, model.Address.Longitude, operatorId, model.CreatorName, model.CreatorPortraitUrl, model.StartDate, model.EndDate, model.Category ); _topicRepository.Add(obj); if (model.ContentImages != null && model.ContentImages.Count() > 0) { var i = 0; foreach (var img in model.ContentImages) { i++; _topicImageRepository.Add(new TopicImage { ImageId = img.ImageId, ImageUrl = img.ImageUrl, TopicId = obj.Id, Order = i }); } } _dbUnitOfWork.Commit(); return(new TopicDTO { Address = obj.Address, Category = obj.Category, ContentImages = model.ContentImages.Select(item => new TopicImageDTO { ImageId = item.ImageId, ImageUrl = item.ImageUrl, TopicId = obj.Id }).ToList(), CreatedBy = obj.CreatedBy, CreatedOn = obj.CreatedOn, CustomTopicUrl = obj.CustomTopicUrl, EndDate = obj.EndDate, FaceImageUrl = obj.FaceImageUrl, Introduction = obj.Introduction, IsCustom = obj.IsCustom, IsSuspend = obj.IsSuspend, LastUpdBy = obj.LastUpdBy, LastUpdOn = obj.LastUpdOn, OrganizationId = obj.OrganizationId, StartDate = obj.StartDate, Title = obj.Title, Id = obj.Id, CreatorName = obj.CreatorName, CreatorPortraitUrl = obj.CreatorPortraitUrl }); }
public void UpdateUser(User user, bool updateNavigationProperties = false) { if (user == null) { throw new ArgumentNullException(); } var userToUpdate = GetUserById(user.UserId); if (userToUpdate == null) { throw new ArgumentException ($"User with Id = {user.UserId} does not exists"); } userToUpdate.Image = user.Image ?? userToUpdate.Image; userToUpdate.Reputation = user.Reputation ?? userToUpdate.Reputation; userToUpdate.Username = user.Username ?? userToUpdate.Username; userToUpdate.E_mail = user.E_mail ?? userToUpdate.E_mail; if (updateNavigationProperties) { userToUpdate.RoleId = user.RoleId; foreach (Topic topic in user.Topics) { Topic topicOrm = topicRepository.GetById(topic.TopicId); if (topicOrm == null) { topicRepository.Add(topic); } else { topicRepository.Update(topic); } } foreach (Message message in user.Messages) { Message messageOrm = messageRepository.GetById(message.MessageId); if (messageOrm == null) { messageRepository.Add(message); } else { messageRepository.Update(message); } } foreach (SectionModerator moderationInfoEntry in user.SectionModerators) { SectionModerator moderationInfoEntryCurrent = sectionModeratorsRepository .GetByPrimaryKey(moderationInfoEntry.SectionId, moderationInfoEntry.UserId); if (moderationInfoEntryCurrent == null) { sectionModeratorsRepository.Add(moderationInfoEntry); } else { sectionModeratorsRepository.Update(moderationInfoEntry); } } } ctx.Entry(userToUpdate).State = EntityState.Modified; ctx.SaveChanges(); }
public void CreateTopic(Topics Topic) { TopicRepository.Add(Topic); }
public Topic Add(Topic param) { _topicRepository.Add(param); return(param); }
public void Create(Topic topic) { _topicRepository.Add(topic); }