List <SitemapItem> ISitemapProvider.GetItems() { var moduleMaterials = AppCore.Get <ModuleMaterials>(); using (var db = new DB.DataLayerContext()) { var news = (from p in db.News orderby p.name ascending where p.status select p).ToList(); var pages = (from p in db.Pages orderby p.name ascending where p.status > 0 select p).ToList(); var items = news.OfType <ItemBase>().Union(pages.OfType <ItemBase>()).OfType <IItemRouted>(); //items.ForEach(item => item.OwnerModule = moduleMaterials); return(items.Select(x => new SitemapItem() { Location = x.Url, LastModificationTime = (x as ItemBase).DateChangeBase >= DateTime.MinValue ? (DateTime?)((x as ItemBase).DateChangeBase) : null }).ToList()); } }
public ActionResult ViewNews(int?IdNews = null) { if (!IdNews.HasValue || IdNews.Value <= 0) { throw new Exception("Не указан номер новости."); } using (var db = new DB.DataLayerContext()) { var data = db.News.Where(x => x.id == IdNews.Value).FirstOrDefault(); if (data == null) { throw new Exception("Указанная новость не найдена."); } if (data.Block) { if (AppCore.GetUserContextManager().GetCurrentUserContext().IsSuperuser) { throw new Exception("Указанная новость удалена (сообщение для суперпользователя)."); } else { throw new Exception("Указанная новость не найдена."); } } return(View("News.cshtml", data)); } }
public ActionResult ViewNewsAll() { using (var db = new DB.DataLayerContext()) { var data = db.News.Where(x => !x.Block).OrderByDescending(x => x.date).ToList(); return(View("NewsList.cshtml", data)); } }
public DB.Page getPageByID(int IdPage) { try { using (var db = new DB.DataLayerContext()) { return((from p in db.Pages where p.id == IdPage select p).FirstOrDefault()); } } catch (Exception ex) { Debug.Logs(ex.Message); return(null); } }
public ActionResult News() { using (var db = new DB.DataLayerContext()) { var showDeleted = Request.Form.GetValues("ShowDeleted")?.Contains("true") ?? false; var query = db.News.AsQueryable(); if (!showDeleted) { query = query.Where(x => !x.Block); } var model = query.OrderByDescending(x => x.date).ToList(); return(View("Admin/NewsList.cshtml", model)); } }
public ActionResult NewsDelete(int?IdNews = null) { var success = false; var result = ""; try { if (!IdNews.HasValue || IdNews.Value <= 0) { throw new Exception("Не указан номер новости."); } using (var db = new DB.DataLayerContext()) { var data = db.News.Where(x => x.id == IdNews.Value).FirstOrDefault(); if (data == null) { throw new Exception("Указанная новость не найдена."); } if (data.Block) { if (AppCore.GetUserContextManager().GetCurrentUserContext().IsSuperuser) { throw new Exception("Указанная новость удалена (сообщение для суперпользователя)."); } else { throw new Exception("Указанная новость не найдена."); } } data.Block = true; db.SaveChanges(); } success = true; //result = "Меню было успешно удалено."; } catch (Exception ex) { success = false; result = ex.Message; } return(ReturnJson(success, result)); }
public ActionResult NewsEdit(int?IdNews = null) { var success = false; var result = ""; try { DB.News data = null; if (!IdNews.HasValue || IdNews.Value <= 0) { data = new DB.News(); } else { using (var db = new DB.DataLayerContext()) { data = db.News.Where(x => x.id == IdNews.Value).FirstOrDefault(); } if (data == null) { throw new Exception("Указанная новость не найдена."); } if (data.Block) { if (AppCore.GetUserContextManager().GetCurrentUserContext().IsSuperuser) { throw new Exception("Указанная новость удалена (сообщение для суперпользователя)."); } else { throw new Exception("Указанная новость не найдена."); } } } return(View("Admin/NewsEdit.cshtml", data)); } catch (Exception ex) { success = false; result = ex.Message; } return(ReturnJson(success, result)); }
public IList <DB.Page> getPagesList() { try { using (var db = new DB.DataLayerContext()) { return((from p in db.Pages where p.status > 0 orderby p.name ascending select p).ToList()); } } catch (Exception ex) { Debug.Logs(ex.Message); return(null); } }
public JsonResult NewsSave(Models.NewsSave model = null) { var answer = JsonAnswer <int>(); try { if (ModelState.IsValid) { using (var db = new DB.DataLayerContext()) { DB.News data = null; if (model.IdMaterial <= 0) { data = new DB.News() { date = DateTime.Now, user = AppCore.GetUserContextManager().GetCurrentUserContext().IdUser, status = true, Block = false }; db.News.Add(data); } else { data = db.News.Where(x => x.id == model.IdMaterial).FirstOrDefault(); if (data == null) { throw new Exception("Указанная новость не найдена."); } if (data.Block) { if (AppCore.GetUserContextManager().GetCurrentUserContext().IsSuperuser) { throw new Exception("Указанная новость удалена (сообщение для суперпользователя)."); } else { throw new Exception("Указанная новость не найдена."); } } } data.name = model.NameMaterial; data.text = model.BodyFull; data.short_text = model.BodyShort; db.SaveChanges(); answer.Data = data.id; var result = AppCore.Get <UrlManager>().Register( Module, data.id, ItemTypeFactory.GetItemType(typeof(DB.News)).IdItemType, nameof(ModuleController.ViewNews), new List <ActionArgument>() { new ActionArgument() { ArgumentName = "IdNews", ArgumentValue = data.id } }, "news/" + UrlManager.Translate(data.name), RoutingConstants.MAINKEY ); if (!result.IsSuccess) { throw new Exception(result.Message); } answer.FromSuccess("Новость сохранена"); } } } catch (Exception ex) { answer.FromException(ex); Module.RegisterEvent(EventType.Error, "Ошибка сохранения новости", "Модель данных, переданная из формы:\r\n" + Newtonsoft.Json.JsonConvert.SerializeObject(model), null, ex); } return(ReturnJson(answer)); }