Esempio n. 1
0
        public JsonResult Add(TopicViewModel topic)
        {
            bool result = false;

            result = topicService.AddTopic(topic);
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        private void Submit_Click(object sender, RoutedEventArgs e)
        {
            List <WordViewModel> words = new List <WordViewModel>();

            if (StackOfWords.Children.Count == 0)
            {
                MessageBox.Show("Can't save empty topic!");
                return;
            }
            if (TopicName.Text == String.Empty)
            {
                MessageBox.Show("Can't save nameless topic!");
                return;
            }

            foreach (WordToAdd word in StackOfWords.Children)
            {
                if (word.English == String.Empty || word.Ukrainian == String.Empty)
                {
                    MessageBox.Show("Can't have empty fields");
                    return;
                }
                WordViewModel wordViewModel = new WordViewModel(word.English, word.Ukrainian);
                words.Add(wordViewModel);
            }

            List <WordDTO> wordDTOs = new List <WordDTO>();

            foreach (var item in words)
            {
                wordDTOs.Add(Mapper.MapWordDTO(item));
            }
            _topicService.AddTopic(wordDTOs, TopicName.Text, 1);
            this.Close();
        }
Esempio n. 3
0
 public ActionResult CreateTopic(CreateEditTopicModel topic)
 {
     if (ModelState.IsValid)
     {
         BllTopic bllTopic = topic.ToBllTopic();
         bllTopic.Author = userService.GetUser(User.Identity.Name);
         topicService.AddTopic(bllTopic);
         return(RedirectToAction("Topics"));
     }
     return(View(topic));
 }
        /// <summary>
        /// 添加或修改专题
        /// </summary>
        /// <param name="topicId"></param>
        /// <param name="title"></param>
        /// <param name="tags"></param>
        /// <returns></returns>
        private long AddOrUpdateTopic(long topicId, string title, string tags, string icon, PlatformType platform)
        {
            long result = 0;
            long shopid = CurrentSellerManager.ShopId;

            if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(tags))
            {
                throw new HimallException("请填写专题的标题与标签");
            }
            if (string.IsNullOrWhiteSpace(icon))
            {
                throw new HimallException("请上传专题的图标");
            }
            TopicInfo topic = new TopicInfo();

            if (topicId > 0)
            {
                topic = _iTopicService.GetTopicInfo(topicId);
                if (topic == null || topic.ShopId != shopid)
                {
                    throw new HimallException("错误的专题编号");
                }
                topic.Name     = title;
                topic.Tags     = tags;
                topic.TopImage = icon;
                topic.PlatForm = platform;
                topic.ShopId   = shopid;
                _iTopicService.UpdateTopic(topic);
            }
            else
            {
                topic.Name     = title;
                topic.Tags     = tags;
                topic.TopImage = icon;
                topic.PlatForm = platform;
                topic.ShopId   = shopid;
                _iTopicService.AddTopic(topic);
                topicId = topic.Id;
            }
            result = topicId;
            if (result <= 0)
            {
                throw new HimallException("数据添加异常");
            }
            return(result);
        }
Esempio n. 5
0
        public JsonResult Add(string topicJson)
        {
            var s = new Newtonsoft.Json.JsonSerializerSettings();

            s.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
            s.NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore;
            var topic = Newtonsoft.Json.JsonConvert.DeserializeObject <Topic>(topicJson, s);

            if (string.IsNullOrWhiteSpace(topic.Name))
            {
                return(Json(new { success = false, msg = "专题名不可为空" }));
            }
            topic.Name = topic.Name.Trim();
            if (string.IsNullOrWhiteSpace(topic.Tags))
            {
                return(Json(new { success = false, msg = "标签不可为空" }));
            }
            foreach (var item in topic.TopicModuleInfo)
            {
                if (string.IsNullOrWhiteSpace(item.Name))
                {
                    return(Json(new { success = false, msg = "错误的模块名" }));
                }
            }
            topic.Tags = topic.Tags.Trim();
            var oriTopic = TopicApplication.GetTopic(topic.Id);

            topic.Platform        = PlatformType.Mobile;
            topic.ShopId          = CurrentSellerManager.ShopId;
            topic.BackgroundImage = oriTopic == null ? string.Empty : oriTopic.BackgroundImage;
            topic.FrontCoverImage = oriTopic == null ? string.Empty : oriTopic.FrontCoverImage;


            if (topic.Id > 0)
            {
                _iTopicService.UpdateTopic(topic);
            }
            else
            {
                _iTopicService.AddTopic(topic);
            }

            return(Json(new { success = true }));
        }
