public NewsCurlyBracket(EntityModel.News news) { Id = news.Id; Title = news.Title; Description = news.Description; Content = news.Content; ImageUrl = news.ImageUrl; DetailsUrl = UrlUtilities.GenerateUrl(HttpContext.Current.Request.RequestContext, "News", "Details", new { id = news.Id, title = news.Title.ToUrlString() }); LastUpdate = news.Updated ?? news.Created; LastUpdatedBy = news.Updated.HasValue ? news.UpdatedBy : news.CreatedBy; RecordOrder = news.RecordOrder; Created = news.Created; CreatedBy = news.CreatedBy; Updated = news.Updated; UpdatedBy = news.UpdatedBy; var newsCategories = news.NewsNewsCategories.Select(nc => nc.NewsCategory).ToList(); Categories = newsCategories.Any() ? newsCategories.Select(c => new CategoryItemModel(c)).ToList() : new List <CategoryItemModel>(); }
/// <summary> /// Save news manage model /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveNewsManageModel(NewsManageModel model) { ResponseModel response; var news = GetById(model.Id); #region Edit News if (news != null) { news.Title = model.Title; news.Status = model.Status; news.Description = model.Description; news.Content = model.Content; news.ImageUrl = model.ImageUrl; news.IsHotNews = model.IsHotNews; var currentCategories = news.NewsNewsCategories.Select(nc => nc.NewsCategoryId).ToList(); foreach (var id in currentCategories) { if (!model.NewsCategoryIds.Contains(id)) { _newsNewsCategoryRepository.Delete(id); } } foreach (var categoryId in model.NewsCategoryIds) { if (currentCategories.All(n => n != categoryId)) { var newsNewsCategory = new NewsNewsCategory { NewsId = news.Id, NewsCategoryId = categoryId }; _newsNewsCategoryRepository.Insert(newsNewsCategory); } } //Get page record order response = Update(news); return response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::News:::Messages:::UpdateSuccessfully:::Update news successfully.") : _localizedResourceServices.T("AdminModule:::News:::Messages:::UpdateFailure:::Update news failed. Please try again later.")); } #endregion news = new EntityModel.News { Title = model.Title, Status = model.Status, Description = model.Description, Content = model.Content, ImageUrl = model.ImageUrl, IsHotNews = model.IsHotNews, Updated = DateTime.Now, UpdatedBy = WorkContext.CurrentUser.Email }; response = Insert(news); foreach (var categoryId in model.NewsCategoryIds) { var newsNewsCategory = new NewsNewsCategory { NewsId = news.Id, NewsCategoryId = categoryId }; _newsNewsCategoryRepository.Insert(newsNewsCategory); } return response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::News:::Messages:::CreateSuccessfully:::Create news successfully.") : _localizedResourceServices.T("AdminModule:::News:::Messages:::CreateFailure:::Create news failed. Please try again later.")); }
public ResponseModel Delete(EntityModel.News news) { return(_newsRepository.Delete(news)); }
public ResponseModel Update(EntityModel.News news) { return(_newsRepository.Update(news)); }
public ResponseModel Insert(EntityModel.News news) { return(_newsRepository.Insert(news)); }
/// <summary> /// Save news manage model /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveNewsManageModel(NewsManageModel model) { ResponseModel response; var news = GetById(model.Id); #region Edit News if (news != null) { news.Title = model.Title; news.Status = model.Status; news.Description = model.Description; news.Content = model.Content; news.ImageUrl = model.ImageUrl; news.IsHotNews = model.IsHotNews; var currentCategories = news.NewsNewsCategories.Select(nc => nc.NewsCategoryId).ToList(); foreach (var id in currentCategories) { if (!model.NewsCategoryIds.Contains(id)) { _newsNewsCategoryRepository.Delete(id); } } foreach (var categoryId in model.NewsCategoryIds) { if (currentCategories.All(n => n != categoryId)) { var newsNewsCategory = new NewsNewsCategory { NewsId = news.Id, NewsCategoryId = categoryId }; _newsNewsCategoryRepository.Insert(newsNewsCategory); } } //Get page record order response = Update(news); return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::News:::Messages:::UpdateSuccessfully:::Update news successfully.") : _localizedResourceServices.T("AdminModule:::News:::Messages:::UpdateFailure:::Update news failed. Please try again later."))); } #endregion news = new EntityModel.News { Title = model.Title, Status = model.Status, Description = model.Description, Content = model.Content, ImageUrl = model.ImageUrl, IsHotNews = model.IsHotNews, Updated = DateTime.Now, UpdatedBy = WorkContext.CurrentUser.Email }; response = Insert(news); foreach (var categoryId in model.NewsCategoryIds) { var newsNewsCategory = new NewsNewsCategory { NewsId = news.Id, NewsCategoryId = categoryId }; _newsNewsCategoryRepository.Insert(newsNewsCategory); } return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::News:::Messages:::CreateSuccessfully:::Create news successfully.") : _localizedResourceServices.T("AdminModule:::News:::Messages:::CreateFailure:::Create news failed. Please try again later."))); }