示例#1
0
        public int SaveOGraph(OGraphBinding OGraph, int SiteID, string UserID)
        {
            using (var _c = db)
            {
                if (OGraph != null)
                {
                    var _Model = new OGraph
                    {
                        OGraphDescription = OGraph.OGraphDescription,
                        OGraphTitle       = OGraph.OGraphTitle
                    };
                    if (OGraph.OGraphID == 0)
                    {
                        _c.OGraphs.Add(_Model);
                    }
                    else
                    {
                        _Model = _c.OGraphs.Where(m => m.OGraphID == OGraph.OGraphID).FirstOrDefault();
                        _Model.OGraphDescription = OGraph.OGraphDescription;
                        _Model.OGraphTitle       = OGraph.OGraphTitle;
                    }
                    _c.SaveChanges();

                    //ADDING MEDIA
                    if (OGraph.FileRead != null)
                    {
                        if (OGraph.FileRead.Deleting)
                        {
                            if (OGraph.FileRead.MediaID != 0)
                            {
                                new MediaBLL().DeleteMedia(OGraph.FileRead.MediaID, SiteID, UserID);
                            }
                        }
                        else
                        {
                            if (OGraph.FileRead != null && !string.IsNullOrEmpty(OGraph.FileRead.FileContent))
                            {
                                new MediaBLL().DeleteMedia(OGraph.FileRead.MediaID, SiteID, UserID);
                                var _Media = new MediaBLL().SaveImage(OGraph.FileRead, SiteID, UserID);
                                _c.OGraphMedias.Add(new OGraphMedia
                                {
                                    MediaID  = _Media.MediaID,
                                    OGraphID = _Model.OGraphID
                                });
                                _c.SaveChanges();
                            }
                        }
                    }
                    return(_Model.OGraphID);
                }
                return(0);
            }
        }
示例#2
0
        public int SaveOGraph(OGraphBinding OGraph, int SiteID, string UserID)
        {
            using (var _c = db)
            {
                if (OGraph != null)
                {
                    var _Model = new OGraph
                    {
                        OGraphDescription = OGraph.OGraphDescription,
                        OGraphTitle = OGraph.OGraphTitle
                    };
                    if (OGraph.OGraphID == 0)
                        _c.OGraphs.Add(_Model);
                    else
                    {
                        _Model = _c.OGraphs.Where(m => m.OGraphID == OGraph.OGraphID).FirstOrDefault();
                        _Model.OGraphDescription = OGraph.OGraphDescription;
                        _Model.OGraphTitle = OGraph.OGraphTitle;
                    }
                    _c.SaveChanges();

                    //ADDING MEDIA
                    if (OGraph.FileRead != null)
                    {
                        if (OGraph.FileRead.Deleting)
                        {
                            if (OGraph.FileRead.MediaID != 0)
                            {
                                new MediaBLL().DeleteMedia(OGraph.FileRead.MediaID, SiteID, UserID);
                            }
                        }
                        else
                        {
                            if (OGraph.FileRead != null && !string.IsNullOrEmpty(OGraph.FileRead.FileContent))
                            {
                                new MediaBLL().DeleteMedia(OGraph.FileRead.MediaID, SiteID, UserID);
                                var _Media = new MediaBLL().SaveImage(OGraph.FileRead, SiteID, UserID);
                                _c.OGraphMedias.Add(new OGraphMedia
                                {
                                    MediaID = _Media.MediaID,
                                    OGraphID = _Model.OGraphID
                                });
                                _c.SaveChanges();
                            }
                        }
                    }
                    return _Model.OGraphID;
                }
                return 0;
            }
        }
