Пример #1
0
        public bool CheckPromotionUnique(PromotionDataModel promotionDataModel)
        {
            var result = _dbContext.Promotions.AsNoTracking().FirstOrDefault(c => c.PromotionId != promotionDataModel.PromotionId &&
                                                                             c.UrlName == promotionDataModel.UrlName) == null;

            return(result);
        }
Пример #2
0
        public PromotionDataModel CreatePromotion(PromotionDataModel promotionDataModel)
        {
            var result = _dbContext.Promotions.Add(promotionDataModel).Entity;

            _dbContext.SaveChanges();

            return(result);
        }
Пример #3
0
        private void DeleteImages(PromotionDataModel promotionDataModel, ICollection <PromotionImage> promotionImages)
        {
            var promotionImageForDeleteCollection = promotionDataModel.PromotionImages.Where(db => promotionImages.All(i => i.ImageId != db.ImageId)).ToList();

            foreach (var countryImageForDelete in promotionImageForDeleteCollection)
            {
                promotionDataModel.PromotionImages.Remove(countryImageForDelete);
            }
        }
Пример #4
0
        private void AddImages(PromotionDataModel promotionDataModel, ICollection <PromotionImage> promotionImages)
        {
            var newImageCollection = promotionImages
                                     .Where(i => promotionDataModel.PromotionImages
                                            .All(db => db.ImageId != i.ImageId))
                                     .ToList();

            foreach (var newImage in newImageCollection)
            {
                promotionDataModel.PromotionImages.Add(newImage);
            }
        }
Пример #5
0
        public void DeletePromotion(PromotionDataModel promotionDataModel)
        {
            var promotion = _dbContext.Promotions
                            .Include(p => p.PromotionImages)
                            .FirstOrDefault(p => p.PromotionId == promotionDataModel.PromotionId);

            if (promotion != null)
            {
                RemovePromotionImages(promotion);
                _dbContext.Promotions.Remove(promotion);

                _dbContext.SaveChanges();
            }
        }
Пример #6
0
        public void UpdatePromotion(PromotionDataModel promotionDataModel)
        {
            var promotionImages = promotionDataModel.PromotionImages;

            promotionDataModel.PromotionImages = new HashSet <PromotionImage>();

            var entry = _dbContext.Entry(promotionDataModel);

            entry.State = EntityState.Modified;
            entry.Collection(c => c.PromotionImages).Load();

            UpdateImages(promotionDataModel, promotionImages);

            _dbContext.SaveChanges();
        }
Пример #7
0
        private void RemovePromotionImages(PromotionDataModel promotionDataModel)
        {
            var promotionImageCollection = promotionDataModel.PromotionImages?.ToList();

            if (promotionImageCollection != null && promotionImageCollection.Any())
            {
                foreach (var promotionImage in promotionImageCollection)
                {
                    var image = promotionImage.Image;
                    if (image != null)
                    {
                        _dbContext.Images.Remove(image);
                    }
                }
            }
        }
Пример #8
0
 private void UpdateImages(PromotionDataModel promotionDataModel, ICollection <PromotionImage> promotionImages)
 {
     AddImages(promotionDataModel, promotionImages);
     DeleteImages(promotionDataModel, promotionImages);
 }