Beispiel #1
0
 public ActionResult Create(RssSource rssSource)
 {
     if (ControllerContext.HttpContext.Request.IsAjaxRequest())
     {
         if (ModelState.IsValid)
         {
             repository.Add(rssSource);
             var result = new HandlerResult {
                 IsSuccess = true, Message = "添加RSS源成功"
             };
             return(Json(result));
         }
         else
         {
             var result = new HandlerResult {
                 IsSuccess = false, Message = "添加RSS源失败"
             };
             return(Json(result));
         }
     }
     else
     {
         if (ModelState.IsValid)
         {
             var flag = repository.Add(rssSource);
             return(Redirect("Index"));
         }
         else
         {
             return(View(rssSource));
         }
     }
 }
        public int AddRssSource(string title, string url)
        {
            if (string.IsNullOrEmpty(title))
            {
                throw new AddRssSourceTitleRequiredException();
            }

            if (!(Uri.TryCreate(url, UriKind.Absolute, out var uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps)))
            {
                throw new AddRssSourceUrlRequiredException();
            }

            var rssSource = new RssSource
            {
                Title     = title,
                Url       = url,
                CreatedAt = DateTime.Now
            };

            return(rssSourceRepository.Add(rssSource));
        }