/// <summary> /// Удаление эл-та меню /// </summary> /// <param name="id"></param> /// <returns></returns> public override bool deleteCmsMenu(Guid id) { using (var db = new CMSdb(_context)) { using (var tran = db.BeginTransaction()) { string logTitle = db.cms_menus.Where(w => w.id == id).First().c_title; int Num = db.cms_menus.Where(w => w.id == id).ToArray().First().n_permit; string Group = db.cms_menus.Where(w => w.id == id).ToArray().First().f_group; db.cms_menus .Where(w => w.n_permit > Num && w.f_group == Group) .Set(p => p.n_permit, p => p.n_permit - 1) .Update(); db.cms_menus.Where(w => w.id == id).Delete(); // логирование var log = new LogModel() { Site = _domain, Section = LogSection.CmsMenu, Action = LogAction.delete, PageId = id, PageName = logTitle, UserId = _currentUserId, IP = _ip, }; insertLog(log); tran.Commit(); return(true); } } }
public bool UpdateNewsCategory(NewsCategoryModel category) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { InsertLog(new LogModel { PageId = category.Id, PageName = category.Name, Section = LogModule.NewsCategory, Action = LogAction.update }); var q = db.core_material_categories.Where(w => w.id == category.Id && w.f_site == _siteId); if (q.Any()) { q .Set(s => s.c_name, category.Name) .Set(s => s.c_alias, category.Alias) .Update(); tr.Commit(); return(true); } return(false); } } }
/// <summary> /// удаляет новости /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DeleteNews(Guid id) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var q = db.core_materials.Where(w => w.gid == id && w.f_site == _siteId); if (q.Any()) { var news = q.Single(); InsertLog(new LogModel { PageId = id, PageName = news.c_title, Comment = "Удалена новость" + String.Format("{0}/", news.c_title), Section = LogModule.News, Action = LogAction.delete, }, news); q.Delete(); tr.Commit(); return(true); } return(false); } } }
public bool AddAnswer(AnswerModel answer) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { int sort = 0; var q = db.vote_answers.Where(w => w.f_vote == answer.ParentId).Select(s => s.n_sort); if (q.Any()) { sort = q.Max(); } sort++; db.vote_answers.Insert(() => new vote_answers { c_variant = answer.Variant, f_vote = answer.ParentId, n_sort = sort }); tr.Commit(); } return(true); } }
public override bool delPhotoItem(Guid id) { using (var db = new CMSdb(_context)) { using (var tran = db.BeginTransaction()) { var data = db.content_photoss.Where(w => w.id == id); if (data.Any()) { Guid AlbumId = data.Single().f_album; int ThisSort = data.Single().n_sort; // удаление фотографии data.Delete(); //корректировка порядка db.content_photoss .Where(w => (w.f_album == AlbumId && w.n_sort > ThisSort)) .Set(u => u.n_sort, u => u.n_sort - 1) .Update(); tran.Commit(); return(true); } return(false); } } }
/// <summary> /// Удаляет фотоальбом /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DeletePhotoAlbum(Guid id) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { bool result = false; var album = db.core_photo_albums.Where(w => w.id == id).SingleOrDefault(); if (album != null) { var log = new LogModel { PageId = id, PageName = album.c_title, Section = LogModule.PhotoAlbums, Action = LogAction.delete }; InsertLog(log, album); result = db.Delete(album) > 0; } tr.Commit(); return(result); } } }
public bool InsertVote(VoteModel vote) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { InsertLog(new LogModel { PageId = vote.Id, PageName = vote.Title, Section = LogModule.Vote, Action = LogAction.insert }); db.vote_vote .Insert( () => new vote_vote { id = vote.Id, c_title = vote.Title, c_text = vote.Text, d_date_start = vote.DateStart, d_date_end = vote.DateEnd, b_type_multi = vote.TypeMulti, b_disabled = vote.Disabled, b_important = vote.Important, f_site = _siteId }); tr.Commit(); return(true); } } }
/// <summary> /// Обновляет данные по продукту /// </summary> /// <param name="item"></param> /// <returns></returns> public override bool updateProduct(ProductModel item) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { bool result = db.content_productss .Where(w => w.id.Equals(item.Id)) .Set(s => s.c_title, item.Title) .Set(s => s.c_code, item.Code) .Set(s => s.c_barcode, item.Barcode) .Set(s => s.c_description, item.Description) .Set(s => s.c_keyword, item.Keyword) .Set(s => s.n_count, item.Count) .Set(s => s.c_photo, item.Photo) .Set(s => s.d_date, item.Date) //.Set(s => s.c_standart, item.Standart) .Set(s => s.m_price, item.Price) .Update() > 0; dbUpdateProductCategories(db, item.Id, item.CategoriesIds); tr.Commit(); return(result); } } }
/// <summary> /// Добавляет новый продукт /// </summary> /// <param name="item"></param> /// <returns></returns> public override bool insertProduct(ProductModel item) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { bool result = db.content_productss .Value(v => v.id, item.Id) .Value(v => v.c_title, item.Title) .Value(v => v.c_code, item.Code) .Value(v => v.c_barcode, item.Barcode) .Value(v => v.c_description, item.Description) .Value(v => v.c_keyword, item.Keyword) .Value(v => v.c_photo, item.Photo) .Value(v => v.n_count, item.Count) .Value(v => v.m_price, item.Price) .Value(v => v.d_date, item.Date) //.Value(v => v.c_standart, item.Standart) .Insert() > 0; dbUpdateProductCategories(db, item.Id, item.Categories.Select(s => s.Id).ToArray()); tr.Commit(); return(result); } } }
/// <summary> /// Добавляет запись о шаблоне /// </summary> /// <param name="template"></param> /// <returns></returns> public bool InsertTemplate(TemplateModel template) { using (var db = new CMSdb(_context)) { using (var tran = db.BeginTransaction()) { var cdTemplate = new core_views() { id = template.Id, c_name = template.Title, c_desc = template.Desc, c_path = template.ViewPath, c_img = template.Image, f_controller = Guid.Empty }; db.Insert(cdTemplate); var log = new LogModel() { PageId = Guid.NewGuid(), PageName = template.Title, Section = LogModule.Templates, Action = LogAction.insert }; InsertLog(log); tran.Commit(); return true; } } }
/// <summary> /// Удаляет шаблон /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DeleteTemplate(Guid id) { using (var db = new CMSdb(_context)) { using (var tran = db.BeginTransaction()) { var data = db.core_views .Where(s => s.id == id); if (data.Any()) { var cdTemplate = data.Single(); db.Delete(cdTemplate); var log = new LogModel() { PageId = id, PageName = String.Format("{0} ({1})", cdTemplate.c_name, cdTemplate.c_path), Section = LogModule.Modules, Action = LogAction.delete }; InsertLog(log); tran.Commit(); return true; } return false; } } }
/// <summary> /// Удаление записи /// </summary> /// <param name="item"></param> /// <returns></returns> public bool DeleteCartProduct(Guid id) { using (var db = new CMSdb(_context)) { using (var tran = db.BeginTransaction()) { var data = db.cart_products .Where(s => s.id == id); if (data.Any()) { var product = data.Single(); //Логирование var log = new LogModel() { PageId = product.id, PageName = product.c_title, Section = LogModule.Cart, Action = LogAction.update, Comment = "Изменена категория" }; InsertLog(log); db.Delete(product); tran.Commit(); return(true); } return(false); } } }
/// <summary> /// Изменяет пароль пользователя сайта /// </summary> /// <param name="id"></param> /// <param name="salt"></param> /// <param name="hash"></param> public override void ChangePasswordUserSite(Guid id, string salt, string hash) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var user = db.content_userss.Where(w => w.id == id); if (user.Any()) { string userName = user.Select(s => string.Format("{0} {1}", s.c_surname, s.c_name)) .SingleOrDefault(); user.Set(p => p.c_salt, salt) .Set(p => p.c_hash, hash) .Update(); // логирование var log = new LogModel() { Site = _domain, Section = LogSection.Users, Action = LogAction.change_pass, PageId = id, PageName = userName, UserId = _currentUserId, IP = _ip, }; insertLog(log); tr.Commit(); } } } }
/// <summary> /// Удаление пользователя /// </summary> /// <param name="id"></param> /// <param name="UserId"></param> /// <param name="IP"></param> /// <returns></returns> public override bool deleteUser(Guid id) { using (var db = new CMSdb(_context)) { using (var tran = db.BeginTransaction()) { var user = db.cms_userss.Where(w => w.id == id); if (user.Any()) { string userName = user.Select(s => string.Format("{0} {1}", s.c_surname, s.c_name)) .SingleOrDefault(); user.Delete(); // логирование //insertLog(UserId, IP, "delete", id, String.Empty, "Users", logTitle); var log = new LogModel() { Site = _domain, Section = LogSection.Users, Action = LogAction.delete, PageId = id, PageName = userName, UserId = _currentUserId, IP = _ip, }; insertLog(log); tran.Commit(); return(true); } return(false); } } }
/// <summary> /// Добавляет фотоальбом /// </summary> /// <param name="album"></param> /// <returns></returns> public bool InsertPhotoAlbum(PhotoAlbumModel album) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var log = new LogModel { PageId = album.Id, PageName = album.Title, Section = LogModule.PhotoAlbums, Action = LogAction.insert }; InsertLog(log); bool result = db.core_photo_albums.Insert(() => new core_photo_albums { id = album.Id, c_title = album.Title, c_preview = album.Preview, c_text = album.Text, d_date = album.Date, b_disabled = album.Disabled, f_site = _siteId }) > 0; tr.Commit(); return(result); } } }
/// <summary> /// Удаляет связь пользователя с ЛС /// </summary> /// <param name="id"></param> /// <param name="user"></param> /// <returns></returns> public bool DropUserSubscr(Guid id, Guid user) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var query = db.lk_user_subscrs .Where(w => w.f_subscr == id) .Where(w => w.f_user == user); var link = query.SingleOrDefault(); bool result = query.Delete() > 0; if (link.b_default) { var newDefault = db.lk_user_subscrs .Where(w => w.f_user == user) .FirstOrDefault(); if (newDefault != null) { result = db.lk_user_subscrs .Where(w => w.f_user == user) .Where(w => w.f_subscr == newDefault.f_subscr) .Set(s => s.b_default, true) .Update() > 0; } } tr.Commit(); return(result); } } }
/// <summary> /// Обновляет фотоальбом /// </summary> /// <param name="album"></param> /// <returns></returns> public bool UpdatePhotoAlbum(PhotoAlbumModel album) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var log = new LogModel { PageId = album.Id, PageName = album.Title, Section = LogModule.PhotoAlbums, Action = LogAction.update }; InsertLog(log); bool result = db.core_photo_albums .Where(w => w.id == album.Id) .Set(s => s.c_title, album.Title) .Set(s => s.c_preview, album.Preview) .Set(s => s.c_text, album.Text) .Set(s => s.d_date, album.Date) .Set(s => s.b_disabled, album.Disabled) .Update() > 0; tr.Commit(); return(result); } } }
/// <summary> /// Выставляет дефолтный ЛС для пользователя /// </summary> /// <param name="subscr"></param> /// <param name="user"></param> /// <returns></returns> public bool SetDefaultUserSubscrLink(Guid subscr, Guid user) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var query = db.lk_user_subscrs .Where(w => w.f_user == user); if (query.Any()) { var result = query .Set(s => s.b_default, false) .Update(); var res = query .Where(w => w.f_subscr == subscr) .Set(s => s.b_default, true) .Update(); tr.Commit(); return(true); } return(false); } } }
/// <summary> /// Удаляет изображение /// </summary> /// <param name="id"></param> /// <returns></returns> public PhotoCoreModel DeletePhoto(Guid id) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var photo = db.core_photos.Where(w => w.id == id).SingleOrDefault(); var log = new LogModel { PageId = id, PageName = photo.c_title, Section = LogModule.Photos, Action = LogAction.delete }; InsertLog(log, photo); bool success = db.Delete(photo) > 0; tr.Commit(); if (success) { return(new PhotoCoreModel { Id = id, Album = photo.f_album, Title = photo.c_title }); } return(null); } } }
/// <summary> /// Удаляет лицевой счёт /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DeleteSubscr(Guid id) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var item = db.lk_subscrs .Where(w => w.id == id) .SingleOrDefault(); if (item != null) { var log = new LogModel { PageId = id, PageName = $"{item.c_name}", Section = LogModule.Subscrs, Action = LogAction.delete }; InsertLog(log, item); db.Delete(item); tr.Commit(); return(true); } return(false); } } }
public bool DeleteVote(Guid id) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var query = db.vote_vote.Where(w => w.id == id && w.f_site == _siteId); if (query.Any()) { InsertLog(new LogModel { PageId = query.Single().id, PageName = query.Single().c_title, Section = LogModule.Vote, Action = LogAction.delete }, query.Single()); query.Delete(); tr.Commit(); return(true); } else { return(false); } } } }
/// <summary> /// Добавляет подразделение /// </summary> /// <param name="item"></param> /// <returns></returns> public bool InsertDepartment(DepartmentModel item) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var log = new LogModel { PageId = item.Id, PageName = item.Title, Section = LogModule.Departments, Action = LogAction.insert }; InsertLog(log); bool result = db.lk_departments.Insert(() => new lk_departments { id = item.Id, c_title = item.Title, c_address = item.Address, c_work_time = item.WorkTime, n_longitude = (decimal)item.Longitude, n_latitude = (decimal)item.Latitude, b_disabled = item.Disabled, f_site = _siteId }) > 0; tr.Commit(); return(result); } } }
/// <summary> /// изьменение порядка вариантов ответов /// </summary> /// <param name="id"></param> /// <param name="new_num"></param> /// <returns></returns> public bool ChangePositionAnswer(Guid id, int new_num) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var query_answer = db.vote_answers.Where(w => w.id == id); Guid Parent = query_answer.Single().f_vote; int actual_num = query_answer.Single().n_sort; if (new_num != actual_num) { if (new_num > actual_num) { db.vote_answers.Where(w => w.f_vote == Parent && w.n_sort > actual_num && w.n_sort <= new_num) .Set(p => p.n_sort, p => p.n_sort - 1) .Update(); } else { var q = db.vote_answers.Where(w => w.f_vote == Parent && w.n_sort < actual_num && w.n_sort >= new_num); q.Set(p => p.n_sort, p => p.n_sort + 1) .Update(); } db.vote_answers.Where(w => w.id == id).Set(s => s.n_sort, new_num).Update(); } tr.Commit(); } } return(true); }
/// <summary> /// Обновляет подразделение /// </summary> /// <param name="item"></param> /// <returns></returns> public bool UpdateDepartment(DepartmentModel item) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var log = new LogModel { PageId = item.Id, PageName = item.Title, Section = LogModule.Departments, Action = LogAction.update }; InsertLog(log); bool result = db.lk_departments .Where(w => w.id == item.Id) .Set(s => s.c_title, item.Title) .Set(s => s.c_address, item.Address) .Set(s => s.c_work_time, item.WorkTime) .Set(s => s.n_longitude, (decimal)item.Longitude) .Set(s => s.n_latitude, (decimal)item.Latitude) .Set(s => s.b_disabled, item.Disabled) .Update() > 0; tr.Commit(); return(result); } } }
/// <summary> /// удаление события /// </summary> /// <param name="Guid"></param> /// <returns></returns> public bool DeleteEvent(Guid Guid) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var q = db.event_events.Where(w => w.gid == Guid && w.f_site == _siteId); if (q.Any()) { var events = q.Single(); InsertLog(new LogModel { PageId = Guid, PageName = events.c_title, Comment = "Удалено событие" + String.Format("{0}/", events.c_title), Section = LogModule.Events, Action = LogAction.delete, }, events); q.Delete(); tr.Commit(); return(true); } return(false); } } }
/// <summary> /// Удаляет подразделение /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DeleteDepartment(Guid id) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { bool result = false; var item = db.lk_departments.Where(w => w.id == id).SingleOrDefault(); if (item != null) { var log = new LogModel { PageId = id, PageName = item.c_title, Section = LogModule.Departments, Action = LogAction.delete }; InsertLog(log, item); result = db.Delete(item) > 0; } tr.Commit(); return(result); } } }
public bool DeleteNewsCategory(Guid id) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var q = db.core_material_categories.Where(w => w.id == id && w.f_site == _siteId); if (q.Any()) { var data = q.Single(); InsertLog(new LogModel { PageId = id, PageName = data.c_name, Section = LogModule.NewsCategory, Action = LogAction.delete, Comment = "Удалена категория новостей" + String.Format("{0}/{1}", data.c_name, data.c_alias), }, data); //смещаем n_sort db.core_material_categories .Where(w => w.f_site == _siteId && w.n_sort > data.n_sort) .Set(p => p.n_sort, p => p.n_sort - 1) .Update(); tr.Commit(); q.Delete(); return(true); } return(false); } } }
/// <summary> /// удалят ветку сообщений из одной темы /// </summary> /// <param name="Guid"></param> /// <returns></returns> public bool DeleteMessages(Guid Guid) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { var q = db.msg_messages.Where(w => w.id == Guid && w.f_site == _siteId); if (q.Any()) { var msg = q.Single(); db.msg_messages.Where(w => w.f_parent == Guid).Delete(); InsertLog(new LogModel { PageId = Guid, PageName = msg.c_theme, Comment = "Удалено сообщение" + String.Format("{0}/", msg.c_theme), Section = LogModule.Messages, Action = LogAction.delete, }, msg); q.Delete(); tr.Commit(); return(true); } return(false); } } }
public bool InsertNewsCaetegory(NewsCategoryModel category) { using (var db = new CMSdb(_context)) { using (var tr = db.BeginTransaction()) { InsertLog(new LogModel { PageId = category.Id, PageName = category.Name, Section = LogModule.NewsCategory, Action = LogAction.update }); int sort = 1; var q = db.core_material_categories.Where(w => w.f_site == _siteId); if (q.Any()) { sort = q.Select(s => s.n_sort).Max() + 1; } bool result = db.core_material_categories .Insert(() => new core_material_categories { c_alias = category.Alias, c_name = category.Name, n_sort = sort, f_site = _siteId }) > 0; tr.Commit(); return(result); } } }
/// <summary> /// Добавляем меню в карту сайта /// </summary> /// <param name="item">Элемент карты сайта</param> /// <returns></returns> public override bool deleteSiteMapMenu(Guid id) { using (var db = new CMSdb(_context)) { using (var tran = db.BeginTransaction()) { var query = db.content_sitemap_menuss.Where(w => w.id == id); if (query.Any()) { var siteMapMenuItem = query.SingleOrDefault(); var log = new LogModel() { Site = _domain, Section = LogSection.SiteMap, Action = LogAction.delete, PageId = id, PageName = siteMapMenuItem.c_title + "(" + siteMapMenuItem.c_alias + ")", UserId = _currentUserId, IP = _ip, }; insertLog(log); db.Delete(siteMapMenuItem); } tran.Commit(); return(true); } } }