Esempio n. 6
0
        public async Task <IActionResult> Post([FromBody] TopicModel model)
        {
            var logger = new LoggerConfiguration()
                         .WriteTo.Sentry(_configuration.GetConnectionString("SENTRY"))
                         .WriteTo.Console()
                         .Enrich.FromLogContext()
                         .CreateLogger();

            try
            {
                logger.Information("Запрос на добавление темы");
                await _topicService.AddTopic(model.ToEntity());

                return(StatusCode(StatusCodes.Status201Created));
            }
            catch (Exception e)
            {
                logger.Error(e, "Произошла ошибка");
                return(StatusCode(StatusCodes.Status500InternalServerError, "Произошла ошибка, обратитесь в службу поддержки!"));
            }
        }
Esempio n. 7
0
        public JsonResult Add(string topicJson)
        {
            var s = new Newtonsoft.Json.JsonSerializerSettings();

            s.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
            s.NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore;
            Model.TopicInfo topic = Newtonsoft.Json.JsonConvert.DeserializeObject <Model.TopicInfo>(topicJson, s);
            if (topic.TopicModuleInfo.Count == 0)
            {
                return(Json(new { success = false, msg = "至少需要录入1个模块!" }));
            }

            if (topic.Id > 0)
            {
                _iTopicService.UpdateTopic(topic);
            }
            else
            {
                _iTopicService.AddTopic(topic);
            }

            return(Json(new { success = true }));
        }
Esempio n. 8
0
        public JsonResult Add(string topicJson)
        {
            var s = new Newtonsoft.Json.JsonSerializerSettings();

            s.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
            s.NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore;
            Model.TopicInfo topic    = Newtonsoft.Json.JsonConvert.DeserializeObject <Model.TopicInfo>(topicJson, s);
            var             oriTopic = _iTopicService.GetTopicInfo(topic.Id);

            topic.PlatForm        = PlatformType.Mobile;
            topic.BackgroundImage = oriTopic == null ? string.Empty : oriTopic.BackgroundImage;
            topic.FrontCoverImage = oriTopic == null ? string.Empty : oriTopic.FrontCoverImage;

            if (topic.Id == 0)
            {
                _iTopicService.AddTopic(topic);
            }
            else
            {
                _iTopicService.UpdateTopic(topic);
            }

            return(Json(new { success = true }));
        }
Esempio n. 9
0
        private void AddTopic(string[] args)
        {
            if (!IsAutorize())
            {
                PrintError(NotAutorizedError);
                return;
            }

            Sections(null);

            var topic = new BllTopic
            {
                Section = new BllSection {
                    Id = ReadInt("Section")
                },
                Title  = ReadString("Title"),
                Text   = ReadString("Text"),
                Author = me,
            };

            topicService.AddTopic(topic);

            MyTopics(null);
        }
Esempio n. 10
0
 public async Task <IActionResult> AddTopic(TopicDto topicDto)
 {
     return(await Create(nameof(AddTopic), async() => await _topicService.AddTopic(User.Identity.GetUserId(), topicDto)));
 }
Esempio n. 11
0
        public async Task <ActionResult <int> > InsertTopic([FromBody] PostTopicRequest model)
        {
            var rs = await _topicService.AddTopic(model.Name, model.Description, model.NameEng, model.DescriptionEng, model.Image, model.StartDate, model.Username);

            return(Ok(rs));
        }
Esempio n. 12
0
 public void Post([FromBody] Topic topic)
 {
     _service.AddTopic(topic);
 }