Exemplo n.º 1
0
        /// <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);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// проверка существования новости по идентифкатору
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool CheckNews(Guid id)
 {
     using (var db = new CMSdb(_context))
     {
         return(db.core_materials.Where(w => w.gid == id && w.f_site == _siteId).Any());
     }
 }
Exemplo n.º 3
0
 public bool ExistNewsCategory(Guid id)
 {
     using (var db = new CMSdb(_context))
     {
         return(db.core_material_categories.Where(w => w.f_site == _siteId && w.id == id).Any());
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// список событий которые можно подключить к новости
        /// </summary>
        /// <returns></returns>
        public EventModel[] GetLastEvents(Guid NewsId)
        {
            using (var db = new CMSdb(_context))
            {
                var q = db.event_events
                        .Where(w => w.f_site == _siteId);

                var AllEvents = db.event_events
                                .Where(w => w.f_site == _siteId).Select(s => s.gid);

                var SelectedEvents = db.event_events_material_link.Where(w => w.f_news == NewsId).Select(s => s.f_events).ToArray();
                var list           = new List <Guid>();
                foreach (var item in AllEvents)
                {
                    if (SelectedEvents != null && !SelectedEvents.Contains(item))
                    {
                        list.Add(item);
                    }
                }
                var EventsDropdownList = list.Join(db.event_events, m => m, n => n.gid, (m, n) => n).OrderByDescending(o => o.d_date).Take(500);
                if (EventsDropdownList.Any())
                {
                    return(EventsDropdownList.Select(s => new EventModel()
                    {
                        Title = s.c_title,
                        Guid = s.gid
                    }).ToArray());
                }
            }
            return(null);
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
        public override bool sortingPhotos(Guid id, int num)
        {
            using (var db = new CMSdb(_context))
            {
                var data = db.content_photoss.Where(w => w.id == id).Select(s => new PhotoModel {
                    AlbumId = s.f_album, Sort = s.n_sort
                }).First();
                var AlbumId = data.AlbumId;

                if (num > data.Sort)
                {
                    db.content_photoss.Where(w => w.f_album == AlbumId && w.n_sort > data.Sort && w.n_sort <= num)
                    .Set(p => p.n_sort, p => p.n_sort - 1)
                    .Update();
                }
                else
                {
                    db.content_photoss.Where(w => w.f_album == AlbumId && w.n_sort < data.Sort && w.n_sort >= num)
                    .Set(p => p.n_sort, p => p.n_sort + 1)
                    .Update();
                }
                db.content_photoss
                .Where(w => w.id == id)
                .Set(s => s.n_sort, num)
                .Update();
            }
            return(true);
        }
Exemplo n.º 7
0
 /// <summary>
 /// проверка существования события по идентифкатору
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool CheckEvets(Guid id)
 {
     using (var db = new CMSdb(_context))
     {
         return(db.event_events.Where(w => w.gid == id && w.f_site == _siteId).Any());
     }
 }
Exemplo n.º 8
0
        public override bool permit_Documents(Guid id, int num)
        {
            using (var db = new CMSdb(_context))
            {
                var data = db.content_documentss.Where(w => w.id == id).Select(s => new DocumentsModel {
                    idPage = s.id_page, Permit = s.n_sort
                }).First();
                var PageId = data.idPage;

                if (num > data.Permit)
                {
                    db.content_documentss.Where(w => w.id_page == PageId && w.n_sort > data.Permit && w.n_sort <= num)
                    .Set(p => p.n_sort, p => p.n_sort - 1)
                    .Update();
                }
                else
                {
                    db.content_documentss.Where(w => w.id_page == PageId && w.n_sort < data.Permit && w.n_sort >= num)
                    .Set(p => p.n_sort, p => p.n_sort + 1)
                    .Update();
                }
                db.content_documentss
                .Where(w => w.id == id)
                .Set(s => s.n_sort, num)
                .Update();
            }
            return(true);
        }
Exemplo n.º 9
0
        public override DocumentsModel[] getDocuments(Guid id)
        {
            using (var db = new CMSdb(_context))
            {
                var data = db.content_documentss.Where(w => w.id_page == id)
                           .OrderBy(o => o.n_sort)
                           .Select(s => new DocumentsModel
                {
                    id       = s.id,
                    Title    = s.c_title,
                    FilePath = s.c_file_path,
                    idPage   = s.id_page
                })

                ;
                if (!data.Any())
                {
                    return(null);
                }
                else
                {
                    return(data.ToArray());
                }
            }
        }
Exemplo n.º 10
0
        /// <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);
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Возвращает фотоальбом
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public PhotoAlbumModel GetPhotoAlbum(Guid id)
 {
     using (var db = new CMSdb(_context))
     {
         return(db.core_photo_albums
                .Where(w => w.id == id)
                .Select(s => new PhotoAlbumModel
         {
             Id = s.id,
             Title = s.c_title,
             Preview = s.c_preview,
             Text = s.c_text,
             Date = s.d_date,
             Disabled = s.b_disabled,
             Photos = s.fkphotosphotoalbumss
                      .OrderBy(o => o.n_sort)
                      .Select(p => new PhotoModel
             {
                 Id = p.id,
                 Preview = p.c_preview,
                 Sort = p.n_sort
             }).ToArray()
         }).SingleOrDefault());
     }
 }
Exemplo n.º 12
0
        /// <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);
                }
            }
        }
