Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
        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());
            }
        }
Ejemplo n.º 4
0
        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));
            }
        }
Ejemplo n.º 5
0
        public void CreateTopic(string TopicName)
        {
            var topic = new Topic
            {
                TopicName = TopicName
            };

            _repository.Add(topic);
            _repository.Save();
        }
Ejemplo n.º 6
0
 public IActionResult Index(Topic topic)
 {
     if (ModelState.IsValid)
     {
         topic.CreateOn = DateTime.Now;
         topic.Type     = TopicType.Normal;
         TopicRepository.Add(topic);
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 7
0
        /// <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));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create(Topic topic)
        {
            try
            {
                await _repository.Add(topic);
            }
            catch
            {
                return(StatusCode(500));
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
        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));
        }
Ejemplo n.º 11
0
 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));
 }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 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;
     }
 }
Ejemplo n.º 14
0
        // 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));
            }
        }
Ejemplo n.º 15
0
        //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;
                }
            }
        }
Ejemplo n.º 16
0
        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
            });
        }
Ejemplo n.º 17
0
        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();
        }
Ejemplo n.º 18
0
 public void CreateTopic(Topics Topic)
 {
     TopicRepository.Add(Topic);
 }
Ejemplo n.º 19
0
 public Topic Add(Topic param)
 {
     _topicRepository.Add(param);
     return(param);
 }
Ejemplo n.º 20
0
 public void Create(Topic topic)
 {
     _topicRepository.Add(topic);
 }