Ejemplo n.º 1
0
        ////Delete
        //public void deleteCategories(articles articles)
        //{
        //    var result = _db.articles.FirstOrDefault(e => e.Id == articles.Id);
        //    result.isBlocked = false;
        //    _db.SaveChanges();
        //}


        public void FullDeleteArticle(articles article)
        {
            //var article = _db.articles.FirstOrDefault(e => e.Id == model.Id);

            var result = _db.articleCategories.Where(e => e.categoriesId == article.Id).ToList();

            var deleteFavourite         = _db.favourites.Where(e => e.articlesId == article.Id);
            var deleteImage             = _db.images.Where(e => e.articlesId == article.Id);
            var deleteRating            = _db.ratings.Where(e => e.articlesId == article.Id);
            var BlockArticlesRequests   = _db.requestsArticles.Where(e => e.articlesId == article.Id);
            var deleteArticleTags       = _db.articlesTags.Where(e => e.articlesId == article.Id);
            var deleteArticleCategories = _db.articleCategories.Where(e => e.articlesId == article.Id);
            var deleteArticle           = _db.articles.Where(e => e.Id == article.Id);


            _db.favourites.RemoveRange(deleteFavourite);
            _db.images.RemoveRange(deleteImage);
            _db.ratings.RemoveRange(deleteRating);


            foreach (var artReq in BlockArticlesRequests)
            {
                artReq.articlesId = null;
            }

            _db.articlesTags.RemoveRange(deleteArticleTags);
            _db.articleCategories.RemoveRange(deleteArticleCategories);
            _db.articles.RemoveRange(deleteArticle);
            _db.SaveChanges();
        }
Ejemplo n.º 2
0
        //Create
        public void CreateArticles(ArticlesCustomClass article)
        {
            var newarticle = new articles();

            newarticle.title     = article.Title;
            newarticle.content   = article.Content;
            newarticle.date      = DateTime.Now;
            newarticle.isBlocked = true;

            if (LoginHelper.IsLoggedIn())
            {
                newarticle.usersId = LoginHelper.CurrentUser().Id;
            }
            else
            {
                newarticle.usersId = 16; // რომ წავა დასასრულისკენ პროექტი, ეს იფ-ელსი წაიშლება და მარტო current user დარჩება
            }


            if (!ExistCustomArticle(article))
            {
                _db.articles.Add(newarticle);

                //_db.SaveChanges();
                foreach (var categoryId in article.CategoriesList)
                {
                    _db.articleCategories.Add(
                        new articleCategories()
                    {
                        categoriesId = categoryId,
                        articlesId   = newarticle.Id
                    });
                    _db.SaveChanges();
                }

                if (article.RequestsList != null)
                {
                    foreach (var requestID in article.RequestsList)
                    {
                        _db.requestsArticles.Add(
                            new requestsArticles()
                        {
                            requestsId = requestID,
                            articlesId = newarticle.Id
                        });
                        _db.SaveChanges();
                    }
                }


                var mapPath = HostingEnvironment.MapPath("~/images/");
                foreach (var file in article.Images)
                {
                    if (file != null)
                    {
                        file.SaveAs(mapPath + file.FileName);
                        _db.images.Add(new images()
                        {
                            name       = file.FileName,
                            url        = "~/images/" + file.FileName,
                            articlesId = newarticle.Id,
                            usersId    = null,
                            isMain     = false
                        });
                        _db.SaveChanges();
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public bool Exist(articles article)
 {
     return(_db.articles.FirstOrDefault(e => e.title == article.title) == null ? false : true);
 }