Exemplo n.º 13
0
        /// <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);
                }
            }
        }
Exemplo n.º 14
0
        /// <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);
                }
            }
        }
Exemplo n.º 15
0
 public bool ChechVote(Guid id)
 {
     using (var db = new CMSdb(_context))
     {
         return(db.vote_vote.Where(w => w.id == id).Any());
     }
 }
Exemplo n.º 16
0
        public override bool deleteSiteMapDocuments(Guid id)
        {
            using (var db = new CMSdb(_context))
            {
                var data = db.content_documentss.Where(w => w.id == id);
                if (data != null)
                {
                    //смещение пермитов
                    var ThisPageId = data.FirstOrDefault().id_page;
                    var ThisPermit = data.FirstOrDefault().n_sort;
                    db.content_documentss
                    .Where(w => w.id_page == ThisPageId && w.n_sort > ThisPermit)
                    .Set(p => p.n_sort, p => p.n_sort - 1)
                    .Update();

                    data
                    .Where(w => w.id == id)
                    .Delete();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 17
0
 public VoteModel GetVoteItem(Guid id)
 {
     using (var db = new CMSdb(_context))
     {
         var query = db.vote_vote.Where(w => w.id == id && w.f_site == _siteId);
         if (query.Any())
         {
             return(query.Select(s => new VoteModel {
                 Id = s.id,
                 Title = s.c_title,
                 Text = s.c_text,
                 DateEnd = s.d_date_end,
                 DateStart = s.d_date_start,
                 Important = s.b_important,
                 Disabled = s.b_disabled,
                 TypeMulti = s.b_type_multi,
                 List = s.fkids.OrderBy(o => o.n_sort).Select(a => new AnswerModel()
                 {
                     Id = a.id,
                     Variant = a.c_variant
                 }).ToList()
             }).Single());
         }
         return(null);
     }
 }
Exemplo n.º 18
0
 /// <summary>
 /// Получаем данные об пользователе по email или id
 /// </summary>
 /// <param name="Email"></param>
 /// <returns></returns>
 public override AccountModel getCmsAccount(string Email)
 {
     using (var db = new CMSdb(_context))
     {
         var data = db.cms_userss.
                    Where(w => w.c_email == Email).
                    Select(s => new AccountModel
         {
             id         = s.id,
             Mail       = s.c_email,
             Salt       = s.c_salt,
             Hash       = s.c_hash,
             Group      = s.f_group,
             Surname    = s.c_surname,
             Name       = s.c_name,
             Patronymic = s.c_patronymic,
             CountError = (s.n_error_count >= 5),
             LockDate   = s.d_try_login,
             Disabled   = s.b_disabled
         });
         if (!data.Any())
         {
             return(null);
         }
         else
         {
             return(data.First());
         }
     }
 }
Exemplo n.º 19
0
 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);
         }
     }
 }
Exemplo n.º 20
0
 public override AccountModel getCmsAccount(Guid Id)
 {
     using (var db = new CMSdb(_context))
     {
         var data = db.cms_userss.
                    Where(w => w.id == Id).
                    Select(s => new AccountModel
         {
             id         = s.id,
             Mail       = s.c_email,
             Salt       = s.c_salt,
             Hash       = s.c_hash,
             Group      = s.f_group,
             Surname    = s.c_surname,
             Name       = s.c_name,
             Patronymic = s.c_patronymic,
             Disabled   = s.b_disabled,
             GroupLvl   = s.fkusersgroup.n_level
         });
         if (!data.Any())
         {
             return(null);
         }
         else
         {
             return(data.First());
         }
     }
 }
Exemplo n.º 21
0
 /// <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);
         }
     }
 }
Exemplo n.º 22
0
        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);
                }
            }
        }
Exemplo n.º 23
0
 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);
         }
     }
 }
Exemplo n.º 24
0
        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);
                    }
                }
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// single news
 /// </summary>
 /// <param name="Guid"></param>
 /// <returns></returns>
 public NewsModel GetNewsItem(Guid Guid)
 {
     using (var db = new CMSdb(_context))
     {
         var query = db.core_materials.Where(w => w.gid == Guid);
         if (query.Any())
         {
             return(query.Select(s => new NewsModel {
                 Guid = s.gid,
                 Date = s.d_date,
                 Title = s.c_title,
                 Alias = s.c_alias,
                 Text = s.c_text,
                 Photo = s.c_photo,
                 Keyw = s.c_keyw,
                 Desc = s.c_desc,
                 SourceName = s.c_source_name,
                 SourceUrl = s.c_source_url,
                 Disabled = s.b_disabled,
                 Category = s.fkcategorieslinks.Select(ss => new NewsCategoryModel()
                 {
                     Id = ss.f_materials_category,
                     Name = ss.fkmaterialscategorieslinkfmk.c_name
                 }).ToArray(),
                 Important = s.b_important
             }).Single());
         }
         return(null);
     }
 }
Exemplo n.º 26
0
        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);
            }
        }
Exemplo n.º 27
0
 /// <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);
         }
     }
 }
Exemplo n.º 28
0
        /// <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);
        }
Exemplo n.º 29
0
 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);
         }
     }
 }
Exemplo n.º 30
0
 /// <summary>
 /// Определяет есть ли
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool CheckMessages(Guid id)
 {
     using (var db = new CMSdb(_context))
     {
         return(db.msg_messages.Where(w => w.id == id && w.f_site == _siteId).Any());
     }
 }