Exemple #1
0
        /// <summary>
        /// Manage user group
        /// </summary>
        /// <param name="operation">the operation</param>
        /// <param name="model">the user group model</param>
        /// <returns></returns>
        public ResponseModel ManageNews(GridOperationEnums operation, NewsModel model)
        {
            IEnumerable<int> categoryIds;
            ResponseModel response;
            Mapper.CreateMap<NewsModel, EntityModel.News>();
            EntityModel.News news;
            switch (operation)
            {
                case GridOperationEnums.Edit:
                    news = _newsRepository.GetById(model.Id);
                    news.Title = model.Title;
                    news.Status = model.Status;
                    news.IsHotNews = model.IsHotNews;
                    response = Update(news);
                    categoryIds = model.Categories.Split(',').Select(int.Parse).ToList();
                    var currentCategories = news.NewsNewsCategories.Select(nc => nc.Id).ToList();
                    foreach (var id in currentCategories)
                    {
                        if (!categoryIds.Contains(id))
                        {
                            _newsNewsCategoryRepository.Delete(id);
                        }
                    }
                    foreach (var categoryId in categoryIds)
                    {
                        if (currentCategories.All(n => n != categoryId))
                        {
                            var newsNewsCategory = new NewsNewsCategory
                            {
                                NewsId = news.Id,
                                NewsCategoryId = categoryId
                            };
                            _newsNewsCategoryRepository.Insert(newsNewsCategory);
                        }
                    }
                    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."));

                //case GridOperationEnums.Add:
                //    news = Mapper.Map<NewsModel, EntityModel.News>(model);
                //    categoryIds = model.Categories.Split(',').Select(int.Parse);
                //    news.Status = model.Status;
                //    news.Content = string.Empty;
                //    news.Description = string.Empty;
                //    news.Updated = DateTime.Now;
                //    news.UpdatedBy = WorkContext.CurrentUser.Email;
                //    response = Insert(news);
                //    foreach (var categoryId in categoryIds)
                //    {
                //        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:::Insert news failed. Please try again later."));

                case GridOperationEnums.Del:
                    news = _newsRepository.GetById(model.Id);
                    if (news != null)
                    {
                        foreach (var currentCategory in news.NewsNewsCategories)
                        {
                            _newsNewsCategoryRepository.Delete(currentCategory);
                        }
                        response = Delete(model.Id);
                        return response.SetMessage(response.Success ?
                            _localizedResourceServices.T("AdminModule:::News:::Messages:::DeleteSuccessfully:::Delete news successfully.")
                            : _localizedResourceServices.T("AdminModule:::News:::Messages:::DeleteFailure:::Delete news failed. Please try again later."));

                    }
                    break;
            }
            return new ResponseModel
            {
                Success = false,
                Message = _localizedResourceServices.T("AdminModule:::News:::Messages:::ObjectNotFounded:::News is not founded.")
            };
        }
Exemple #2
0
 public JsonResult Manage(NewsModel model, GridManagingModel manageModel)
 {
     return Json(_newsServices.ManageNews(manageModel.Operation, model));
 }