public ActionResult CreateEditStar(CreateUpdateStarInput input)
 {
     if (!ModelState.IsValid)
     {
         throw new UserFriendlyException("你提交的表单有误!");
     }
     _starService.CreateStar(input);
     return RedirectToAction("Index");
 }
Exemple #2
0
        public void CreateStar(CreateUpdateStarInput input)
        {
            Logger.Info("添加明星的输入信息(CreateUpdateStarInput对象): " + input);

            var star = new Star
            {
                Name = input.Name,
                Nickname = input.Nickname,
                ChineseName = input.ChineseName,
                Gender = input.Gender,
                Description = input.Description,
                IsBlocked = false,//添加明星默认不屏蔽
                CreationTime = DateTime.Now,
                LastUpdateTime = DateTime.Now,

            };
            //添加该明星对应的首个博客(一个明星对应多个博客,在创建明星时只能添加一个博客,创建完之后才可以增加更多)
            _starRepository.Insert(star);
            _unitOfWorkManager.Current.SaveChanges();
            var blog = new Blog
            {
                Url = input.BlogUrl,
                CreationTime = DateTime.Now,
                LastUpdateTime = DateTime.Now,
                StarId = star.Id,
            };
            blog.ResolveUrl(input.BlogUrl);
            var sameBlog = _blogRepository.GetAll().Where(b => b.Name == blog.Name).Where(b => b.Provider == blog.Provider);
            if (sameBlog.Count() > 0)
            {
                //保证微博地址在数据库中的唯一性,爬虫就不会重复下载博文
                //抛出异常后上面_starRepository.Insert(star)的操作会被回滚
                throw new UserFriendlyException("你添加的微博" + input.BlogUrl + "已经存在,不能重复添加");

            }
            else
            {
                _blogRepository.Insert(blog);
            }
        }
Exemple #3
0
        public void UpdateStar(CreateUpdateStarInput input)
        {
            //Logger.Info("Updating a star for input: " + input);

            var star = _starRepository.Get(input.Id);
            star.Gender = input.Gender;
            star.ChineseName = input.ChineseName;
            star.Nickname = input.Nickname;
            star.Name = input.Name;
            star.Description = input.Description;
            star.LastUpdateTime = DateTime.Now;
            //star.IsBlocked = input.IsBlocked;//编辑明星时也可以进行屏蔽操作,暂不搞

        }