public IActionResult Seed() { try { _newsRepository.ClearAll(); } catch (Exception e) { return(BadRequest("Gick inte att tömma databasen.")); } try { _newsRepository.Add(new NewsArticle() { Title = "Title1", Header = "Header1", Body = "Body1" }); _newsRepository.Add(new NewsArticle() { Title = "Title1", Header = "Header2", Body = "Body2" }); } catch (Exception e) { return(BadRequest("Gick inte att seeda.")); } return(Ok("Reseedat databasen.")); }
public async Task <News> AddNews(NewsDto news) { var newNews = _newsRepository.Add(news); await _context.SaveChangesAsync(); return(newNews); }
public async Task <int> Add(News news) { newsRepository.Add(news); var res = await newsRepository.Save(); return(res); }
public IActionResult Add([FromBody] News news) { if (news == null) { return(BadRequest("News is null")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } news.CreatedDate = DateTime.Now; news.UpdatedDate = DateTime.Now; if (news.Category?.Id != null) { Category c = _categoryRepository.GetById((int)news.Category.Id); news.Category = c; } // Förhindra att ny kategori skapas om ingen anges if (news.Category?.Id == null) { news.Category = null; } _newsRepository.Add(news); return(Ok(news.Id)); }
public void Add(News model) { var entity = NewsFactory.Create(model); _newsRepository.Add(entity); model.Id = entity.Id; }
public IActionResult Add([FromBody] AddNewsViewModel newsItem) { if (newsItem == null) { return(BadRequest("News is null")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } newsItem.News.CreatedDate = DateTime.Now; newsItem.News.UpdatedDate = DateTime.Now; if (newsItem.News.Category?.Id != null) { Category c = _categoryRepository.GetById((int)newsItem.News.Category.Id); newsItem.News.Category = c; } // Förhindra att ny kategori skapas om ingen anges if (newsItem.News.Category?.Id == null) { newsItem.News.Category = null; } //creates all tags and the connection between tags and news News thisNews = _newsRepository.Add(newsItem.News); foreach (var tag in newsItem.Tags) { if (tag.Id == 0) { var newTag = _tagRepository.Create(tag); var tagConnection = new NewsTag { News = thisNews, NewsId = thisNews.Id, Tag = newTag, TagId = newTag.Id }; thisNews.NewsTags.Add(tagConnection); } else { var alreadyAddedTag = _tagRepository.GetById(tag.Id); var tagConnection = new NewsTag { News = thisNews, NewsId = thisNews.Id, Tag = alreadyAddedTag }; thisNews.NewsTags.Add(tagConnection); } } //updates the news to add the connection between tags and this news _newsRepository.Update(thisNews); return(Ok()); }
public async Task Add(NewsVM newsVM) { var news = _mapper.Map <News>(newsVM); news.CreateDate = DateTime.Now; await _newsRepository.Add(news); await _context.SaveChangesAsync(); }
public ActionResult Create(News news) { if (ModelState.IsValid) { _repo.Add(news); return(RedirectToAction("Index")); } return(View(news)); }
public IActionResult Create([FromBody] News news) { if (news == null) { return(BadRequest()); } news = _newsRepository.Add(news); return(CreatedAtRoute(RouteName.GetNews, new { id = news.Id }, news)); }
public IActionResult Add(News news) { if (!ModelState.IsValid) { return(View(news)); } news.Created = DateTime.Now; _newsRepository.Add(news); return(RedirectToAction(MethodNames.INDEX)); }
public bool AddNews(News news) { if (newsRepository.FindByName(news.Name) == null) { newsRepository.Add(news); return(true); } else { return(false); } }
public void NewsRepository_AddTest_InValidNews() { INewsRepository newsRepository = IoCFactory.Instance.CurrentContainer.Resolve <INewsRepository>(); News news = new News() { Title = null, Summary = "", //Image = "test Image" }; newsRepository.Add(news); newsRepository.UnitOfWork.CommitAndRefreshChanges(); }
public ActionResult NewsCreate(News n) { try { newsRepository.Add(n); return(RedirectToAction("NewsIndex")); } catch { return(View()); } }
public async Task <NewsResponse> AddNewsAsync(AddNewsRequest request) { if (request == null) { throw new ArgumentNullException(); } var news = _mapper.Map <Entities.News>(request); var result = _newsRepository.Add(news); await _newsRepository.UnitOfWork.SaveChangesAsync(); var response = _mapper.Map <NewsResponse>(result); return(response); }
public ActionResult Add(News model, string close) { try { var news = newsRepository.FindByTitle(model.MetaTitle); if (news != null) { return(Json(new { IsSuccess = false, Message = "Tiêu đề tin tức đã tồn tại", }, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(model.Image)) { return(Json(new { IsSuccess = false, Message = "Vui lòng thêm ảnh đại diện bài viết", }, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(model.Contents)) { return(Json(new { IsSuccess = false, Message = "Vui lòng thêm nội dung bài viết", }, JsonRequestBehavior.AllowGet)); } model.CreatedBy = User.ID; newsRepository.Add(model); return(Json(new { Close = close, IsSuccess = true, Message = "Thêm mới thành công" }, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new { IsSuccess = false, Message = "Thêm mới thất bại " }, JsonRequestBehavior.AllowGet)); } }
public void NewsRepository_AddTest_ValidNews() { INewsRepository newsRepository = IoCFactory.Instance.CurrentContainer.Resolve <INewsRepository>(); newsRepository.UnitOfWork.RollbackChanges(); News news1 = new News() { Id = new Guid("1cd1ae08-8e48-c902-0147-08d1ca79fb6a"), Title = "test title", Summary = "test Texte" }; //news1.Image = "test Image"; newsRepository.Add(news1); newsRepository.UnitOfWork.Commit(); News byId = newsRepository.GetElementById(news1.Id); Assert.IsNotNull((object)byId); Assert.IsTrue(byId.Id == news1.Id); }
public ActionResult Add(News model, string close) { try { var news = newsRepository.GetAll().FirstOrDefault(x => x.MetaTitle.Trim().Equals(model.MetaTitle.Trim())); if (news != null) { return(Json(new { IsSuccess = true, Message = "Tiêu đề tin tức đã tồn tại", }, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(model.Contents)) { return(Json(new { IsSuccess = false, Message = "Vui lòng thêm nội dung bài viết", }, JsonRequestBehavior.AllowGet)); } model.LinkSeo = HelperString.RenderLinkSeo(model.MetaTitle); model.CreatedBy = User.ID; model.CreatedDate = DateTime.Now; newsRepository.Add(model); return(Json(new { Close = close, IsSuccess = true, Message = "Thêm mới thành công" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { IsSuccess = false, Message = "Thêm mới thất bại " }, JsonRequestBehavior.AllowGet)); } }
public IActionResult AddNews(AddNewsModel newsModel) { if (ModelState.IsValid) { var model = new News() { Title = newsModel.Title, Content = newsModel.Content, PublishDate = newsModel.PublishDate }; if (newsModel?.File?.Length > 0) { using (var ms = new MemoryStream()) { newsModel.File.CopyTo(ms); var fileBytes = ms.ToArray(); model.File = Convert.ToBase64String(fileBytes); } } var newNews = _newsRepository.Add(model); if (newsModel.SelectedCategory != null) { foreach (var item in newsModel.SelectedCategory) { _newsCategoryRepository.Add(new NewsCategory { NewsId = newNews.Id, CategoryId = item }); } } if (newsModel.SelectedKeyword != null) { foreach (var item in newsModel.SelectedKeyword) { _newsKeywordRepository.Add(new NewsKeyword { NewsId = newNews.Id, KeywordId = item }); } } if (newsModel.SelectedPlace != null) { foreach (var item in newsModel.SelectedPlace) { _newsPublishPlaceRepository.Add(new NewsPublishPlace { NewsId = newNews.Id, PlaceId = item }); } } return(RedirectToAction("List")); } return(View(newsModel)); }
public int CreatNews(News news) { return(_newrepo.Add(news)); }
public void AddNews(NewsDto newsDto) { newsDto.CreateTime = DateTime.Now; _newsRepository.Add(QsMapper.CreateMap <NewsDto, News>(newsDto)); _newsRepository.UnitOfWork.Commit(); }
public News Add(News entity) { return(_news.Add(entity)); }
public void AddNews(ParticularNewsModel news) { var newsEntity = Mapper.Map <ParticularNewsIntoBoardEntity>(news); _newsRepository.Add(newsEntity); }
public int AddNews(DLModel.News news) { return(_newsRepository.Add((DLModel.News) new DLModel.News().InjectFrom(news)).NewsID); }
public async Task <News> Add(News news) { return(await newsRepository.Add(news)); }
// POST api/<controller> public void Post([FromBody] News value) { _repository.Add(value); _repository.Save(); }
public async Task Execute(News news) { await _newsRepository.Add(news); }
public IActionResult GetTestMongAdd([FromBody] News entity) { _newsGatewayRepository.Add(entity); return(Ok("DONE")); }
public void Add(News news) { _newsRepository.Add(news); }
protected override void CreateInitialData() { _newsRepository = Locator.GetService<INewsRepository>(); var news = new[] { new News { Date = new DateTime(2010,1,1), Title = "News 1", ShortDescription = "News 1" }, new News { Date = new DateTime(2012,10,10), Title = "News 2", ShortDescription = "News 2" }, new News { Date = DateTime.Now, Title = "News 3", ShortDescription = "News 3" }, new News { Date = DateTime.Now, Title = "News 4", ShortDescription = "News 4" } }; foreach (var obj in news) { _newsRepository.Add(obj); } }
public bool SubmitNews(News news) { _newsRepository.Add(news); return(true); }