示例#3
0
        public int Save(BlogPostModelBinding Model, string UserID)
        {
            using (var _c = db)
            {
                Can(Model.SiteID, UserID, _c);
                var _BlogPost = new BlogPost(Model.SiteID);
                if (string.IsNullOrEmpty(Model.FriendlyUrl))
                    Model.FriendlyUrl = Model.Title.CleanUrl();
                if (Model.BlogPostID == 0)
                {
                    var _BlogPostCulture = new BlogPostCulture(Model);
                    _BlogPostCulture.DateCreated = DateTime.Now;
                    //ADD TAGS
                    if (Model.Tags != null)
                    {
                        _BlogPostCulture.BlogPostTags = new List<BlogPostTag>();
                        foreach (var item in Model.Tags)
                        {
                            var _BTID = GetTagID(item.BlogTagName);
                            _BlogPostCulture.BlogPostTags.Add(new BlogPostTag
                            {
                                BlogTagID = GetTagID(item.BlogTagName),
                                CultureID = Model.CultureID
                            });
                        }
                    }

                    _BlogPost.BlogPostCultures = new List<BlogPostCulture>();
                    _BlogPost.BlogPostCultures.Add(_BlogPostCulture);
                    _c.BlogPosts.Add(_BlogPost);

                    //CATEGORIES
                    if (Model.Categories != null)
                    {
                        _BlogPost.BlogPostCategories = new List<BlogPostCategory>();
                        foreach (var item in Model.Categories)
                        {
                            _BlogPost.BlogPostCategories.Add(new BlogPostCategory
                            {
                                BlogCategoryID = item.BlogCategoryID
                            });
                        }
                    }
                    _c.SaveChanges();
                    return _BlogPost.BlogPostID;
                }
                else
                {
                    var _BP = _c.BlogPostCultures
                        .Where(m => m.CultureID == Model.CultureID && m.BlogPostID == Model.BlogPostID)
                        .FirstOrDefault();
                    _BP.UpdateContent(Model);

                    //CATEGORIES
                    if (Model.Categories != null)
                    {
                        var _C = Model.Categories
                            .Where(m => m.Adding)
                            .Select(m => new BlogPostCategory
                            {
                                BlogCategoryID = m.BlogCategoryID,
                                BlogPostID = Model.BlogPostID
                            });
                        foreach (var item in _C.ToList())
                        {
                            if (!_c.BlogPostCategories
                                .Where(m => m.BlogCategoryID == item.BlogCategoryID
                                && m.BlogPostID == item.BlogPostID).Any())
                            {
                                _BP.BlogPost.BlogPostCategories.Add(item);
                            }
                        }
                        var _CToDelete = Model.Categories
                            .Where(m => m.Deleting).Select(m => m.BlogCategoryID);
                        _c.BlogPostCategories.RemoveRange(_c.BlogPostCategories
                            .Where(m => _CToDelete.Contains(m.BlogCategoryID))
                            .ToList());
                    }
                    //ADD TAGS
                    if (Model.Tags != null)
                    {
                        foreach (var item in Model.Tags)
                        {
                            var _BTID = GetTagID(item.BlogTagName);

                            var _BPT = _c.BlogPostTags
                                .Where(m => m.BlogTagID == _BTID
                            && m.BlogPostID == Model.BlogPostID
                            && m.CultureID == Model.CultureID)
                            .FirstOrDefault();

                            if (item.Adding && _BPT == null)
                            {
                                _BPT = new BlogPostTag(item, _BTID, Model.CultureID);
                                _BP.BlogPostTags.Add(_BPT);
                            }
                            else if (item.Deleting && _BPT != null)
                            {
                                _c.BlogPostTags.Remove(_BPT);
                            }

                        }
                    }
                    _c.SaveChanges();

                    int _BlogPostID = Model.BlogPostID != 0 ? Model.BlogPostID : _BlogPost.BlogPostID;

                    //ADD FEATURE IMAGE
                    if (Model.FeatureImageFileRead != null)
                    {
                        if (Model.FeatureImageFileRead.Deleting)
                        {
                            if (Model.FeatureImageFileRead.MediaID != 0)
                            {
                                new MediaBLL().DeleteMedia(Model.FeatureImageFileRead.MediaID, Model.SiteID, UserID);
                            }
                        }
                        else
                        {
                            if (Model.FeatureImageFileRead != null && !string.IsNullOrEmpty(Model.FeatureImageFileRead.FileContent))
                            {
                                new MediaBLL().DeleteMedia(Model.FeatureImageFileRead.MediaID, Model.SiteID, UserID);
                                var _Media = new MediaBLL().SaveImage(Model.FeatureImageFileRead, Model.SiteID, UserID);
                                _c.BlogPostFeatureImages.Add(new BlogPostFeatureImage
                                {
                                    BlogPostID = _BlogPostID,
                                    CultureID = Model.CultureID,
                                    MediaID = _Media.MediaID
                                });
                                _c.SaveChanges();
                            }
                        }
                    }
                    //ADD IMAGES
                    if (Model.ImagesFileRead != null)
                    {
                        foreach (var item in Model.ImagesFileRead)
                        {
                            var _BPI = _c.BlogPostImages
                                .Where(m => m.BlogPostID == _BlogPostID
                                && m.CultureID == Model.CultureID
                                && m.MediaID == item.MediaID).FirstOrDefault();
                            if (item.Adding && _BPI == null)
                            {
                                _c.BlogPostImages.Add(new BlogPostImages
                                {
                                    BlogPostID = _BlogPostID,
                                    CultureID = Model.CultureID,
                                    MediaID = item.MediaID
                                });
                            }
                            else if (item.Deleting && _BPI != null)
                            {
                                new MediaBLL().DeleteMedia(item.MediaID, Model.SiteID, UserID);
                            }
                        }
                        _c.SaveChanges();
                    }
                    return _BP.BlogPostID;
                }
            }
        }
