Beispiel #1
0
        public async Task <ActionResult> Add([FromBody] News news)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ApiResponse {
                    Status = false, ModelState = ModelState
                }));
            }

            try
            {
                var addedNews = await newsService.Add(news);

                if (news == null)
                {
                    return(BadRequest(new ApiResponse {
                        Status = false, ModelState = ModelState
                    }));
                }
                return(CreatedAtRoute("GetNewsRoute", new { id = news.id },
                                      new ApiResponse {
                    Status = true, News = news
                }));
            }
            catch
            {
                return(BadRequest(new ApiResponse {
                    Status = false
                }));
            }
        }
 public IActionResult PublishNews()
 {
     try
     {
         string publishBy = Request.Form["account"];
         if (publishBy != "zhengwei")
         {
             throw new Exception("发布人有误!");
         }
         string title    = Request.Form["title"];
         string content  = Request.Form["content"];
         string newstype = Request.Form["newstype"];
         News   news     = new News();
         news.Title         = title;
         news.PublishedBy   = publishBy;
         news.PublishedTime = DateTime.Now;
         news.Content       = content;
         news.BrowsedTimes  = 1000;
         news.Type          = newstype;
         _newsService.Add(news);
     }
     catch (Exception ex)
     {
         throw new Exception("发布出错");
     }
     return(Content("OK"));
 }
Beispiel #3
0
        public async Task SendNews(NewsDto entity)
        {
            bool addNews = await newsService.Add(mapper.Map <News>(entity));

            if (addNews)
            {
                await Clients.All.SendAsync(HubConstants.SendNews, mapper.Map <NewsDto>(entity));
            }
        }
Beispiel #4
0
        public ActionResult Newses_Create([DataSourceRequest] DataSourceRequest request, News news)
        {
            if (ModelState.IsValid)
            {
                _newsService.Add(news);
            }

            return(Json(new[] { news }.ToDataSourceResult(request, ModelState)));
        }
