Example #1
0
        /// <summary>
        /// Метод для удаления товара с модерации
        /// </summary>
        public void RemoveFromModeration(int idModerationProduct)
        {
            using (postgresContext context = new postgresContext())
            {
                string pathToModeratateProduct = $@"{BaseSettings.Default.SourcePath}\ModerateProducts\{idModerationProduct}";

                //Удалить все файлы
                if (Directory.Exists(pathToModeratateProduct))
                {
                    foreach (string newPath in Directory.GetFiles(pathToModeratateProduct, "*.*", SearchOption.AllDirectories))
                    {
                        File.Delete(newPath);
                    }
                }
                Directory.Delete($@"{pathToModeratateProduct}\Images");
                Directory.Delete(pathToModeratateProduct);

                List <TModerateEmployers> moderateEmployers = context.TModerateEmployers.Where(u => u.IdModerateProduct == idModerationProduct).ToList();
                foreach (TModerateEmployers moderator in moderateEmployers)
                {
                    context.TModerateEmployers.Remove(moderator);
                }

                context.SaveChanges();

                TModerateProducts moderateProduct = context.TModerateProducts.FirstOrDefault(u => u.Id == idModerationProduct);
                context.TModerateProducts.Remove(moderateProduct);
                context.SaveChanges();
            }
        }
Example #2
0
        /// <summary>
        /// Метод для добавления продукта в магазин
        /// </summary>
        public void AddProduct(int idModerateProduct)
        {
            using (postgresContext context = new postgresContext())
            {
                TProducts         TProduct        = new TProducts();
                TModerateProducts moderateProduct = context.TModerateProducts.FirstOrDefault(u => u.Id == idModerateProduct);
                List <TProducts>  products        = context.TProducts.ToList();

                TProduct.Id          = products.Count > 0 ? (products.Max(u => u.Id) + 1) : 1;
                TProduct.Name        = moderateProduct.Name;
                TProduct.Description = moderateProduct.Description;
                TProduct.IdDeveloper = moderateProduct.IdDeveloper;
                TProduct.IdPublisher = moderateProduct.IdPublisher;

                string pathToModeratateProduct = $@"{BaseSettings.Default.SourcePath}\ModerateProducts\{idModerateProduct}";
                string pathToProduct           = $@"{BaseSettings.Default.SourcePath}\Products\{TProduct.Id}";

                //Создать идентичное дерево каталогов
                foreach (string dirPath in Directory.GetDirectories(pathToModeratateProduct, "*", SearchOption.AllDirectories))
                {
                    Directory.CreateDirectory(dirPath.Replace(pathToModeratateProduct, pathToProduct));
                }

                //Скопировать все файлы. И перезаписать(если такие существуют)
                foreach (string newPath in Directory.GetFiles(pathToModeratateProduct, "*.*", SearchOption.AllDirectories))
                {
                    File.Copy(newPath, newPath.Replace(pathToModeratateProduct, pathToProduct), true);
                }

                //Удалить все файлы
                foreach (string newPath in Directory.GetFiles(pathToModeratateProduct, "*.*", SearchOption.AllDirectories))
                {
                    File.Delete(newPath);
                }



                TProduct.Quantity       = 100;
                TProduct.ReleaseDate    = DateTime.Now.Date;
                TProduct.RetailPrice    = moderateProduct.RetailPrice;
                TProduct.WholesalePrice = moderateProduct.WholesalePrice;
                context.TProducts.Add(TProduct);
                context.SaveChanges();
            }
        }