示例#4
0
        public int Save(BlogPostModelBinding Model, string UserID)
        {
            using (var _c = db)
            {
                Can(Model.SiteID, UserID, _c);
                var _BlogPost = new BlogPost(Model.SiteID);
                if (string.IsNullOrEmpty(Model.FriendlyUrl))
                {
                    Model.FriendlyUrl = Model.Title.CleanUrl();
                }
                if (Model.BlogPostID == 0)
                {
                    var _BlogPostCulture = new BlogPostCulture(Model);
                    _BlogPostCulture.DateCreated = DateTime.Now;
                    //ADD TAGS
                    if (Model.Tags != null)
                    {
                        _BlogPostCulture.BlogPostTags = new List <BlogPostTag>();
                        foreach (var item in Model.Tags)
                        {
                            var _BTID = GetTagID(item.BlogTagName);
                            _BlogPostCulture.BlogPostTags.Add(new BlogPostTag
                            {
                                BlogTagID = GetTagID(item.BlogTagName),
                                CultureID = Model.CultureID
                            });
                        }
                    }

                    _BlogPost.BlogPostCultures = new List <BlogPostCulture>();
                    _BlogPost.BlogPostCultures.Add(_BlogPostCulture);
                    _c.BlogPosts.Add(_BlogPost);

                    //CATEGORIES
                    if (Model.Categories != null)
                    {
                        _BlogPost.BlogPostCategories = new List <BlogPostCategory>();
                        foreach (var item in Model.Categories)
                        {
                            _BlogPost.BlogPostCategories.Add(new BlogPostCategory
                            {
                                BlogCategoryID = item.BlogCategoryID
                            });
                        }
                    }
                    _c.SaveChanges();
                    return(_BlogPost.BlogPostID);
                }
                else
                {
                    var _BP = _c.BlogPostCultures
                              .Where(m => m.CultureID == Model.CultureID && m.BlogPostID == Model.BlogPostID)
                              .FirstOrDefault();
                    _BP.UpdateContent(Model);

                    //CATEGORIES
                    if (Model.Categories != null)
                    {
                        var _C = Model.Categories
                                 .Where(m => m.Adding)
                                 .Select(m => new BlogPostCategory
                        {
                            BlogCategoryID = m.BlogCategoryID,
                            BlogPostID     = Model.BlogPostID
                        });
                        foreach (var item in _C.ToList())
                        {
                            if (!_c.BlogPostCategories
                                .Where(m => m.BlogCategoryID == item.BlogCategoryID &&
                                       m.BlogPostID == item.BlogPostID).Any())
                            {
                                _BP.BlogPost.BlogPostCategories.Add(item);
                            }
                        }
                        var _CToDelete = Model.Categories
                                         .Where(m => m.Deleting).Select(m => m.BlogCategoryID);
                        _c.BlogPostCategories.RemoveRange(_c.BlogPostCategories
                                                          .Where(m => _CToDelete.Contains(m.BlogCategoryID))
                                                          .ToList());
                    }
                    //ADD TAGS
                    if (Model.Tags != null)
                    {
                        foreach (var item in Model.Tags)
                        {
                            var _BTID = GetTagID(item.BlogTagName);

                            var _BPT = _c.BlogPostTags
                                       .Where(m => m.BlogTagID == _BTID &&
                                              m.BlogPostID == Model.BlogPostID &&
                                              m.CultureID == Model.CultureID)
                                       .FirstOrDefault();

                            if (item.Adding && _BPT == null)
                            {
                                _BPT = new BlogPostTag(item, _BTID, Model.CultureID);
                                _BP.BlogPostTags.Add(_BPT);
                            }
                            else if (item.Deleting && _BPT != null)
                            {
                                _c.BlogPostTags.Remove(_BPT);
                            }
                        }
                    }
                    _c.SaveChanges();

                    int _BlogPostID = Model.BlogPostID != 0 ? Model.BlogPostID : _BlogPost.BlogPostID;

                    //ADD FEATURE IMAGE
                    if (Model.FeatureImageFileRead != null)
                    {
                        if (Model.FeatureImageFileRead.Deleting)
                        {
                            if (Model.FeatureImageFileRead.MediaID != 0)
                            {
                                new MediaBLL().DeleteMedia(Model.FeatureImageFileRead.MediaID, Model.SiteID, UserID);
                            }
                        }
                        else
                        {
                            if (Model.FeatureImageFileRead != null && !string.IsNullOrEmpty(Model.FeatureImageFileRead.FileContent))
                            {
                                new MediaBLL().DeleteMedia(Model.FeatureImageFileRead.MediaID, Model.SiteID, UserID);
                                var _Media = new MediaBLL().SaveImage(Model.FeatureImageFileRead, Model.SiteID, UserID);
                                _c.BlogPostFeatureImages.Add(new BlogPostFeatureImage
                                {
                                    BlogPostID = _BlogPostID,
                                    CultureID  = Model.CultureID,
                                    MediaID    = _Media.MediaID
                                });
                                _c.SaveChanges();
                            }
                        }
                    }
                    //ADD IMAGES
                    if (Model.ImagesFileRead != null)
                    {
                        foreach (var item in Model.ImagesFileRead)
                        {
                            var _BPI = _c.BlogPostImages
                                       .Where(m => m.BlogPostID == _BlogPostID &&
                                              m.CultureID == Model.CultureID &&
                                              m.MediaID == item.MediaID).FirstOrDefault();
                            if (item.Adding && _BPI == null)
                            {
                                _c.BlogPostImages.Add(new BlogPostImages
                                {
                                    BlogPostID = _BlogPostID,
                                    CultureID  = Model.CultureID,
                                    MediaID    = item.MediaID
                                });
                            }
                            else if (item.Deleting && _BPI != null)
                            {
                                new MediaBLL().DeleteMedia(item.MediaID, Model.SiteID, UserID);
                            }
                        }
                        _c.SaveChanges();
                    }
                    return(_BP.BlogPostID);
                }
            }
        }