Пример #1
0
        public async Task <IActionResult> Create(ProductViewModel model)
        {
            if (ModelState.IsValid)
            {
                Product prod = _context.Products.FirstOrDefault(x => x.Name.ToLower() == model.Product.Name.ToLower());
                if (prod != null)
                {
                    model.BrandProductCategories       = _context.BrandProductCategories.Include("Brand").Include("ProductSubCategory.ProductSubCategoryTranslate").ToList();
                    TempData["Error"]                  = "Bu adda məhsul artıq mövcuddur!";
                    ViewData["BrandProductCategoryId"] = new SelectList(_context.BrandProductCategories, "Id", "Id", model.Product.BrandProductCategoryId);
                    return(View(model));
                }
                _context.Add(model.Product);
                await _context.SaveChangesAsync();

                foreach (var product in model.ProductTranslates)
                {
                    product.ProductId = _context.Products.FirstOrDefault(x => x.Name == model.Product.Name && x.CreatedAt == model.Product.CreatedAt).Id;
                    _context.Add(product);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Məhsul Yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            model.BrandProductCategories       = _context.BrandProductCategories.Include("Brand").Include("ProductSubCategory.ProductSubCategoryTranslate").ToList();
            ViewData["BrandProductCategoryId"] = new SelectList(_context.BrandProductCategories, "Id", "Id", model.Product.BrandProductCategoryId);
            return(View(model));
        }
        public async Task <IActionResult> Create(HomeHeaderViewModel model)
        {
            if (model.HomeHeader.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(webHostEnvironment);
                    model.HomeHeader.Photo = fileManager.Upload(model.HomeHeader.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(model.HomeHeader);
                await _context.SaveChangesAsync();

                foreach (var homeHeader in model.HomeHeaderTranslates)
                {
                    homeHeader.HomeHeaderId = _context.HomeHeaders.FirstOrDefault(x => x.Photo == model.HomeHeader.Photo && x.ModifiedAt == model.HomeHeader.ModifiedAt).Id;
                    _context.Add(homeHeader);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Ana Səhifə Başlığı yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", model.HomeHeader.ProductId);
            return(View(model));
        }
Пример #3
0
        public async Task <IActionResult> Create(BlogViewModel model)
        {
            if (model.Blog.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(_webHostEnvironment);
                    model.Blog.Photo = fileManager.Upload(model.Blog.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(model.Blog);
                await _context.SaveChangesAsync();

                foreach (var blog in model.BlogTranslates)
                {
                    blog.BlogId = _context.Blogs.FirstOrDefault(x => x.Photo == model.Blog.Photo && x.CreatedAt == model.Blog.CreatedAt).Id;
                    _context.Add(blog);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Xəbər yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Пример #4
0
        public async Task <IActionResult> Create(ProductPhoto productPhoto)
        {
            if (productPhoto.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(_webHostEnvironment);
                    productPhoto.Photo = fileManager.Upload(productPhoto.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(productPhoto);
                await _context.SaveChangesAsync();

                TempData["Success"] = "Məhsul üçün Şəkil Əlavə olundu";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", productPhoto.ProductId);
            return(View(productPhoto));
        }
        public async Task <IActionResult> Create(ProperityViewModel model)
        {
            if (ModelState.IsValid)
            {
                _context.Add(model.Properity);
                await _context.SaveChangesAsync();

                foreach (var properity in model.ProperityTranslates)
                {
                    properity.ProperityId = _context.Properities.FirstOrDefault(x => x.CreatedAt == model.Properity.CreatedAt).Id;
                    _context.Add(properity);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Xüsusiyyət yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Пример #6
0
        public async Task <IActionResult> Create(ProductSubCategoryViewModel model)
        {
            if (_context.ProductSubCategoryTranslates.Any(x => x.Name.ToLower() == model.ProductSubCategoryTranslates[1].Name.ToLower()))
            {
                ViewData["AdminManagerId"]    = new SelectList(_context.AdminManagers, "Id", "Email", model.ProductSubCategory.AdminManagerId);
                ViewData["ProductCategoryId"] = new SelectList(_context.ProductCategories, "Id", "Id", model.ProductSubCategory.ProductCategoryId);
                TempData["Error"]             = "Bu adda Alt kateqoriya mövcuddur!";
                return(View(model));
            }
            if (model.ProductSubCategory.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(_webHostEnvironment);
                    model.ProductSubCategory.Photo = fileManager.Upload(model.ProductSubCategory.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                model.ProductSubCategory.CreatedAt  = DateTime.Now;
                model.ProductSubCategory.ModifiedAt = DateTime.Now;
                model.ProductSubCategory.Status     = true;
                _context.Add(model.ProductSubCategory);
                await _context.SaveChangesAsync();

                foreach (var productSubCategory in model.ProductSubCategoryTranslates)
                {
                    productSubCategory.ProductSubCategoryId = _context.ProductSubCategories.FirstOrDefault(x => x.Photo == model.ProductSubCategory.Photo && x.CreatedAt == model.ProductSubCategory.CreatedAt).Id;
                    _context.Add(productSubCategory);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Alt kateqoriya yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AdminManagerId"]    = new SelectList(_context.AdminManagers, "Id", "Email", model.ProductSubCategory.AdminManagerId);
            ViewData["ProductCategoryId"] = new SelectList(_context.ProductCategories, "Id", "Id", model.ProductSubCategory.ProductCategoryId);
            return(View(model));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("Id,Name,Code,Status,CreatedAt")] Color color)
        {
            if (ModelState.IsValid)
            {
                _context.Add(color);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(color));
        }
Пример #8
0
        public async Task <IActionResult> Create([Bind("Name,Slug,Status,CreatedAt,Id,AdminManagerId,ModifiedAt")] Brand brand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(brand);
                await _context.SaveChangesAsync();

                TempData["Success"] = "Yeni Brend uğurla yaradıldı";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AdminManagerId"] = new SelectList(_context.AdminManagers, "Id", "Email", brand.AdminManagerId);
            return(View(brand));
        }
        public async Task <IActionResult> Create(ProperityProduct properityProduct)
        {
            if (ModelState.IsValid)
            {
                ProperityProduct properity = _context.ProperityProducts.FirstOrDefault(x => x.ProductId == properityProduct.ProductId && x.ProperityId == properityProduct.ProperityId);
                if (properity != null)
                {
                    TempData["Error"]       = "Artiq Bu Məhsul üçün Xüsusiyyət seçilib";
                    ViewData["ProductId"]   = new SelectList(_context.Products, "Id", "Name", properityProduct.ProductId);
                    ViewData["ProperityId"] = new SelectList(_context.ProperityTranslates.Where(x => x.LanguageId == 2), "ProperityId", "Name", properityProduct.ProperityId);
                    return(View(properityProduct));
                }
                _context.Add(properityProduct);
                await _context.SaveChangesAsync();

                TempData["Success"] = "Məhsul üçün Xüsusiyyət uğurla seçildi";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"]   = new SelectList(_context.Products, "Id", "Name", properityProduct.ProductId);
            ViewData["ProperityId"] = new SelectList(_context.ProperityTranslates.Where(x => x.LanguageId == 2), "ProperityId", "Name", properityProduct.ProperityId);
            return(View(properityProduct));
        }
Пример #10
0
        public async Task <IActionResult> Create([Bind("Id,BrandId,ProductSubCategoryId")] BrandProductCategory brandProductCategory)
        {
            if (ModelState.IsValid)
            {
                BrandProductCategory brandProduct = _context.BrandProductCategories.FirstOrDefault(x => x.ProductSubCategoryId == brandProductCategory.ProductSubCategoryId && x.BrandId == brandProductCategory.BrandId);
                if (brandProduct != null)
                {
                    TempData["Error"] = "Artiq Bu Brend üçün Kateqoriya seçilib";

                    ViewData["BrandId"] = new SelectList(_context.Brands, "Id", "Name", brandProductCategory.BrandId);
                    ViewData["ProductSubCategoryId"] = new SelectList(_context.ProductCategoryTranslates.Where(x => x.LanguageId == 2), "ProductCategoryId", "Name", brandProductCategory.ProductSubCategoryId);
                    return(View(brandProductCategory));
                }
                _context.Add(brandProductCategory);
                await _context.SaveChangesAsync();

                TempData["Success"] = "Brend üçün Kateqoriya uğurla seçildi";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"] = new SelectList(_context.Brands, "Id", "Name", brandProductCategory.BrandId);
            ViewData["ProductSubCategoryId"] = new SelectList(_context.ProductCategoryTranslates.Where(x => x.LanguageId == 2), "ProductCategoryId", "Name", brandProductCategory.ProductSubCategoryId);
            return(View(brandProductCategory));
        }