Beispiel #5
0
 public ActionResult Create(News news)
 {
     if (ModelState.IsValid)
     {
         newsservice.Add(news);
         this.uow.SaveChanges();
         return(RedirectToAction("IndexAdmin", "News"));
     }
     return(View(news));
 }
 public IActionResult Create(NewsViewModel model)
 {
     model.DateOfPost = DateTime.Now;
     if (ModelState.IsValid)
     {
         _newsService.Add(model);
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Beispiel #7
0
 public ActionResult Add(News News)
 {
     if (NewsService.Add(News))
     {
         return(Redirect("News"));
     }
     else
     {
         return(Content("no"));
     }
 }
Beispiel #8
0
        public ActionResult Create(News news, HttpPostedFileBase NewsImage, HttpPostedFileBase[] newsGalleryPost, string tags)
        {
            if (ModelState.IsValid)
            {
                news.UserId    = _userService.GetUserByIdentity(User.Identity.Name).UserId;
                news.NewsImage = "no-photo.jpg";
                if (NewsImage != null)
                {
                    news.NewsImage = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(NewsImage.FileName);
                    NewsImage.SaveAs(Server.MapPath("/Content/Upload/NewsImages/Images/") + news.NewsImage);
                    //---------------------resize Images ----------------------
                    InsertShowImage.ImageResizer img = new InsertShowImage.ImageResizer(150);
                    img.Resize(Server.MapPath("/Content/Upload/NewsImages/Images/") + news.NewsImage, Server.MapPath("/Content/Upload/NewsImages/thumbnail/") + news.NewsImage);
                }

                //------------Create Gallery Product --------------
                if (newsGalleryPost[0] != null && newsGalleryPost.Any())
                {
                    foreach (HttpPostedFileBase file in newsGalleryPost)
                    {
                        string galleryname = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName);
                        file.SaveAs(Server.MapPath("/Content/Upload/NewsImages/Images/" + galleryname));
                        //---------------------resize Images  for Gallery----------------------
                        InsertShowImage.ImageResizer img = new InsertShowImage.ImageResizer(350);
                        img.Resize(Server.MapPath("/Content/Upload/NewsImages/Images/") + galleryname, Server.MapPath("/Content/Upload/NewsImages/thumbnail/") + galleryname);
                        news.NewsGallery.Add(new NewsGallery()
                        {
                            NewsId    = news.NewsId,
                            ImageName = galleryname
                        });
                    }
                }

                //-------------------Tags---------------------
                if (!string.IsNullOrEmpty(tags))
                {
                    string[] tag = tags.Split('-');
                    foreach (string t in tag)
                    {
                        news.NewsTag.Add(new NewsTag()
                        {
                            NewsId    = news.NewsId,
                            TagsTitle = t.Trim()
                        });
                    }
                }
                _newsService.Add(news);
                return(RedirectToAction("Index"));
            }

            ViewBag.NewsGroupId = new SelectList(_newsGroupService.NewsGroups(), "NewsGroupId", "GroupTitle", news.NewsGroupId);
            return(View(news));
        }
Beispiel #9
0
 public IActionResult Create(int id, NewsViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         viewModel.Updated = viewModel.Created;
         var currentUser = userManager.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
         viewModel.AuthorId = currentUser.Id;
         newsService.Add(viewModel);
         return(RedirectToAction("Index"));
     }
     PopPopulateLists(viewModel);
     return(View(viewModel));
 }
        public async Task <ActionResult> Add(NewsViewModel newsModel)
        {
            var news = new DomainClasses.News()
            {
                Title       = newsModel.Title,
                Body        = newsModel.Body.ToSafeHtml(),
                CreatedDate = DateTime.Now
            };

            _newsService.Add(news);

            await _dbContext.SaveChangesAsync();

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Beispiel #11
0
 public ActionResult Post(News news)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest());
         }
         _context.Add(news);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
        public ActionResult Create(newsViewModels item, HttpPostedFileBase idFile, HttpPostedFileBase idFilee)
        {
            if (ModelState.IsValid)
            {
                //upload de l'image

                //   var path = Path.Combine(Server.MapPath("~/Content/img"), idFile.FileName);
                //  idFile.SaveAs(path);
                //  g.link_imgg = "img\\"+idFile.FileName;
                // g.link_img= "img\\" + idFilee.FileName;
                string uniqueName = Guid.NewGuid().ToString() +
                                    System.IO.Path.GetExtension(idFile.FileName);
                var uploadUrl = Server.MapPath("~/Content/img");

                idFile.SaveAs(Path.Combine(uploadUrl, uniqueName));


                string uniqueNamee = Guid.NewGuid().ToString() +
                                     System.IO.Path.GetExtension(idFilee.FileName);
                var uploadUrll = Server.MapPath("~/Content/img");

                idFilee.SaveAs(Path.Combine(uploadUrll, uniqueNamee));

                item.link_imgg = "img\\" + uniqueName;
                item.link_img  = "img\\" + uniqueNamee;
                item.DTYPE     = "news";
                item.date      = DateTime.UtcNow;
                // artSer.AddGames(g);

                news n = new news()
                {
                    idArticle   = item.idArticle,
                    name        = item.name,
                    description = item.description,
                    link_imgg   = item.link_imgg,
                    link_img    = item.link_img,
                    DTYPE       = item.DTYPE,
                    date        = item.date,
                };
                artSer.Add(n);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
Beispiel #13
0
 public ActionResult NewsCreate(News model, HttpPostedFileBase Image)
 {
     if (ModelState.IsValid)
     {
         if (Image != null)
         {
             WebImage img      = new WebImage(Image.InputStream);
             FileInfo fotoInfo = new FileInfo(Image.FileName);
             string   newFoto  = Guid.NewGuid().ToString() + fotoInfo.Extension;
             img.Resize(1080, 720);
             img.Save("~/Areas/Admin/Uploads/NewsFoto/" + newFoto);
             model.Image = "/Areas/Admin/Uploads/NewsFoto/" + newFoto;
         }
     }
     model.Date = DateTime.Now;
     _newsService.Add(model);
     return(RedirectToAction("News", "News"));
 }
Beispiel #14
0
        public GameDetails SetManagerName(string managerName)
        {
            var game = GetCurrentGame();

            game.ManagerName = managerName;
            Update(game);
            GameCache.CurrentSeasonId = game.CurrentSeasonId;

            var newsText = managerName + " has become manager of " + _teamService.GetTeamName(game.TeamId);

            _newsService.Add(new News
            {
                TeamId        = game.TeamId,
                GameDetailsId = game.Id,
                SeasonId      = game.CurrentSeasonId,
                NewsText      = newsText
            });

            return(game);
        }
Beispiel #15
0
        public async Task <IActionResult> Add(NewsRequestResourceModel newsRequestResourceModel)
        {
            try
            {
                var newsId = await _newsService.Add(newsRequestResourceModel.Title,
                                                    newsRequestResourceModel.ContentParagraph,
                                                    newsRequestResourceModel.NewsDate,
                                                    newsRequestResourceModel.Section,
                                                    newsRequestResourceModel.Author,
                                                    newsRequestResourceModel.Position);



                return(StatusCode((int)HttpStatusCode.Created, new { Message = "News was created successfully.", NewsId = newsId }));
            }
            catch (EntityException e)
            {
                return(StatusCode((int)HttpStatusCode.UnprocessableEntity, new { e.Message, e.Code, Field = e.Field.ToLower() }));
            }
        }
        public ActionResult Create([Bind(Include = "NewsID,NewsTitle,NewsContent,NewsPhoto")] News news, Picture picture)
        {
            if (ModelState.IsValid)
            {
                var fileName     = "";
                var physicalPath = "";
                var relativePath = "";
                if (picture.File != null && picture.File.ContentLength > 0)
                {
                    relativePath = "~/Content/images/news/" + Path.GetFileName(picture.File.FileName);
                    physicalPath = Server.MapPath(relativePath);
                    picture.File.SaveAs(physicalPath);
                }

                news.NewsPhoto = relativePath + fileName;
                _newsService.Add(news);
            }

            return(RedirectToAction("Index"));
        }
Beispiel #17
0
        public async Task <IActionResult> Create(CreateOrUpdateViewModel createViewModel)
        {
            if (createViewModel.image != null)
            {
                var fileName   = Path.GetFileName(createViewModel.image.FileName);
                var filePath   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\", fileName);
                var dbFilePath = Path.Combine("\\images\\", fileName);
                var fileStream = new FileStream(filePath, FileMode.Create);
                using (fileStream)
                {
                    await createViewModel.image.CopyToAsync(fileStream);
                }
                createViewModel.news.Imagepath = dbFilePath;
            }

            createViewModel.news.CreatedOn = DateTime.Now;
            createViewModel.news.AuthorId  = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            _newsService.Add(createViewModel.news);

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #18
0
 public ActionResult add(NewsAddViewModel _model)
 {
     if (ModelState.IsValid)
     {
         News news = new News()
         {
             CreateTime = DateTime.Now,
             Title      = _model.Title,
             Type       = _model.Type,
             Contents   = _model.Contents
         };
         news = newsBll.Add(news);
         if (news.Id > 0)
         {
             return(RedirectToAction("list"));
         }
         else
         {
             ModelState.AddModelError("", "添加失败!");
         }
     }
     return(View());
 }
Beispiel #19
0
 public void AddNews(NewsDetailDto news)
 {
     _newsService.Add(news);
 }
 public IActionResult AddNew([FromBody] News input)
 {
     _newsService.Add(input);
     return(Ok());
 }